Commit e617738f authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

MainWindow: Add save question at PAMHYR closed.

Showing with 51 additions and 3 deletions
+51 -3
...@@ -14,6 +14,7 @@ from PyQt5.QtCore import ( ...@@ -14,6 +14,7 @@ from PyQt5.QtCore import (
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QMainWindow, QApplication, QAction, QMainWindow, QApplication, QAction,
QFileDialog, QShortcut, QMenu, QToolBar, QFileDialog, QShortcut, QMenu, QToolBar,
QMessageBox,
) )
from PyQt5.uic import loadUi from PyQt5.uic import loadUi
...@@ -77,6 +78,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -77,6 +78,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
def __init__(self, conf=None): def __init__(self, conf=None):
super(ApplicationWindow, self).__init__() super(ApplicationWindow, self).__init__()
self._close_question = False
# App Configuration # App Configuration
self.conf = conf self.conf = conf
...@@ -175,6 +178,24 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -175,6 +178,24 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.retranslateUi() self.retranslateUi()
super(ApplicationWindow, self).changeEvent(event) super(ApplicationWindow, self).changeEvent(event)
def close(self):
if self.model is not None and not self.model.is_saved:
self._close_question = True
if self.dialog_close():
super(ApplicationWindow, self).close()
else:
self._close_question = False
else:
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):
super(ApplicationWindow, self).closeEvent(event)
else:
super(ApplicationWindow, self).closeEvent(event)
def default_style(self): def default_style(self):
"""Set default window style """Set default window style
...@@ -262,6 +283,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -262,6 +283,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
else: else:
self.model.filename = file_name + ".pamhyr" self.model.filename = file_name + ".pamhyr"
print("[INFO] Save...")
self.model.save() self.model.save()
def save_as_study(self): def save_as_study(self):
...@@ -285,15 +307,41 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -285,15 +307,41 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.model.save() self.model.save()
############# ##################
# SUBWINDOW # # MSG AND DIALOG #
############# ##################
def msg_select_reach(self): def msg_select_reach(self):
self.message_box("Please select a reach", self.message_box("Please select a reach",
"Geometry edition need a reach selected " "Geometry edition need a reach selected "
"into river network window to work on it") "into river network window to work on it")
def dialog_close(self, cancel = True):
dlg = QMessageBox(self)
dlg.setWindowTitle("Close PAMHYR without saving study")
dlg.setText("Do you want to save current study before PAMHYR close ?")
opt = QMessageBox.Save | QMessageBox.Ignore
if cancel:
opt |= QMessageBox.Cancel
dlg.setStandardButtons(opt)
dlg.setIcon(QMessageBox.Warning)
res = dlg.exec()
if res == QMessageBox.Save:
self.save_study()
return True
elif res == QMessageBox.Ignore:
return True
elif res == QMessageBox.Cancel:
return False
#############
# SUBWINDOW #
#############
def open_configure(self): def open_configure(self):
"""Open configure window """Open configure window
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment