diff --git a/doc/dev/documentation.org b/doc/dev/documentation.org index bbef8dc214f174aef64918786fbd6d8eb0476dd2..7dd65b9bac8a8ae0f4e4fa4ed37b3e68ad372417 100644 --- a/doc/dev/documentation.org +++ b/doc/dev/documentation.org @@ -1,5 +1,5 @@ # documentation.org -- Pamhyr developers documentation -# Copyright (C) 2023 INRAE +# Copyright (C) 2023-2024 INRAE # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -538,44 +538,44 @@ generic value from optional parameters, for examples: #+NAME: window #+CAPTION: Example of Pamhyr2 window #+begin_src python :python python3 :results output :noweb yes - from View.Tools.PamhyrWindow import PamhyrWindow - from View.My.Translate import MyTranslate - from View.My.Table import MyTableModel - - 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__( - # Window title - title = self._pamhyr_name + " - " + study.name, - # Window standard data - study = study, config = config, - trad = MyTranslate(), - parent = parent, - # Activate undo/redo and copy/paste shortcut - options = ["undo", "copy"] - ) + from View.Tools.PamhyrWindow import PamhyrWindow + from View.My.Translate import MyTranslate + from View.My.Table import MyTableModel + + class MyWindow(PamhyrWindow): + _pamhyr_ui = "MyUI" + _pamhyr_name = "My window" + + def __init__(self, study=None, config=None, + my_data=None, + parent=None): + self._my_data = my_data + + super(MyWindow, self).__init__( + # Window title + title = self._pamhyr_name + " - " + study.name, + # Window standard data + study = study, config = config, + trad = MyTranslate(), + parent = parent, + # Activate undo/redo and copy/paste shortcut + options = ["undo", "copy"] + ) - # Add custom data to hash window computation - self._hash_data.append(self._my_data) + # Add custom data to hash window computation + self._hash_data.append(self._my_data) - # Setup custom window components - self.setup_table() - self.setup_connections() + # Setup custom window components + self.setup_table() + self.setup_connections() - def setup_table(self): - # Init table(s)... + def setup_table(self): + # Init table(s)... - def setup_connections(self): - # Init action connection(s)... + def setup_connections(self): + # Init action connection(s)... - # ... + # ... #+end_src Typically we called method =setup_*=, the method to initialize some @@ -661,11 +661,13 @@ creation, this stack is accessible at =self._undo_stack=. *** Plot -To define a new plot you can create a class who inherit to APlot. The -creator need threee argument: +To define a new plot you can create a class who inherit to +PamhyrPlot. The creator need at leaste five argument: - A =canvas= of type =MplCanvas= + - A (optional) =trad= of type =PamhyrTranslate= - A =data= used in =draw= and =update= to create and update the plot - A optional =toolbar= of type =PamhyrToolbar= + - A =parent= window This class must implement two method =draw= and =update=, the first method to draw the plot from scratch, the second to update the plot if data has changed. @@ -673,19 +675,36 @@ data has changed. #+begin_src python :python python3 :results output :noweb yes from View.Tools.PamhyrPlot import PamhyrPlot - class MyPlot(APlot): - def __init__(self, canvas=None, data=None, toolbar=None): + class MyPlot(PamhyrPlot): + def __init__(self, canvas=None, trad=None, toolbar=None + data=None, parent=None): super(MyPlot, self).__init__( canvas=canvas, + trad=trad, data=data, - toolbar=toolbar + toolbar=toolbar, + parent=parent ) + self.label_x = self._trad["x"] + self.label_y = self._trad["y"] + + # Optional configuration + self._isometric_axis = False + + self._auto_relim_update = True + self._autoscale_update = True + def draw(self): # Draw function code... - def update(self, ind = None): + def update(self): # Update function code... + + def clear(self): + # Clear plot values... + + # ... #+end_src ** Solver @@ -745,7 +764,7 @@ execute a code on distant computer, for example, over ssh. style=dashed; subgraph cluster021 { label="Solver Classes"; - classSolverM7[label="Mage7", fillcolor=6]; + //classSolverM7[label="Mage7", fillcolor=6]; classSolverM8[label="Mage8", fillcolor=6]; classSolverR[label="RubarBE", fillcolor=6]; } @@ -828,7 +847,7 @@ solver and get results: - (2.1) The solver read the input file(s) - (2.2) The solver compute results and write it to solver output file(s) - - (3) Pamhyr2 create a Reuslts + - (3) Pamhyr2 create a =Results= object - (3.1) The Pamhyr2 solver class read solver output file(s) and complete Results with readed data @@ -958,8 +977,16 @@ different methods: ** Unit tests -The unit tests is actually not implemented in Pamhyr2, it is a *work -in progress*. +A very small part of Pamhyr2 has unit test. This part is limited to the Model. + +#+begin_src shell + python3 -m venv test + . test test/bin/activate + pip3 install -U -r ./full-requirements.txt + + cd src/ + python3 -Walways -m unittest discovert -v -t . +#+end_src ** The debug mode @@ -970,14 +997,14 @@ line: ./Pamhyr2 debug #+end_src -This mode add some log and add two action in main window menu: -"About/Debug" open a window with Python Repl in current Python -environement, and "About/Debug SQLite" who open the application +This mode add some log and add two action in main window menu: "About +> Debug" open a window with Python Repl in current Python +environement, and "About > Debug SQLite" who open the application SQLiteBrowser (if installed) on current Study to explore the study data base file. #+NAME: debug-repl -#+ATTR_LATEX: :width 12cm +#+ATTR_LATEX: :width 14cm #+CAPTION: Pamhyr2 debug Python REPL [[./images/python-debug-repl.png]] diff --git a/doc/dev/images/python-debug-repl.png b/doc/dev/images/python-debug-repl.png index 847f4afc6f94829f2ccc3abc729505e841fa6626..ef11efa77621f4501b84a23c6a9943106997fe7a 100644 Binary files a/doc/dev/images/python-debug-repl.png and b/doc/dev/images/python-debug-repl.png differ