diff --git a/cuegui/cuegui/MainWindow.py b/cuegui/cuegui/MainWindow.py index 14450aeeb..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() @@ -138,7 +142,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 +299,10 @@ 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.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 +412,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 +463,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 +481,15 @@ def __restoreSettings(self): self.move(self.settings.value("%s/Position" % self.name, QtCore.QPoint(0, 0))) + self.saveWindowSettingsCheck.setChecked(self.settings.value("SaveOnExit", "true") == "true") + + 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(