mirror of https://gitlab.com/pamhyr/pamhyr2
doc: dev: Update with PamhyrWindow, and minor change in hash computation.
parent
624e9b6f71
commit
e7fd2077bd
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue