Save main window state before closing

This commit is contained in:
Hofer Julian 2020-06-22 10:36:23 +02:00 committed by GitHub
parent 96e4d4bef2
commit 9fc495f51d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -215,6 +215,14 @@ def get_misc_settings():
'key': 'previous_profile_id', 'str_value': '1', 'type': 'internal',
'label': 'Previously selected profile'
},
{
'key': 'previous_window_width', 'str_value': '800', 'type': 'internal',
'label': 'Previous window width'
},
{
'key': 'previous_window_height', 'str_value': '600', 'type': 'internal',
'label': 'Previous window height'
},
]
if sys.platform == 'darwin':
settings += [

View File

@ -30,6 +30,11 @@ class MainWindow(MainWindowBase, MainWindowUI):
self.app = parent
self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint)
# Use previous window state
previous_window_width = SettingsModel.get(key='previous_window_width')
previous_window_height = SettingsModel.get(key='previous_window_height')
self.resize(int(previous_window_width.str_value), int(previous_window_height.str_value))
# Select previously used profile, if available
prev_profile_id = SettingsModel.get(key='previous_profile_id')
self.current_profile = BackupProfileModel.get_or_none(id=prev_profile_id.str_value)
@ -168,6 +173,14 @@ class MainWindow(MainWindowBase, MainWindowUI):
self.set_status(self.tr('Task cancelled'))
def closeEvent(self, event):
# Save window state in SettingsModel
SettingsModel.update({SettingsModel.str_value: str(self.frameGeometry().width())})\
.where(SettingsModel.key == 'previous_window_width')\
.execute()
SettingsModel.update({SettingsModel.str_value: str(self.frameGeometry().height())})\
.where(SettingsModel.key == 'previous_window_height')\
.execute()
if not is_system_tray_available():
run_in_background = QMessageBox.question(self,
trans_late("MainWindow QMessagebox",