From b8a83ca21a0a44487097dbf41735e3bad176d5e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Wed, 12 Jun 2013 11:22:08 -0300 Subject: Always show context menu when clicking the systray --- changes/feature_always_show_context_menu | 3 +++ src/leap/gui/mainwindow.py | 34 +++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 changes/feature_always_show_context_menu diff --git a/changes/feature_always_show_context_menu b/changes/feature_always_show_context_menu new file mode 100644 index 00000000..9e94726e --- /dev/null +++ b/changes/feature_always_show_context_menu @@ -0,0 +1,3 @@ + o Clicking in the tray icon will always show the context menu + instead of activating the window under certain + circumstances. Closes #2788 \ No newline at end of file diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py index 01707554..3c6c579c 100644 --- a/src/leap/gui/mainwindow.py +++ b/src/leap/gui/mainwindow.py @@ -523,31 +523,41 @@ class MainWindow(QtGui.QMainWindow): self._systray.setContextMenu(systrayMenu) self._systray.setIcon(QtGui.QIcon(self.ERROR_ICON)) self._systray.setVisible(True) - self._systray.activated.connect(self._toggle_visible) + self._systray.activated.connect(self._tray_activated) - def _toggle_visible(self, reason=None): + def _tray_activated(self, reason=None): """ SLOT TRIGGER: self._systray.activated - Toggles the window visibility + Displays the context menu from the tray icon """ get_action = lambda visible: ( - self.tr("Show"), - self.tr("Hide"))[int(visible)] - - minimized = self.isMinimized() + self.tr("Show Main Window"), + self.tr("Hide Main Window"))[int(visible)] if reason != QtGui.QSystemTrayIcon.Context: - # do show - if minimized: - self.showNormal() - self.setVisible(not self.isVisible()) - # set labels visible = self.isVisible() self._action_visible.setText(get_action(visible)) + context_menu = self._systray.contextMenu() + # for some reason, context_menu.show() + # is failing in a way beyond my understanding. + # (not working the first time it's clicked). + # this works however. + # XXX in osx it shows some glitches. + context_menu.exec_(self._systray.geometry().center()) + + def _toggle_visible(self): + """ + SLOT + TRIGGER: self._action_visible.triggered + + Toggles the window visibility + """ + self.setVisible(not self.isVisible()) + def _center_window(self): """ Centers the mainwindow based on the desktop geometry -- cgit v1.2.3