From 73475220e94e79bff7d076ab98104b00c5fc2446 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Fri, 19 Jan 2024 10:08:30 +0100 Subject: [PATCH] Mainwindow: Add action to open results from a file. --- src/View/MainWindow.py | 37 ++++++++++++++++++++++++++++++++++++- src/View/ui/MainWindow.ui | 9 +++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 793a044e..41a25c07 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -82,7 +82,7 @@ no_model_action = [ model_action = [ "action_menu_close", "action_menu_edit", "action_menu_save", "action_menu_save_as", "action_toolBar_close", "action_toolBar_save", - "action_menu_numerical_parameter", + "action_menu_numerical_parameter", "action_open_results_from_file", ] other_model_action = [ @@ -207,6 +207,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self.open_reach_sediment_layers, "action_menu_close": self.close_model, "action_menu_results_last": self.open_last_results, + "action_open_results_from_file": self.open_results_from_file, # Help "action_menu_pamhyr_users_pdf": lambda: self.open_doc_user(ext="pdf"), @@ -838,6 +839,14 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self._solver_workdir(solver) ) + # Open from file + if type(results) is str: + logger.info(f"Open results from {os.path.dirname(results)}") + results = solver.results( + self._study, + os.path.dirname(results), + ) + # No results available if results is None: return @@ -878,6 +887,32 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self.open_solver_results(self._last_solver, self._last_results) + def open_results_from_file(self): + if self._study is None: + return + + dialog = QFileDialog(self) + dialog.setFileMode(QFileDialog.FileMode.ExistingFile) + dialog.setDefaultSuffix(".BIN") + # dialog.setFilter(dialog.filter() | QtCore.QDir.Hidden) + dialog.setNameFilters(['Mage (*.BIN)']) + + if self._last_solver is None: + dialog.setDirectory( + os.path.dirname(self._study.filename) + ) + else: + dialog.setDirectory( + self._solver_workdir(self._last_solver) + ) + + if dialog.exec_(): + file_name = dialog.selectedFiles() + self.open_solver_results( + self._last_solver, + results=file_name[0] + ) + ################# # DOCUMENTATION # ################# diff --git a/src/View/ui/MainWindow.ui b/src/View/ui/MainWindow.ui index bf73c3d3..ecb069cc 100644 --- a/src/View/ui/MainWindow.ui +++ b/src/View/ui/MainWindow.ui @@ -139,6 +139,7 @@ <string>&Results</string> </property> <addaction name="action_menu_results_last"/> + <addaction name="action_open_results_from_file"/> </widget> <widget class="QMenu" name="menu_cartography"> <property name="locale"> @@ -943,6 +944,14 @@ <string>Edit hydraulic structures</string> </property> </action> + <action name="action_open_results_from_file"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Open results from file</string> + </property> + </action> </widget> <resources/> <connections> -- GitLab