From 36fd8cdc8ae03abc0ca16bded411bea0e54245db Mon Sep 17 00:00:00 2001
From: Youcef AOUAD <youcef.aouad@inrae.fr>
Date: Tue, 22 Oct 2024 11:35:29 +0200
Subject: [PATCH] display adists results from main

---
 src/View/MainWindow.py        | 46 +++++++++++++++++++++++++++++++++++
 src/View/Results/translate.py |  3 ++-
 src/View/ui/MainWindow.ui     |  9 +++++++
 3 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py
index bd68b652..4e41ce46 100644
--- a/src/View/MainWindow.py
+++ b/src/View/MainWindow.py
@@ -23,6 +23,8 @@ import logging
 import subprocess
 from queue import Queue
 from functools import reduce
+
+from numpy.core.multiarray import where
 from platformdirs import user_cache_dir
 
 from Solver.AdisTS import AdisTS
@@ -41,6 +43,7 @@ from PyQt5.QtWidgets import (
     QMainWindow, QApplication, QAction,
     QFileDialog, QShortcut, QMenu, QToolBar,
     QMessageBox, QProgressDialog, QTabWidget,
+    QDialog, QVBoxLayout, QLabel,
 )
 from PyQt5.uic import loadUi
 
@@ -106,6 +109,7 @@ 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_open_results_from_file",
+    "action_open_results_adists",
 ]
 
 other_model_action = [
@@ -271,6 +275,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
             "action_menu_close": self.close_model,
             "action_menu_results_last": self.open_last_results,
             "action_open_results_from_file": self.open_results_from_file,
+            "action_open_results_adists": self.open_results_adists,
             # Help
             "action_menu_pamhyr_users_wiki": self.open_doc_user,
             "action_menu_pamhyr_developers_pdf":
@@ -1532,6 +1537,47 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
                 results=file_name[0]
             )
 
+    def open_results_adists(self):
+        if self._study is None:
+            return
+
+        if self._study.filename == "":
+            return
+
+        options = QFileDialog.Options()
+        options |= QFileDialog.DontUseNativeDialog
+
+        dialog = QFileDialog(self, options=options)
+        dialog.setFileMode(QFileDialog.DirectoryOnly) ##QFileDialog.FileMode.ExistingFile)
+
+        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_():
+            dir_path = dialog.selectedFiles()[0]
+            dir_list = os.listdir(dir_path)
+            bin_list = list(filter(lambda s: "bin" in s, dir_list))
+            logger.info(f"Select results: {dir_path}")
+            if len(bin_list) >= 2 and ("total_sediment.bin" in bin_list):
+                self.open_solver_results_adists(
+                    self._last_solver,
+                    results=None,
+                )
+            else:
+                dlg = QDialog(self)
+                dlg.setWindowTitle("AdisTS Results")
+                layout  = QVBoxLayout()
+                message = QLabel("AdisTS Results not found")
+                layout.addWidget(message)
+                dlg.setLayout(layout)
+                dlg.exec()
+
     #################
     # DOCUMENTATION #
     #################
diff --git a/src/View/Results/translate.py b/src/View/Results/translate.py
index 243e618d..fd3550c0 100644
--- a/src/View/Results/translate.py
+++ b/src/View/Results/translate.py
@@ -27,7 +27,8 @@ class ResultsTranslate(MainTranslate):
     def __init__(self, pollutants=None):
         if pollutants is not None:
             self.pollutants = pollutants
-            self.pollutants.remove("total_sediment")
+            if "total_sediment" in self.pollutants:
+                self.pollutants.remove("total_sediment")
         else:
             self.pollutants = pollutants
 
diff --git a/src/View/ui/MainWindow.ui b/src/View/ui/MainWindow.ui
index 9dba82a2..3ee6d998 100644
--- a/src/View/ui/MainWindow.ui
+++ b/src/View/ui/MainWindow.ui
@@ -161,6 +161,7 @@
     </property>
     <addaction name="action_menu_results_last"/>
     <addaction name="action_open_results_from_file"/>
+    <addaction name="action_open_results_adists"/>
    </widget>
    <widget class="QMenu" name="menu_help">
     <property name="title">
@@ -773,6 +774,14 @@
     <string>DIF</string>
    </property>
   </action>
+  <action name="action_open_results_adists">
+   <property name="enabled">
+    <bool>false</bool>
+   </property>
+   <property name="text">
+    <string>Open results AdisTS</string>
+   </property>
+  </action>
  </widget>
  <resources/>
  <connections>
-- 
GitLab