From 3011d9fd53174e0608d0fd67bd69ce1dddcab414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20I=C3=B1iguez=20Goia?= Date: Sun, 21 Jun 2020 00:40:01 +0200 Subject: [PATCH] UI: show/hide stats window by clicking on the systray icon closes #39 --- ui/opensnitch/service.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/opensnitch/service.py b/ui/opensnitch/service.py index f0aeefaeda..e95462d5b0 100644 --- a/ui/opensnitch/service.py +++ b/ui/opensnitch/service.py @@ -123,6 +123,7 @@ def _setup_tray(self): 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 @@ def _setup_tray(self): 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()