Python PyQt5.QtWidgets 模块,QSystemTrayIcon() 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用PyQt5.QtWidgets.QSystemTrayIcon()

项目:recordium    作者:facundobatista    | 项目源码 | 文件源码
def __init__(self, app, version):
        self.app = app
        self.version = version

        # build the icon and message line, which will be properly set below when calling the
        # set_message_number() method
        self.sti = sti = QtWidgets.QSystemTrayIcon()
        self.menu = menu = QtWidgets.QMenu()
        self._messages_action = menu.addAction('')
        self.set_message_number()
        self._messages_action.triggered.connect(self._show_messages)

        menu.addSeparator()
        action = menu.addAction("Configure")
        action.triggered.connect(self._configure)
        action = menu.addAction("About")
        action.triggered.connect(self._about)
        action = menu.addAction("Quit")
        action.triggered.connect(lambda _: self.app.quit())
        sti.setContextMenu(menu)

        sti.show()
项目:kawaii-player    作者:kanishka-linux    | 项目源码 | 文件源码
def __init__(self, parent=None, ui_widget=None, home=None, window=None, logr=None):
        global ui, MainWindow, logger
        QtWidgets.QSystemTrayIcon.__init__(self, parent)
        ui = parent
        MainWindow = window
        logger = logr
        icon_img = os.path.join(home, 'src', 'tray.png')
        self.right_menu = RightClickMenuIndicator(ui_widget=ui_widget,
                                                  window=window, logr=logr)
        self.setContextMenu(self.right_menu)

        self.activated.connect(self.onTrayIconActivated)
        self.p = QtGui.QPixmap(24, 24)
        self.p.fill(QtGui.QColor("transparent"))
        painter = QtGui.QPainter(self.p)
        if os.path.exists(icon_img):
            self.setIcon(QtGui.QIcon(icon_img))
        else:
            self.setIcon(QtGui.QIcon(""))
        self.full_scr = 1
        del painter
项目:kawaii-player    作者:kanishka-linux    | 项目源码 | 文件源码
def onTrayIconActivated(self, reason):
        print(reason, '--reason--')
        if reason == QtWidgets.QSystemTrayIcon.Trigger:
            if not ui.float_window.isHidden():
                ui.float_window.hide()
                self.right_menu.h_mode.setText('&Show')
            elif self.right_menu.d_vid.text().lower() == '&attach video':
                ui.float_window.show()
                self.right_menu.h_mode.setText('&Hide')
            else:
                if MainWindow.isHidden():
                    self.right_menu.h_mode.setText('&Hide')
                    if ui.music_mode_dim_show:
                        MainWindow.showNormal()
                        MainWindow.setGeometry(
                            ui.music_mode_dim[0], ui.music_mode_dim[1], 
                            ui.music_mode_dim[2], ui.music_mode_dim[3])
                        MainWindow.show()
                    else:
                        MainWindow.showMaximized()
                else:
                    MainWindow.hide()
                    self.right_menu.h_mode.setText('&Show')
项目:AnimeWatch    作者:kanishka-linux    | 项目源码 | 文件源码
def __init__(self,parent=None):
        global name,home
        QtWidgets.QSystemTrayIcon.__init__(self, parent)
        icon_img = os.path.join(home,'src','tray.png')
        self.right_menu = RightClickMenuIndicator()
        self.setContextMenu(self.right_menu)

        self.activated.connect(self.onTrayIconActivated)
        self.p = QtGui.QPixmap(24,24)
        self.p.fill(QtGui.QColor("transparent"))
        painter = QtGui.QPainter(self.p)
        if os.path.exists(icon_img):
            self.setIcon(QtGui.QIcon(icon_img))
        else:
            self.setIcon(QtGui.QIcon(""))
        self.full_scr = 1
        del painter
项目:AnimeWatch    作者:kanishka-linux    | 项目源码 | 文件源码
def onTrayIconActivated(self, reason):
        print(reason,'--reason--')
        if reason == QtWidgets.QSystemTrayIcon.Trigger:
            if not ui.float_window.isHidden():
                ui.float_window.hide()
                self.right_menu.h_mode.setText('&Show')
            elif self.right_menu.d_vid.text().lower() == '&attach video':
                ui.float_window.show()
                self.right_menu.h_mode.setText('&Hide')
            else:
                if MainWindow.isHidden():
                    self.right_menu.h_mode.setText('&Hide')
                    if ui.music_mode_dim_show:
                        MainWindow.showNormal()
                        MainWindow.setGeometry(
                            ui.music_mode_dim[0],ui.music_mode_dim[1],
                            ui.music_mode_dim[2],ui.music_mode_dim[3])
                        MainWindow.show()
                    else:
                        MainWindow.showMaximized()
                else:
                    MainWindow.hide()
                    self.right_menu.h_mode.setText('&Show')
项目:AnimeWatch    作者:kanishka-linux    | 项目源码 | 文件源码
def __init__(self,parent=None):
        global name,home
        QtWidgets.QSystemTrayIcon.__init__(self, parent)
        icon_img = os.path.join(home,'src','tray.png')
        self.right_menu = RightClickMenuIndicator()
        self.setContextMenu(self.right_menu)

        self.activated.connect(self.onTrayIconActivated)
        self.p = QtGui.QPixmap(24,24)
        self.p.fill(QtGui.QColor("transparent"))
        painter = QtGui.QPainter(self.p)
        if os.path.exists(icon_img):
            self.setIcon(QtGui.QIcon(icon_img))
        else:
            self.setIcon(QtGui.QIcon(""))
        self.full_scr = 1
        del painter
项目:AnimeWatch    作者:kanishka-linux    | 项目源码 | 文件源码
def onTrayIconActivated(self, reason):
        print(reason,'--reason--')
        if reason == QtWidgets.QSystemTrayIcon.Trigger:
            if not ui.float_window.isHidden():
                ui.float_window.hide()
                self.right_menu.h_mode.setText('&Show')
            elif self.right_menu.d_vid.text().lower() == '&attach video':
                ui.float_window.show()
                self.right_menu.h_mode.setText('&Hide')
            else:
                if MainWindow.isHidden():
                    self.right_menu.h_mode.setText('&Hide')
                    if ui.music_mode_dim_show:
                        MainWindow.showNormal()
                        MainWindow.setGeometry(
                            ui.music_mode_dim[0],ui.music_mode_dim[1],
                            ui.music_mode_dim[2],ui.music_mode_dim[3])
                        MainWindow.show()
                    else:
                        MainWindow.showMaximized()
                else:
                    MainWindow.hide()
                    self.right_menu.h_mode.setText('&Show')
项目:hackucsc-lazyeye    作者:zamlz    | 项目源码 | 文件源码
def toggle(self, reason):
        if reason == QtWidgets.QSystemTrayIcon.Trigger:
            # Toggle camera state and switch icon and tooltip
            self.cameraState = (self.cameraState + 1) % 2
            self.setToolTip(const.TRAY_TOOLTIP[self.cameraState])
            icon = QtGui.QIcon(QtGui.QPixmap(const.TRAY_ICON[self.cameraState]))
            self.setIcon(icon)

            # Toggle webcam
            if self.cameraState == const.CAMERA_INACTIVE:
                const.disableCamera = True
                self.showMessage(const.TEAM_NAME,
                                 const.TOGGLE_MESSAGE[self.cameraState],
                                 QtWidgets.QSystemTrayIcon.Information,
                                 const.TOGGLE_MESSAGE_TIME)
            else:
                const.disableCamera = False
                self.showMessage(const.TEAM_NAME,
                                 const.TOGGLE_MESSAGE[self.cameraState],
                                 QtWidgets.QSystemTrayIcon.Information,
                                 const.TOGGLE_MESSAGE_TIME)
                live_vid.main()
项目:copa    作者:komradz    | 项目源码 | 文件源码
def __icon_activated(self, reason):
        if reason == QtWidgets.QSystemTrayIcon.DoubleClick:
            self.show()

    #translate UI
项目:grid-control    作者:akej74    | 项目源码 | 文件源码
def on_systemTrayIcon_activated(self, reason):
        if reason == QtWidgets.QSystemTrayIcon.DoubleClick:
            self.parent.toggle_visibility()
项目:mindfulness-at-the-computer    作者:SunyataZero    | 项目源码 | 文件源码
def on_systray_activated(self, i_reason):
        # LXDE:
        # XFCE:
        # MacOS:
        logging.debug("===== on_systray_activated entered =====")
        logging.debug("i_reason = " + str(i_reason))
        logging.debug("mouseButtons() = " + str(QtWidgets.QApplication.mouseButtons()))
        self.tray_icon.activated.emit(i_reason)
        """
        if i_reason == QtWidgets.QSystemTrayIcon.Trigger:
            self.restore_window()
        else:
            self.tray_icon.activated.emit(i_reason)
        """
        logging.debug("===== on_systray_activated exited =====")
项目:hackucsc-lazyeye    作者:zamlz    | 项目源码 | 文件源码
def __init__(self, icon, parent=None):
        QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)

        self.cameraState = const.CAMERA_ACTIVE
        self.setToolTip(const.TRAY_TOOLTIP[const.CAMERA_ACTIVE])

        self.menu = QtWidgets.QMenu(parent)
        exitAction = self.menu.addAction("Exit    ")
        exitAction.setStatusTip('Exit Application')
        exitAction.triggered.connect(sys.exit)
        self.setContextMenu(self.menu)
项目:hackucsc-lazyeye    作者:zamlz    | 项目源码 | 文件源码
def fireAlertMessage(self, msg, time):
        if self.supportsMessages():
            self.showMessage(const.ALERT_TITLE,
                             const.ALERT_MESSAGE[msg],
                             QtWidgets.QSystemTrayIcon.Information,
                             time)


#######################
# Main Function
#######################
项目:TabPad    作者:nitg16    | 项目源码 | 文件源码
def systraysetup(self):
        self.tray_icon = QSystemTrayIcon(self)
        self.tray_icon.setIcon(self.appicon)

        self.show_action = QAction("Show", self)
        self.quit_action = QAction("Quit", self)
        self.hide_action = QAction("Hide", self)
        self.settings_action = QAction("Settings", self)
        self.layout_action = QAction("Edit Current Layout", self)
        self.restart_action = QAction("Restart", self)
        self.autorepeat_action = QAction("Stop All Inputs", self)
        self.about_action = QAction("About TabPad", self)

        self.show_action.setIcon(QIcon.fromTheme("go-home"))
        self.hide_action.setIcon(QIcon.fromTheme("go-down"))
        self.settings_action.setIcon(QIcon.fromTheme("preferences-other"))
        self.layout_action.setIcon(QIcon.fromTheme("edit-find-replace"))
        self.quit_action.setIcon(QIcon.fromTheme("application-exit"))
        self.autorepeat_action.setIcon(QIcon.fromTheme("process-stop"))
        self.restart_action.setIcon(QIcon.fromTheme("view-refresh"))
        self.about_action.setIcon(QIcon.fromTheme("help-about"))

        self.show_action.triggered.connect(self.showpad)
        self.hide_action.triggered.connect(self.hidepad)
        self.quit_action.triggered.connect(self.quithandler)
        self.settings_action.triggered.connect(self.show_settings_window)
        self.layout_action.triggered.connect(self.show_layout_window)
        self.restart_action.triggered.connect(self.restart_program)
        self.autorepeat_action.triggered.connect(self.finish_all_inputs)
        self.about_action.triggered.connect(self.show_about_dialog)

        self.tray_menu = QMenu()
        self.tray_menu.addAction(self.show_action)
        self.tray_menu.addAction(self.hide_action)
        self.tray_menu.addAction(self.autorepeat_action)
        self.tray_menu.addAction(self.layout_action)
        self.tray_menu.addAction(self.settings_action)
        self.tray_menu.addAction(self.restart_action)
        self.tray_menu.addAction(self.about_action)
        self.tray_menu.addAction(self.quit_action)
        self.tray_icon.setContextMenu(self.tray_menu)
        self.tray_icon.show()
        self.tray_icon.activated.connect(self.catchclick)