mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Config: Save the last study open and keep close status.
This commit is contained in:
1 parent
02dafd4694
commit
9ecd9a8f2a
3 files changed
+82
-5
No files matched your search
+49
-3
@@ -119,6 +119,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
self.trans = QTranslator(self)
|
||||
#self.ui.retranslateUi()
|
||||
|
||||
if self.conf.last_study != "" and not self.conf.close_correctly:
|
||||
self.dialog_reopen_study()
|
||||
|
||||
def set_title(self):
|
||||
if self.model is not None:
|
||||
self.setWindowTitle(f"PAMHYR - {self.model.name}")
|
||||
@@ -202,16 +205,24 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
if self.model is not None and not self.model.is_saved:
|
||||
self._close_question = True
|
||||
if self.dialog_close():
|
||||
# PAMHYR is close correctly (no crash)
|
||||
self.conf.set_close_correctly()
|
||||
|
||||
super(ApplicationWindow, self).close()
|
||||
else:
|
||||
self._close_question = False
|
||||
else:
|
||||
# PAMHYR is close correctly (no crash)
|
||||
self.conf.set_close_correctly()
|
||||
|
||||
super(ApplicationWindow, self).close()
|
||||
|
||||
def closeEvent(self, event):
|
||||
if not self._close_question:
|
||||
if self.model is not None and not self.model.is_saved:
|
||||
if self.dialog_close(cancel = False):
|
||||
# PAMHYR is close correctly (no crash)
|
||||
self.conf.set_close_correctly()
|
||||
super(ApplicationWindow, self).closeEvent(event)
|
||||
else:
|
||||
super(ApplicationWindow, self).closeEvent(event)
|
||||
@@ -264,11 +275,13 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
def set_model(self, model):
|
||||
self.model = model
|
||||
self.update_enable_action()
|
||||
self.conf.set_last_study(self.model.filename)
|
||||
self.set_title()
|
||||
|
||||
def close_model(self):
|
||||
self.model = None
|
||||
self.update_enable_action()
|
||||
self.conf.set_close_correctly()
|
||||
self.set_title()
|
||||
|
||||
def update_enable_action(self):
|
||||
@@ -295,6 +308,19 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
# FEATURES #
|
||||
############
|
||||
|
||||
def open_study(self, filename):
|
||||
"""Open a study
|
||||
|
||||
Args:
|
||||
filename: The study path
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
self.set_model(Study.open(filename))
|
||||
logger.info(f"Open Study - {self.model.name}")
|
||||
self.set_title()
|
||||
|
||||
def save_study(self):
|
||||
"""Save current study
|
||||
|
||||
@@ -351,6 +377,27 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
"Geometry edition need a reach selected "
|
||||
"into river network window to work on it")
|
||||
|
||||
def dialog_reopen_study(self):
|
||||
dlg = QMessageBox(self)
|
||||
|
||||
dlg.setWindowTitle("Last open study")
|
||||
dlg.setText("Do you want to open again the last open study?")
|
||||
opt = QMessageBox.Cancel | QMessageBox.Ok #| QMessageBox.Open
|
||||
|
||||
dlg.setStandardButtons(opt)
|
||||
dlg.setIcon(QMessageBox.Question)
|
||||
|
||||
res = dlg.exec()
|
||||
|
||||
if res == QMessageBox.Ok:
|
||||
self.open_study(self.conf.last_study)
|
||||
return True
|
||||
elif res == QMessageBox.Open:
|
||||
self.open_model()
|
||||
return True
|
||||
elif res == QMessageBox.Cancel:
|
||||
return False
|
||||
|
||||
def dialog_close(self, cancel = True):
|
||||
dlg = QMessageBox(self)
|
||||
|
||||
@@ -411,12 +458,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||
dialog.setDefaultSuffix(".pamhyr")
|
||||
#dialog.setFilter(dialog.filter() | QtCore.QDir.Hidden)
|
||||
dialog.setNameFilters(['PamHyr (*.pamhyr)'])
|
||||
dialog.setDirectory(os.path.dirname(self.conf.last_study))
|
||||
|
||||
if dialog.exec_():
|
||||
file_name = dialog.selectedFiles()
|
||||
self.set_model(Study.open(file_name[0]))
|
||||
logger.info(f"Open Study - {self.model.name}")
|
||||
self.set_title()
|
||||
self.open_study(file_name[0])
|
||||
|
||||
def open_new_study(self):
|
||||
"""Open dialog to set new study
|
||||
|
||||
Reference in new issue
Block a user