-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a basic system tray using PyQt6.
- Loading branch information
1 parent
5b70d9b
commit 8ad6795
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from PyQt6.QtGui import QIcon, QAction | ||
from PyQt6.QtWidgets import QApplication, QSystemTrayIcon, QMenu | ||
|
||
|
||
class SystemTray: | ||
def __init__(self, window): | ||
self.app = QApplication([]) | ||
self.app.setQuitOnLastWindowClosed(False) | ||
|
||
self.window = window | ||
self.shown = False | ||
|
||
icon = QIcon.fromTheme("io.github.giantpinkrobots.varia") | ||
|
||
tray = QSystemTrayIcon(icon=icon, parent=self.app) | ||
tray.setVisible(True) | ||
|
||
menu = QMenu() | ||
self.quit_action = QAction("Quit Varia") | ||
self.quit_action.triggered.connect(lambda: self.window.trayExit()) | ||
menu.addAction(self.quit_action) | ||
|
||
tray.activated.connect(lambda: self._toggle_window()) | ||
|
||
tray.setContextMenu(menu) | ||
|
||
def run(self): | ||
if not self.window.appconf["default_mode"] == "background": | ||
self.shown = True | ||
self.window.show() | ||
self.app.exec() | ||
|
||
def exit(self): | ||
self.app.quit() | ||
|
||
def _toggle_window(self): | ||
if not self.shown: | ||
self.window.show() | ||
self.shown = True | ||
else: | ||
self.window.hide() | ||
self.shown = False |