From e3315c8f81b79358d866a02769ed060df9f8fa79 Mon Sep 17 00:00:00 2001
From: Theophile Terraz <theophile.terraz@inrae.fr>
Date: Fri, 14 Feb 2025 14:48:40 +0100
Subject: [PATCH] add 'cancel' button when closing Pamhyr2 from x button

---
 src/View/MainWindow.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py
index 5a251438..f5b015fa 100644
--- a/src/View/MainWindow.py
+++ b/src/View/MainWindow.py
@@ -348,10 +348,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
     def closeEvent(self, event):
         if not self._close_question:
             if self._study is not None and not self._study.is_saved:
-                if self.dialog_close(cancel=False):
+                if self.dialog_close():
                     # PAMHYR is close correctly (no crash)
                     self.conf.set_close_correctly()
                     super(ApplicationWindow, self).closeEvent(event)
+                else:
+                    event.ignore()
         else:
             super(ApplicationWindow, self).closeEvent(event)
 
@@ -531,7 +533,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
         self.update()
 
     def close_model(self):
-        if not self.dialog_close(cancel=True):
+        if not self.dialog_close():
             return
 
         self._study = None
@@ -833,21 +835,19 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
 
         return file
 
-    def dialog_close(self, cancel=True):
+    def dialog_close(self):
         dlg = QMessageBox(self)
 
         dlg.setWindowTitle(self._trad["mb_close_title"])
         dlg.setText(self._trad["mb_close_msg"])
         opt = QMessageBox.Save | QMessageBox.Close
-        if cancel:
-            opt |= QMessageBox.Cancel
+        opt |= QMessageBox.Cancel
 
         dlg.setStandardButtons(opt)
         dlg.setIcon(QMessageBox.Warning)
         dlg.button(QMessageBox.Save).setText(self._trad["Save"])
         dlg.button(QMessageBox.Close).setText(self._trad["Close"])
-        if cancel:
-            dlg.button(QMessageBox.Cancel).setText(self._trad["Cancel"])
+        dlg.button(QMessageBox.Cancel).setText(self._trad["Cancel"])
 
         res = dlg.exec()
 
-- 
GitLab