From a3da09cf5bc79a9ba2ac1d4df323c5a81303360c Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Thu, 4 Sep 2025 09:59:24 +0200 Subject: [PATCH] Mainwindow: Add backup file dialog. --- src/View/MainWindow.py | 24 ++++++++++++++++++++++-- src/View/Translate.py | 10 ++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index fc787061..51a4de10 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -864,12 +864,32 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): if os.path.exists(backup): file_modified_date = time.ctime(os.path.getmtime(file)) backup_modified_date = time.ctime(os.path.getmtime(backup)) + if backup_modified_date > file_modified_date: - logger.info(f"Select backup ({backup})") - file = backup + yes = self.dialog_open_backup_study() + + if yes: + logger.info(f"Select backup ({backup})") + file = backup return file + def dialog_open_backup_study(self): + dlg = QMessageBox(self) + + dlg.setWindowTitle(self._trad["mb_open_backup_title"]) + dlg.setText(self._trad["mb_open_backup_msg"]) + opt = QMessageBox.No | QMessageBox.Yes + + dlg.setStandardButtons(opt) + dlg.setIcon(QMessageBox.Question) + dlg.button(QMessageBox.Yes).setText(self._trad["Yes"]) + dlg.button(QMessageBox.No).setText(self._trad["No"]) + + res = dlg.exec() + + return res == QMessageBox.Yes + def dialog_close(self): dlg = QMessageBox(self) diff --git a/src/View/Translate.py b/src/View/Translate.py index 0ae8ffd9..de52777d 100644 --- a/src/View/Translate.py +++ b/src/View/Translate.py @@ -200,6 +200,15 @@ class MainTranslate(UnitTranslate): "Do you want to open again the last open study?" ) + self._dict["mb_open_backup_title"] = _translate( + "MainWindow", "Open backup file" + ) + self._dict["mb_open_backup_msg"] = _translate( + "MainWindow", + "A more recent backup file as found for this study, " + + "do you want to open the backup file?" + ) + self._dict["mb_close_title"] = _translate( "MainWindow", "Close without saving study" ) @@ -207,6 +216,7 @@ class MainTranslate(UnitTranslate): "MainWindow", "Do you want to save current study before closing it?" ) + self._dict["x"] = _translate("MainWindow", "X (m)") self._dict["y"] = _translate("MainWindow", "Y (m)") self._dict["Yes"] = _translate("MainWindow", "Yes")