From e7fd2077bd3f7c390488fc352df98205026a5d75 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Tue, 26 Sep 2023 14:19:22 +0200
Subject: [PATCH] doc: dev: Update with PamhyrWindow, and minor change in hash
 computation.

---
 doc/dev/documentation.org         | 40 +++++++++++++++++--------------
 src/View/Tools/ListedSubWindow.py |  7 ++++--
 src/View/Tools/PamhyrWindow.py    | 13 ++++------
 3 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/doc/dev/documentation.org b/doc/dev/documentation.org
index 16d6a69c..c5266896 100644
--- a/doc/dev/documentation.org
+++ b/doc/dev/documentation.org
@@ -445,33 +445,37 @@ window, and =/src/View/ui/Widgets= for custom widget.
 
 *** Window
 
-An abstract class ASubMainWindow is used for most of Pamhyr2
-windows. This class implemente some useful method allows to easy load
-an window UI file. In addition, the abstract ListedSubWindow must be
-also inherits by a window class, it is allow to keep a list of open
-windows and avoid window duplicate.
+The abstract class PamhyrWindow and PamhyrDialog are used for most of
+Pamhyr2 window. These class allow to create an window for Pamhyr2 GUI
+and implemente some useful methods.
 
 #+NAME: window
 #+CAPTION: Example of Pamhyr2 window
 #+begin_src python :python python3 :results output :noweb yes
-  class MyWindow(ASubMainWindow, ListedSubWindow):
-      def __init__(self, title="My window",
-                   study=None, config=None, parent=None):
-          self._study = study
-          self._config = config
-          self._parent = parent
+  from View.Tools.PamhyrWindow import PamhyrWindow
 
-          self._title = title + " - " + study.name
+  class MyWindow(PamhyrWindow):
+      _pamhyr_ui = "MyUI"
+      _pamhyr_name = "My window"
+
+      def __init__(self, my_data=None,
+                   study=None, config=None,
+                   parent=None):
+          self._my_data = my_data
 
           super(MyWindow, self).__init__(
-              name=title,         # The windows name for windows
-                                  # registration (avoid duplicate)
-              ui="My",            # The ui file name (here "My.ui")
-              parent=parent       # The parent window
+              # Window title
+              title = self._pamhyr_name + " - " + study.name,
+              # Window standard data
+              study = study, config = config, parent = parent,
+              # Activate undo/redo and copy/paste shortcut
+              options = ["undo", "copy"]
           )
-          # Set Windows title
-          self.ui.setWindowTitle(self._title)
 
+          # Add custom data to hash window computation
+          self._hash_data.append(self._my_data)
+
+          # Setup custom window components
           self.setup_table()
           self.setup_connections()
 
diff --git a/src/View/Tools/ListedSubWindow.py b/src/View/Tools/ListedSubWindow.py
index f671cc60..6c93b84e 100644
--- a/src/View/Tools/ListedSubWindow.py
+++ b/src/View/Tools/ListedSubWindow.py
@@ -36,7 +36,10 @@ class ListedSubWindow(object):
     def sub_win_add(self, name, win):
         self.sub_win_list.append((name, win))
         self.sub_win_cnt += 1
-        logger.info(f"Open window: {name} ({self.sub_win_cnt})")
+        try:
+            logger.info(f"Open window: {name}: {self.sub_win_cnt}: {win.hash()}")
+        except:
+            logger.info(f"Open window: {name}: {self.sub_win_cnt}: X")
 
     def sub_win_del(self, name):
         self.sub_win_list = list(
@@ -46,7 +49,7 @@ class ListedSubWindow(object):
             )
         )
         self.sub_win_cnt = len(self.sub_win_list)
-        logger.info(f"Close window: {name} ({self.sub_win_cnt})")
+        logger.info(f"Close window: {name}: {self.sub_win_cnt}")
 
     def _sub_win_exists(self, name):
         return reduce(
diff --git a/src/View/Tools/PamhyrWindow.py b/src/View/Tools/PamhyrWindow.py
index d6ae6752..34ff547f 100644
--- a/src/View/Tools/PamhyrWindow.py
+++ b/src/View/Tools/PamhyrWindow.py
@@ -35,6 +35,7 @@ class PamhyrWindowTools(object):
     def __init__(self, options = ["undo", "copy"], parent = None, **kwargs):
         super(PamhyrWindowTools, self).__init__()
 
+        self._hash_data = []
         self._undo_stack = None
 
         if "undo" in options:
@@ -130,12 +131,7 @@ class PamhyrWindowTools(object):
         Returns:
             The hash
         """
-        data = [
-            self._study,
-            self._config,
-        ]
-
-        return self._hash()
+        return self._hash(self._hash_data)
 
 
 class PamhyrWindow(ASubMainWindow, ListedSubWindow, PamhyrWindowTools):
@@ -152,14 +148,15 @@ class PamhyrWindow(ASubMainWindow, ListedSubWindow, PamhyrWindowTools):
         self._config = config
         self._parent = parent
 
-        logger.info(self._pamhyr_name)
-
         super(PamhyrWindow, self).__init__(
             name = self._pamhyr_name,
             ui = self._pamhyr_ui,
             parent = parent,
         )
 
+        self._hash_data.append(self._study)
+        self._hash_data.append(self._config)
+
         self._set_title()
 
 
-- 
GitLab