From 627391b56002d86ea5ade70d4424b0430e92d556 Mon Sep 17 00:00:00 2001 From: Jimmy Christensen Date: Tue, 10 Dec 2024 00:31:24 +0100 Subject: [PATCH 1/2] Add toggleable option to save settings on exit, which is enabled default --- cuegui/cuegui/MainWindow.py | 39 ++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/cuegui/cuegui/MainWindow.py b/cuegui/cuegui/MainWindow.py index 14450aeeb..55e23b14b 100644 --- a/cuegui/cuegui/MainWindow.py +++ b/cuegui/cuegui/MainWindow.py @@ -138,7 +138,9 @@ def handleExit(self, sig, flag): """Save current state and close the application""" del sig del flag - self.__saveSettings() + # Only save settings on exit if toggled + if self.saveWindowSettingsCheck.isChecked(): + self.__saveSettings() self.__windowCloseApplication() @staticmethod @@ -293,6 +295,12 @@ def __windowMenuSetup(self, menu): changeTitle.triggered.connect(self.__windowMenuHandleChangeTitle) # pylint: disable=no-member menu.addAction(changeTitle) + # Menu Bar: Window -> Save Window Settings on Exit + self.saveWindowSettingsCheck = QtWidgets.QAction("Save Window Settings on Exit", self) + self.saveWindowSettingsCheck.setCheckable(True) + self.saveWindowSettingsCheck.triggered.connect(self.__saveSettingsToggle) # pylint: disable=no-member + menu.addAction(self.saveWindowSettingsCheck) + # Menu Bar: Window -> Save Window Settings saveWindowSettings = QtWidgets.QAction("Save Window Settings", self) saveWindowSettings.triggered.connect(self.__saveSettings) # pylint: disable=no-member @@ -402,9 +410,6 @@ def __windowOpened(self): def __windowClosed(self): """Called from closeEvent on window close""" - # Save the fact that this window is open or not when the app closed - self.settings.setValue("%s/Open" % self.name, self.app.closingApp) - # pylint: disable=bare-except try: self.windows.remove(self) @@ -456,7 +461,9 @@ def closeEvent(self, event): @type event: QEvent @param event: The close event""" del event - self.__saveSettings() + # Only save settings on exit if toggled + if self.saveWindowSettingsCheck.isChecked(): + self.__saveSettings() self.__windowClosed() def __restoreSettings(self): @@ -472,6 +479,17 @@ def __restoreSettings(self): self.move(self.settings.value("%s/Position" % self.name, QtCore.QPoint(0, 0))) + self.saveWindowSettingsCheck.setChecked( + True if self.settings.value("SaveOnExit", "true") == "true" else False + ) + + def __saveSettingsToggle(self, checked): + """Toggles saving window settings on exit""" + + # Make sure that it has the same state in all windows + for window in self.windows: + window.saveWindowSettingsCheck.setChecked(checked) + def __saveSettings(self): """Saves the windows settings""" logger.info('Saving: %s', self.settings.fileName()) @@ -480,6 +498,15 @@ def __saveSettings(self): # For populating the default state: print self.saveState().toBase64() + # Save the fact that this window is open or not + for windowName in self.windows_names: + for window in self.windows: + if window.name == windowName: + self.settings.setValue("%s/Open" % windowName, True) + break + else: + self.settings.setValue("%s/Open" % windowName, False) + self.settings.setValue("Version", self.app_version) self.settings.setValue("%s/Title" % self.name, @@ -491,6 +518,8 @@ def __saveSettings(self): self.settings.setValue("%s/Position" % self.name, self.pos()) + self.settings.setValue("SaveOnExit", self.saveWindowSettingsCheck.isChecked()) + def __revertLayout(self): """Revert back to default window layout""" result = QtWidgets.QMessageBox.question( From 52ee1685a1a0d42db58765a067d77c9bb9e2a7b0 Mon Sep 17 00:00:00 2001 From: Jimmy Christensen Date: Tue, 10 Dec 2024 00:44:21 +0100 Subject: [PATCH 2/2] Fix linting errors --- cuegui/cuegui/MainWindow.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cuegui/cuegui/MainWindow.py b/cuegui/cuegui/MainWindow.py index 55e23b14b..237419e48 100644 --- a/cuegui/cuegui/MainWindow.py +++ b/cuegui/cuegui/MainWindow.py @@ -86,6 +86,10 @@ def __init__(self, app_name, app_version, window_name, parent = None): self.setAnimated(False) self.setDockNestingEnabled(True) + # Create checkable menuitem + self.saveWindowSettingsCheck = QtWidgets.QAction("Save Window Settings on Exit", self) + self.saveWindowSettingsCheck.setCheckable(True) + # Register this window self.__windowOpened() @@ -296,8 +300,6 @@ def __windowMenuSetup(self, menu): menu.addAction(changeTitle) # Menu Bar: Window -> Save Window Settings on Exit - self.saveWindowSettingsCheck = QtWidgets.QAction("Save Window Settings on Exit", self) - self.saveWindowSettingsCheck.setCheckable(True) self.saveWindowSettingsCheck.triggered.connect(self.__saveSettingsToggle) # pylint: disable=no-member menu.addAction(self.saveWindowSettingsCheck) @@ -479,9 +481,7 @@ def __restoreSettings(self): self.move(self.settings.value("%s/Position" % self.name, QtCore.QPoint(0, 0))) - self.saveWindowSettingsCheck.setChecked( - True if self.settings.value("SaveOnExit", "true") == "true" else False - ) + self.saveWindowSettingsCheck.setChecked(self.settings.value("SaveOnExit", "true") == "true") def __saveSettingsToggle(self, checked): """Toggles saving window settings on exit"""