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
|
*** Window
|
||||||
|
|
||||||
An abstract class ASubMainWindow is used for most of Pamhyr2
|
The abstract class PamhyrWindow and PamhyrDialog are used for most of
|
||||||
windows. This class implemente some useful method allows to easy load
|
Pamhyr2 window. These class allow to create an window for Pamhyr2 GUI
|
||||||
an window UI file. In addition, the abstract ListedSubWindow must be
|
and implemente some useful methods.
|
||||||
also inherits by a window class, it is allow to keep a list of open
|
|
||||||
windows and avoid window duplicate.
|
|
||||||
|
|
||||||
#+NAME: window
|
#+NAME: window
|
||||||
#+CAPTION: Example of Pamhyr2 window
|
#+CAPTION: Example of Pamhyr2 window
|
||||||
#+begin_src python :python python3 :results output :noweb yes
|
#+begin_src python :python python3 :results output :noweb yes
|
||||||
class MyWindow(ASubMainWindow, ListedSubWindow):
|
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||||
def __init__(self, title="My window",
|
|
||||||
study=None, config=None, parent=None):
|
|
||||||
self._study = study
|
|
||||||
self._config = config
|
|
||||||
self._parent = parent
|
|
||||||
|
|
||||||
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__(
|
super(MyWindow, self).__init__(
|
||||||
name=title, # The windows name for windows
|
# Window title
|
||||||
# registration (avoid duplicate)
|
title = self._pamhyr_name + " - " + study.name,
|
||||||
ui="My", # The ui file name (here "My.ui")
|
# Window standard data
|
||||||
parent=parent # The parent window
|
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_table()
|
||||||
self.setup_connections()
|
self.setup_connections()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,10 @@ class ListedSubWindow(object):
|
||||||
def sub_win_add(self, name, win):
|
def sub_win_add(self, name, win):
|
||||||
self.sub_win_list.append((name, win))
|
self.sub_win_list.append((name, win))
|
||||||
self.sub_win_cnt += 1
|
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):
|
def sub_win_del(self, name):
|
||||||
self.sub_win_list = list(
|
self.sub_win_list = list(
|
||||||
|
|
@ -46,7 +49,7 @@ class ListedSubWindow(object):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.sub_win_cnt = len(self.sub_win_list)
|
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):
|
def _sub_win_exists(self, name):
|
||||||
return reduce(
|
return reduce(
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class PamhyrWindowTools(object):
|
||||||
def __init__(self, options = ["undo", "copy"], parent = None, **kwargs):
|
def __init__(self, options = ["undo", "copy"], parent = None, **kwargs):
|
||||||
super(PamhyrWindowTools, self).__init__()
|
super(PamhyrWindowTools, self).__init__()
|
||||||
|
|
||||||
|
self._hash_data = []
|
||||||
self._undo_stack = None
|
self._undo_stack = None
|
||||||
|
|
||||||
if "undo" in options:
|
if "undo" in options:
|
||||||
|
|
@ -130,12 +131,7 @@ class PamhyrWindowTools(object):
|
||||||
Returns:
|
Returns:
|
||||||
The hash
|
The hash
|
||||||
"""
|
"""
|
||||||
data = [
|
return self._hash(self._hash_data)
|
||||||
self._study,
|
|
||||||
self._config,
|
|
||||||
]
|
|
||||||
|
|
||||||
return self._hash()
|
|
||||||
|
|
||||||
|
|
||||||
class PamhyrWindow(ASubMainWindow, ListedSubWindow, PamhyrWindowTools):
|
class PamhyrWindow(ASubMainWindow, ListedSubWindow, PamhyrWindowTools):
|
||||||
|
|
@ -152,14 +148,15 @@ class PamhyrWindow(ASubMainWindow, ListedSubWindow, PamhyrWindowTools):
|
||||||
self._config = config
|
self._config = config
|
||||||
self._parent = parent
|
self._parent = parent
|
||||||
|
|
||||||
logger.info(self._pamhyr_name)
|
|
||||||
|
|
||||||
super(PamhyrWindow, self).__init__(
|
super(PamhyrWindow, self).__init__(
|
||||||
name = self._pamhyr_name,
|
name = self._pamhyr_name,
|
||||||
ui = self._pamhyr_ui,
|
ui = self._pamhyr_ui,
|
||||||
parent = parent,
|
parent = parent,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._hash_data.append(self._study)
|
||||||
|
self._hash_data.append(self._config)
|
||||||
|
|
||||||
self._set_title()
|
self._set_title()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue