Python PyQt5.QtWidgets.QSystemTrayIcon() Examples

The following are 21 code examples of PyQt5.QtWidgets.QSystemTrayIcon(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtWidgets , or try the search function .
Example #1
Source File: qomui_gui.py    From qomui with GNU General Public License v3.0 7 votes vote down vote up
def systemtray(self):
        self.trayIcon = QtGui.QIcon.fromTheme("qomui")
        self.tray = QtWidgets.QSystemTrayIcon()

        if self.tray.isSystemTrayAvailable() == False:
            self.setWindowState(QtCore.Qt.WindowActive)
            self.showNormal()
        else:
            self.tray.setIcon(self.trayIcon)
            self.trayMenu = QtWidgets.QMenu()
            self.pop_tray_menu()
            self.tray.setContextMenu(self.trayMenu)
            self.tray.show()
            self.tray.setToolTip("Status: disconnected")
            self.tray.activated.connect(self.restoreUi)

        #if self.windowState() == QtCore.Qt.WindowActive:
         #   self.trayMenu.insert(Action) 
Example #2
Source File: system_tray_icon.py    From attack_monitor with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, icon, parent, main_app, learning_mode):
        self.main_app = main_app
        QtWidgets.QSystemTrayIcon.__init__(self, parent)
        self.setIcon(icon)
        menu = QtWidgets.QMenu(parent)

        #LEARNING MODE
        menu_learning_action = menu.addAction("Learning mode")
        menu_learning_action.setCheckable(True)
        menu_learning_action.setChecked(learning_mode)

        menu_learning_action.toggled.connect(self.main_app.set_learning_mode)

        menu.addSeparator()

        #EXIT
        exitAction = menu.addAction("Exit")
        exitAction.triggered.connect(self.exit_zero)

        self.setContextMenu(menu) 
Example #3
Source File: traywidget.py    From kawaii-player with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #4
Source File: traywidget.py    From kawaii-player with GNU General Public License v3.0 6 votes vote down vote up
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') 
Example #5
Source File: runcat.py    From Tools with MIT License 6 votes vote down vote up
def runcatCPU():
    app = QApplication(sys.argv)
    # 最后一个可视的窗口退出时程序不退出
    app.setQuitOnLastWindowClosed(False)
    icon = QSystemTrayIcon()
    icon.setIcon(QIcon('icons/0.png'))
    icon.setVisible(True)
    cpu_percent = psutil.cpu_percent(interval=1) / 100
    cpu_percent_update_fps = 20
    fps_count = 0
    while True:
        fps_count += 1
        if fps_count > cpu_percent_update_fps:
            cpu_percent = psutil.cpu_percent(interval=1) / 100
            fps_count = 0
        # 开口向上的抛物线, 左边递减
        time_interval = (cpu_percent * cpu_percent - 2 * cpu_percent + 2) / 20
        for i in range(5):
            icon.setIcon(QIcon('icons/%d.png' % i))
            icon.setToolTip('cpu: %.2f' % cpu_percent)
            time.sleep(time_interval)
    app.exec_() 
Example #6
Source File: runcat.py    From Tools with MIT License 6 votes vote down vote up
def runcatMemory():
    app = QApplication(sys.argv)
    # 最后一个可视的窗口退出时程序不退出
    app.setQuitOnLastWindowClosed(False)
    icon = QSystemTrayIcon()
    icon.setIcon(QIcon('icons/0.png'))
    icon.setVisible(True)
    memory_percent = psutil.virtual_memory().percent / 100
    memory_percent_update_fps = 20
    fps_count = 0
    while True:
        fps_count += 1
        if fps_count > memory_percent_update_fps:
            memory_percent = psutil.virtual_memory().percent / 100
            fps_count = 0
        # 开口向上的抛物线, 左边递减
        time_interval = (memory_percent * memory_percent - 2 * memory_percent + 2) / 20
        for i in range(5):
            icon.setIcon(QIcon('icons/%d.png' % i))
            icon.setToolTip('memory: %.2f' % memory_percent)
            time.sleep(time_interval)
    app.exec_() 
Example #7
Source File: app.py    From tinydecred with ISC License 5 votes vote down vote up
def sysTrayActivated(self, trigger):
        """
        Qt Slot called when the user interacts with the system tray icon. Shows
        the window, creating an icon in the user's application panel that
        persists until the appWindow is minimized.
        """
        if trigger == QtWidgets.QSystemTrayIcon.Trigger:
            self.appWindow.show()
            self.appWindow.activateWindow() 
Example #8
Source File: angrysearch.py    From ANGRYsearch with GNU General Public License v2.0 5 votes vote down vote up
def make_sys_tray(self):
        if Qw.QSystemTrayIcon.isSystemTrayAvailable():
            menu = Qw.QMenu()
            menu.addAction('v1.0.1')
            menu.addSeparator()
            exitAction = menu.addAction('Quit')
            exitAction.triggered.connect(self.close)

            self.tray_icon = Qw.QSystemTrayIcon()
            self.tray_icon.setIcon(self.icon)
            self.tray_icon.setContextMenu(menu)
            self.tray_icon.show()
            self.tray_icon.setToolTip('ANGRYsearch')
            self.tray_icon.activated.connect(self.sys_tray_clicking) 
Example #9
Source File: mainwindow.py    From track with Apache License 2.0 5 votes vote down vote up
def _initialize_tray_icon(self) -> QtWidgets.QSystemTrayIcon:
        def restore_window(reason: QtWidgets.QSystemTrayIcon.ActivationReason) -> None:
            if reason == QtWidgets.QSystemTrayIcon.DoubleClick:
                self.tray_icon.hide()
                self.showNormal()

        tray_icon = QtWidgets.QSystemTrayIcon(self)
        tray_icon.setIcon(self.windowIcon())
        tray_icon.activated.connect(restore_window)
        return tray_icon 
Example #10
Source File: utils.py    From v2rayL with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, w, app):
        self.app = app
        self.w = w
        QApplication.setQuitOnLastWindowClosed(False)  # 禁止默认的closed方法,
        self.w.show()  # 不设置显示则为启动最小化到托盘
        self.tp = QSystemTrayIcon(self.w)
        self.initUI()
        self.run()

        # sys.stdout = EmittingStream(textWritten=self.w.output_ter_result)
        # sys.stderr = EmittingStream(textWritten=self.w.output_ter_result) 
Example #11
Source File: service.py    From opensnitch with GNU General Public License v3.0 5 votes vote down vote up
def _setup_tray(self):
        self._menu = QtWidgets.QMenu()
        self._stats_action = self._menu.addAction("Statistics")
        self._stats_action.triggered.connect(lambda: self._stats_dialog.show())
        self._menu.addAction("Close").triggered.connect(self._on_exit)
        self._tray = QtWidgets.QSystemTrayIcon(self.off_icon)
        self._tray.setContextMenu(self._menu)
        self._tray.show() 
Example #12
Source File: gridcontrol.py    From grid-control with GNU General Public License v3.0 5 votes vote down vote up
def on_systemTrayIcon_activated(self, reason):
        if reason == QtWidgets.QSystemTrayIcon.DoubleClick:
            self.parent.toggle_visibility() 
Example #13
Source File: utils.py    From vorta with GNU General Public License v3.0 5 votes vote down vote up
def is_system_tray_available():
    app = QApplication.instance()
    if app is None:
        app = QApplication([])
        tray = QSystemTrayIcon()
        is_available = tray.isSystemTrayAvailable()
        app.quit()
    else:
        tray = QSystemTrayIcon()
        is_available = tray.isSystemTrayAvailable()

    return is_available 
Example #14
Source File: systray.py    From scudcloud with MIT License 5 votes vote down vote up
def activatedEvent(self, reason):
        if reason in [QtWidgets.QSystemTrayIcon.MiddleClick, QtWidgets.QSystemTrayIcon.Trigger]:
            if self.window.isHidden() or self.window.isMinimized() or not self.window.isActiveWindow():
                self.restore()
            else:
                self.window.hide() 
Example #15
Source File: system_tray_icon.py    From attack_monitor with GNU General Public License v3.0 5 votes vote down vote up
def show_message(self, title, msg, icon):
        self.showMessage(title, msg, icon)

        #QtWidgets.QSystemTrayIcon.Critical
        #winsound.PlaySound('sound\\Buzz-SoundBible.com-1790490578.wav', 0) 
Example #16
Source File: __main__.py    From qhangups with GNU General Public License v3.0 5 votes vote down vote up
def icon_activated(self, reason):
        """Connect or disconnect from Hangouts by double-click on tray icon"""
        if reason == QtWidgets.QSystemTrayIcon.Trigger or reason == QtWidgets.QSystemTrayIcon.DoubleClick:
            if self.icon_doubleclick_timer.isActive():
                self.icon_doubleclick_timer.stop()
                if self.hangups_running:
                    self.hangups_stop()
                else:
                    self.hangups_start()
            else:
                self.icon_doubleclick_timer.start(QtWidgets.qApp.doubleClickInterval()) 
Example #17
Source File: __main__.py    From qhangups with GNU General Public License v3.0 5 votes vote down vote up
def create_icon(self):
        """Create system tray icon"""
        self.trayIcon = QtWidgets.QSystemTrayIcon(self)
        self.iconActive = QtGui.QIcon("{}/qhangups.svg".format(os.path.dirname(os.path.abspath(__file__))))
        self.iconDisabled = QtGui.QIcon("{}/qhangups_disabled.svg".format(os.path.dirname(os.path.abspath(__file__))))
        # Workaround for Plasma 5 not showing SVG icons
        self.iconActive = QtGui.QIcon(self.iconActive.pixmap(128, 128))
        self.iconDisabled = QtGui.QIcon(self.iconDisabled.pixmap(128, 128))

        self.trayIcon.activated.connect(self.icon_activated)
        self.trayIcon.setContextMenu(self.trayIconMenu)
        self.trayIcon.setIcon(self.iconDisabled)
        self.trayIcon.setToolTip("QHangups")
        self.trayIcon.show() 
Example #18
Source File: main_win.py    From mindfulness-at-the-computer with GNU General Public License v3.0 5 votes vote down vote up
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 =====") 
Example #19
Source File: angrysearch.py    From ANGRYsearch with GNU General Public License v2.0 5 votes vote down vote up
def sys_tray_clicking(self, reason):
        if (reason == Qw.QSystemTrayIcon.DoubleClick or
                reason == Qw.QSystemTrayIcon.Trigger):
            self.show()
        elif (reason == Qw.QSystemTrayIcon.MiddleClick):
            self.close() 
Example #20
Source File: QtApplication.py    From Uranium with GNU Lesser General Public License v3.0 4 votes vote down vote up
def __init__(self, tray_icon_name: str = None, **kwargs) -> None:
        plugin_path = ""
        if sys.platform == "win32":
            if hasattr(sys, "frozen"):
                plugin_path = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "PyQt5", "plugins")
                Logger.log("i", "Adding QT5 plugin path: %s", plugin_path)
                QCoreApplication.addLibraryPath(plugin_path)
            else:
                import site
                for sitepackage_dir in site.getsitepackages():
                    QCoreApplication.addLibraryPath(os.path.join(sitepackage_dir, "PyQt5", "plugins"))
        elif sys.platform == "darwin":
            plugin_path = os.path.join(self.getInstallPrefix(), "Resources", "plugins")

        if plugin_path:
            Logger.log("i", "Adding QT5 plugin path: %s", plugin_path)
            QCoreApplication.addLibraryPath(plugin_path)

        # use Qt Quick Scene Graph "basic" render loop
        os.environ["QSG_RENDER_LOOP"] = "basic"

        super().__init__(sys.argv, **kwargs) # type: ignore

        self._qml_import_paths = [] #type: List[str]
        self._main_qml = "main.qml" #type: str
        self._qml_engine = None #type: Optional[QQmlApplicationEngine]
        self._main_window = None #type: Optional[MainWindow]
        self._tray_icon_name = tray_icon_name #type: Optional[str]
        self._tray_icon = None #type: Optional[str]
        self._tray_icon_widget = None #type: Optional[QSystemTrayIcon]
        self._theme = None #type: Optional[Theme]
        self._renderer = None #type: Optional[QtRenderer]

        self._job_queue = None #type: Optional[JobQueue]
        self._version_upgrade_manager = None #type: Optional[VersionUpgradeManager]

        self._is_shutting_down = False #type: bool

        self._recent_files = [] #type: List[QUrl]

        self._configuration_error_message = None #type: Optional[ConfigurationErrorMessage]

        self._http_network_request_manager = HttpRequestManager(parent = self)

        #Metadata required for the file dialogues.
        self.setOrganizationDomain("https://ultimaker.com/")
        self.setOrganizationName("Ultimaker B.V.") 
Example #21
Source File: app.py    From launcher with MIT License 4 votes vote down vote up
def init_tray(self):

        tray = QtWidgets.QSystemTrayIcon(self.windowIcon(), parent=self)
        tray.setToolTip("Avalon Launcher")

        # Build the right-mouse context menu for the tray icon
        menu = QtWidgets.QMenu()

        def window_show():
            self.window.show()
            self.window.raise_()
            self.window.requestActivate()

        show = QtWidgets.QAction("Show", self)
        show.triggered.connect(window_show)
        menu.addAction(show)

        def on_quit():
            # fix crash on quit with QML window open
            self.closeAllWindows()

            # fix tray icon remaining visible until hover over
            self._tray.hide()

            self.quit()

        quit = QtWidgets.QAction("Quit", self)
        quit.triggered.connect(on_quit)
        menu.addAction(quit)
        tray.setContextMenu(menu)

        # Add the double clicked behavior
        def on_tray_activated(reason):
            if reason == QtWidgets.QSystemTrayIcon.Context:
                return

            if self.window.isVisible():
                self.window.hide()

            elif reason == QtWidgets.QSystemTrayIcon.Trigger:
                window_show()

        tray.activated.connect(on_tray_activated)

        self._tray = tray

        tray.show()
        tray.showMessage("Avalon", "Launcher tray started.", 500)