mirror of https://gitlab.com/pamhyr/pamhyr2
doc: dev: View section (UI, window).
parent
42dfdcc3b1
commit
afa21c9057
|
|
@ -347,7 +347,7 @@ of Bar (Listing [[sql-bar]] and [[sql-foo]]).
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+NAME: sql-foo
|
#+NAME: sql-foo
|
||||||
#+CAPTION: Exemple of class Foo inherits SQLSubModel.
|
#+CAPTION: Exemple of class Foo inherits SQLSubModel and contains a list of Bar object (Listing [[sql-bar]]).
|
||||||
#+begin_src python :python python3 :results output :noweb yes
|
#+begin_src python :python python3 :results output :noweb yes
|
||||||
class Foo(SQLSubModel):
|
class Foo(SQLSubModel):
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
@ -420,11 +420,119 @@ basic methods for object dictionary in Model. This class is like
|
||||||
PamhyrModelList but use a dictionary instead of list.
|
PamhyrModelList but use a dictionary instead of list.
|
||||||
|
|
||||||
** TODO View
|
** TODO View
|
||||||
*** TODO UI file
|
|
||||||
*** TODO Translate
|
Pamhyr2 use Qt as graphical user interface library with the
|
||||||
*** TODO Window
|
application "Qt designer" for windows or widget creation (see [[UI file]])
|
||||||
|
and "Qt linguist" for interface translate (see [[Translate]]). In
|
||||||
|
addition, we use matplotlib as ploting library (see [[Plot]]).
|
||||||
|
|
||||||
|
Typically, each model componant have an associated window in
|
||||||
|
application to add, delete or edit this componant. At top level of
|
||||||
|
View directory we found the =MainWindow.py= file and some
|
||||||
|
sub-directories. A view sub-directory contains: A =Window.py= file, a
|
||||||
|
=Table.py= file with table model definition if nessessary, one or more
|
||||||
|
=Plot*.py= file with plot class definition, a =translate.py= file with
|
||||||
|
componant translate, and possible other files or sub-directories.
|
||||||
|
|
||||||
|
*** UI file
|
||||||
|
|
||||||
|
We define as possible all Pamhyr2 windows and custom widgets with "Qt
|
||||||
|
designer". This application generate UI file who describes interface
|
||||||
|
organisation with table, layout, button, etc. This method is faster
|
||||||
|
than hand made windows and widget creation, and saves us some purely
|
||||||
|
descriptive code. The UI files are saved into =src/View/ui= for
|
||||||
|
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.
|
||||||
|
|
||||||
|
#+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
|
||||||
|
|
||||||
|
self._title = title + " - " + study.name
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
# Set Windows title
|
||||||
|
self.ui.setWindowTitle(self._title)
|
||||||
|
|
||||||
|
self.setup_table()
|
||||||
|
self.setup_connections()
|
||||||
|
|
||||||
|
def setup_table(self):
|
||||||
|
# Init table(s)...
|
||||||
|
|
||||||
|
def setup_connections(self):
|
||||||
|
# Init action connection(s)...
|
||||||
|
|
||||||
|
# ...
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Typically we called method =setup_*=, the method to initialize some
|
||||||
|
window componants or connections.
|
||||||
|
|
||||||
|
*** Table
|
||||||
|
|
||||||
|
An abstract class PamhyrTableModel is available to define a simple
|
||||||
|
QAbstractTableModel shortly. In simple cases, there are only =data=
|
||||||
|
and =setData= methode to implement, but the constructor needs more
|
||||||
|
information than a classic QAbstractTableModel class.
|
||||||
|
|
||||||
|
#+begin_src python :python python3 :results output :noweb yes
|
||||||
|
# Table headers with display name translatable (translate.py)
|
||||||
|
table_headers = {
|
||||||
|
"foo": _translate("My", "Foo"),
|
||||||
|
"bar": _translate("My", "Bar"),
|
||||||
|
"baz": _translate("My", "Baz"),
|
||||||
|
}
|
||||||
|
|
||||||
|
def retranslate():
|
||||||
|
# Hack because dict definition is not able to be
|
||||||
|
# translate... (need to be called in window '__init__')
|
||||||
|
table_headers["foo"] = _translate("My", "Foo")
|
||||||
|
table_headers["bar"] = _translate("My", "Bar")
|
||||||
|
table_headers["baz"] = _translate("My", "Baz")
|
||||||
|
|
||||||
|
# Table model definition (Table.py)
|
||||||
|
class MyTableModel(PamhyrTableModel):
|
||||||
|
def data(self, index, role):
|
||||||
|
# Retrun data at INDEX...
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def setData(self, index, value, role=Qt.EditRole):
|
||||||
|
# Set VALUE at INDEX...
|
||||||
|
|
||||||
|
# Table model creation (Window.py)
|
||||||
|
self._model = MyTableModel(
|
||||||
|
table_view = table, # The table view object
|
||||||
|
table_headers = table_headers, # The table column headers dict
|
||||||
|
# (with traduction)
|
||||||
|
editable_headers = ["foo", "bar"], # List of editable column name
|
||||||
|
delegates = {
|
||||||
|
"bar": self.my_delegate, # Custom delegate for column 'bar'
|
||||||
|
},
|
||||||
|
data = self._my_lst, # The data
|
||||||
|
undo = self._undo_stack, # The undo command stack
|
||||||
|
)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
*** TODO UndoCommand
|
*** TODO UndoCommand
|
||||||
*** TODO Table
|
|
||||||
*** TODO Plot
|
*** TODO Plot
|
||||||
*** TODO Mainwindow
|
*** TODO Mainwindow
|
||||||
** TODO Solver
|
** TODO Solver
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue