From 1f7b47f978b0f8602acd9528d9752b7fde7d476a Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 24 Nov 2012 13:53:07 +0000 Subject: [PATCH] Cadence/Claudia/Systray: Implement hide on close --- doc/TODO | 3 --- resources/ui/cadence.ui | 40 ++++++++-------------------------------- src/cadence.py | 8 +------- src/claudia.py | 17 ++++++++--------- src/systray.py | 28 ++++++++++++++++++++++++++-- 5 files changed, 43 insertions(+), 53 deletions(-) diff --git a/doc/TODO b/doc/TODO index 73cf56e..2fcacdc 100644 --- a/doc/TODO +++ b/doc/TODO @@ -21,6 +21,3 @@ Claudia: PatchCanvas: - Implement export to Catarina file - -Systray: - - Implement hide-on-close diff --git a/resources/ui/cadence.ui b/resources/ui/cadence.ui index 86c0eed..d724967 100644 --- a/resources/ui/cadence.ui +++ b/resources/ui/cadence.ui @@ -7,7 +7,7 @@ 0 0 739 - 549 + 529 @@ -515,7 +515,7 @@ 0 0 366 - 120 + 100 @@ -663,7 +663,7 @@ 0 0 366 - 117 + 97 @@ -804,7 +804,7 @@ 0 0 366 - 117 + 97 @@ -1511,7 +1511,7 @@ 0 0 - 76 + 94 76 @@ -1529,7 +1529,7 @@ 0 0 - 89 + 94 76 @@ -1547,7 +1547,7 @@ 0 0 - 89 + 94 76 @@ -1565,7 +1565,7 @@ 0 0 - 89 + 94 76 @@ -2066,14 +2066,6 @@ Default is off - - - &Quit - - - Ctrl+Q - - @@ -2087,22 +2079,6 @@ Default is off - - act_quit - triggered() - CadenceMainW - close() - - - -1 - -1 - - - 399 - 299 - - - tw_tweaks currentCellChanged(int,int,int,int) diff --git a/src/cadence.py b/src/cadence.py index ec331d3..76d5d69 100755 --- a/src/cadence.py +++ b/src/cadence.py @@ -2052,11 +2052,6 @@ class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW): if geometry: self.restoreGeometry(self.settings.value("Geometry", "")) - self.m_savedSettings = { - "Main/UseSystemTray": self.settings.value("Main/UseSystemTray", True, type=bool), - "Main/CloseToTray": self.settings.value("Main/CloseToTray", True, type=bool) - } - self.cb_jack_autostart.setChecked(GlobalSettings.value("JACK/AutoStart", True, type=bool)) self.cb_a2j_autostart.setChecked(GlobalSettings.value("A2J/AutoStart", True, type=bool)) self.cb_pulse_autostart.setChecked(GlobalSettings.value("Pulse2JACK/AutoStart", havePulseAudio, type=bool)) @@ -2097,8 +2092,7 @@ class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW): def closeEvent(self, event): self.saveSettings() - self.systray.close() - QMainWindow.closeEvent(self, event) + self.systray.handleQtCloseEvent(event) #--------------- main ------------------ if __name__ == '__main__': diff --git a/src/claudia.py b/src/claudia.py index a3574f1..85f09fe 100755 --- a/src/claudia.py +++ b/src/claudia.py @@ -2494,11 +2494,10 @@ class ClaudiaMainW(QMainWindow, ui_claudia.Ui_ClaudiaMainW): def closeEvent(self, event): self.saveSettings() if self.systray: - #if self.saved_settings["Main/CloseToTray"] and self.systray.isTrayAvailable() and self.isVisible(): - #self.hide() - #self.systray.setActionText("show", QStringStr(gui.tr("Restore"))) - #event.ignore() - #return + if self.m_savedSettings["Main/CloseToTray"]: + if self.systray.handleQtCloseEvent(event): + patchcanvas.clear() + return self.systray.close() patchcanvas.clear() QMainWindow.closeEvent(self, event) @@ -2542,10 +2541,10 @@ if __name__ == '__main__': setUpSignals(gui) # App-Loop - #if gui.systray: - #ret = gui.systray.exec_(app) - #else: - ret = app.exec_() + if gui.systray: + ret = gui.systray.exec_(app) + else: + ret = app.exec_() # Close Jack if jack.client: diff --git a/src/systray.py b/src/systray.py index 794b985..d9b5e9b 100644 --- a/src/systray.py +++ b/src/systray.py @@ -19,7 +19,7 @@ # Imports (Global) import os, sys from PyQt4.QtCore import QTimer, SIGNAL -from PyQt4.QtGui import QAction, QIcon, QMenu, QSystemTrayIcon +from PyQt4.QtGui import QAction, QIcon, QMainWindow, QMenu, QSystemTrayIcon try: if os.getenv("DESKTOP_SESSION") in ("ubuntu", "ubuntu-2d") and not os.path.exists("/var/cadence/no_app_indicators"): @@ -81,6 +81,7 @@ class GlobalSysTray(object): def __init__(self, parent, name, icon): object.__init__(self) + self._app = None self._parent = parent self._gtk_running = False self._quit_added = False @@ -491,6 +492,17 @@ class GlobalSysTray(object): else: return False + def handleQtCloseEvent(self, event): + if self.isTrayAvailable() and self._parent.isVisible(): + event.ignore() + self.__hideShowCall() + return False + else: + self.close() + + QMainWindow.closeEvent(self._parent, event) + return True + # ------------------------------------------------------------------------------------------- def show(self): @@ -531,6 +543,7 @@ class GlobalSysTray(object): self.menu.close() def exec_(self, app): + self._app = app if TrayEngine == "AppIndicator": self._gtk_running = True return Gtk.main() @@ -616,6 +629,10 @@ class GlobalSysTray(object): if self._parent.isVisible(): self.setActionText("show", self._parent.tr("Restore")) self._parent.hide() + + if self._app: + self._app.setQuitOnLastWindowClosed(False) + else: self.setActionText("show", self._parent.tr("Minimize")) @@ -624,9 +641,16 @@ class GlobalSysTray(object): else: self._parent.showNormal() - QTimer.singleShot(100, self.__raiseWindow) + if self._app: + self._app.setQuitOnLastWindowClosed(True) + + QTimer.singleShot(500, self.__raiseWindow) def __quitCall(self): + if self._app: + self._app.setQuitOnLastWindowClosed(True) + + self._parent.hide() self._parent.close() def __raiseWindow(self):