mirror of https://gitlab.com/pamhyr/pamhyr2
MainWindow: Add save question at PAMHYR closed.
parent
4ed1aef4a5
commit
e617738fcd
|
|
@ -14,6 +14,7 @@ from PyQt5.QtCore import (
|
|||
from PyQt5.QtWidgets import (
|
||||
QMainWindow, QApplication, QAction,
|
||||
QFileDialog, QShortcut, QMenu, QToolBar,
|
||||
QMessageBox,
|
||||
)
|
||||
from PyQt5.uic import loadUi
|
||||
|
||||
|
|
@ -77,6 +78,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
def __init__(self, conf=None):
|
||||
super(ApplicationWindow, self).__init__()
|
||||
|
||||
self._close_question = False
|
||||
|
||||
# App Configuration
|
||||
self.conf = conf
|
||||
|
||||
|
|
@ -175,6 +178,24 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
self.retranslateUi()
|
||||
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):
|
||||
"""Set default window style
|
||||
|
||||
|
|
@ -262,6 +283,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
else:
|
||||
self.model.filename = file_name + ".pamhyr"
|
||||
|
||||
print("[INFO] Save...")
|
||||
self.model.save()
|
||||
|
||||
def save_as_study(self):
|
||||
|
|
@ -285,15 +307,41 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
|
||||
self.model.save()
|
||||
|
||||
#############
|
||||
# SUBWINDOW #
|
||||
#############
|
||||
##################
|
||||
# MSG AND DIALOG #
|
||||
##################
|
||||
|
||||
def msg_select_reach(self):
|
||||
self.message_box("Please select a reach",
|
||||
"Geometry edition need a reach selected "
|
||||
"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):
|
||||
"""Open configure window
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue