diff --git a/doc/dev/documentation.org b/doc/dev/documentation.org index 16d6a69c0b6e672b32a4c2945bd749b7cd4bde02..c5266896898db85756e0052a953547ac88543a68 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 f671cc6041515869660220f9d331c7e2281ac674..6c93b84eda99b998a6109c5e9f211cc54a81df4e 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 d6ae675247696462aa7b2e21554169c7c9e56a8c..34ff547fb04126e3119ca937866c76950bcc2949 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()