UI: show/hide stats window by clicking on the systray icon

closes #39
This commit is contained in:
Gustavo Iñiguez Goia 2020-06-21 00:40:01 +02:00
parent 73eb5b65eb
commit 3011d9fd53

View file

@ -123,6 +123,7 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
self._tray = QtWidgets.QSystemTrayIcon(self.off_icon)
self._tray.setContextMenu(self._menu)
self._tray.activated.connect(self._on_tray_icon_activated)
self._menu.addAction("Help").triggered.connect(
lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl(Config.HELP_URL))
@ -135,6 +136,13 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
if not self._tray.isSystemTrayAvailable():
self._stats_dialog.show()
def _on_tray_icon_activated(self, reason):
if reason == QtWidgets.QSystemTrayIcon.Trigger or reason == QtWidgets.QSystemTrayIcon.MiddleClick:
if self._stats_dialog.isVisible():
self._stats_dialog.hide()
else:
self._stats_dialog.show()
def _on_close(self):
self._exit = True
self._on_exit()