Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cuegui] Add toggleable option to save settings on exit #1612

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions cuegui/cuegui/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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())
Expand All @@ -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,
Expand All @@ -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(
Expand Down