-
Notifications
You must be signed in to change notification settings - Fork 0
/
systray.py
59 lines (42 loc) · 1.71 KB
/
systray.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
from games_controller import Game
from icons import Icons
from static import *
class GameAction(QAction):
def __init__(self, parent: QSystemTrayIcon, index: int, game: Game):
super().__init__(icon=game.icon, text=game.name, parent=parent)
self.index = index
self.game = game
self.triggered.connect(lambda: GameAction.launchGame(self.index))
@staticmethod
def launchGame(index: int): pass # OVERRIDED BY APP
class SystrayCustomWidget(QSystemTrayIcon):
actions = []
show_mainwindow = Signal()
quit = Signal()
def __init__(self):
super().__init__()
self.setIcon(Icons.appIcon())
self.activated.connect(self._activatedSlot)
@Slot(QSystemTrayIcon.ActivationReason)
def _activatedSlot(self, reason: QSystemTrayIcon.ActivationReason):
if reason == QSystemTrayIcon.ActivationReason.DoubleClick:
self.show_mainwindow.emit()
def refresh(self, games: list[Game]):
self.systray_menu = QMenu()
self.actions = []
for game in games:
game: Game
index = len(self.actions)
action = GameAction(self.parent(), index, game)
self.actions.append(action)
self.systray_menu.addActions(self.actions)
self.systray_menu.addSeparator()
self.systray_menu.addAction(Icons.appIcon(), 'Afficher l\'interface', self.show_mainwindow.emit)
self.systray_menu.addSeparator()
self.systray_menu.addAction(Icons.quitIcon(), 'Quitter', self.quit.emit)
self.systray_menu.setFont(QFont('Segoe UI', 12)) # FONT & SIZE WILL BE DEFINED IN SETTINGS LATER
self.setContextMenu(self.systray_menu)
self.setToolTip(f'{APP_TITLE} v{APP_VERSION}\n{len(games)} game(s)')