The Python View is a 2D Render View that is configured from a python script, given as property.
One use case is to use external tools like Matplotlib to do the rendering, like here:
ParaView expects 2 methods to be defined in the script in order to works
def render(view, width, height):
This is not easy to discover, and easy to break.
There is no way to manipulate parameters from a GUI. All of them should be defined and modified directly in the python script. This is not a user friendly way to control a view in the application.
This View make me think about
Programmable Filter and I wonder if we may modify the Python View to be more consistent with it.
- Add an API on
vtkPythonView to add a list of custom parameters (
AddParameter(string, string)) and the relevant property
- Create a dedicated property for each method content
setup_data to the
Python Representation part
Those points can be done incrementally.
With the first, it makes it possible to create a XML plugin to create a python view with a hardcoded script while having accessible properties.
Having one property per method seems the correct way to do to me. Expecting only the function content (without
def line) brings consistency with
ProgrammableXXX filters, and make it easier for
vtkPythonView to hook it up. An alternative is to let the
def function(): line be part of the property but put it as the default value so it is more discoverable.
The last point is for consistency with ParaView paradigm. This implies the previous point.
Workaround to control the python with a GUI: Customize Python View with Python plugins
Looks nice to me. What about PythonPlugins ? Would that make the python view compatible with python plugins ?
Nope. Python plugins are still another thing, I didn’t investigate for now.
Currently, the python plugins are
vtkAlgorithm subclasses with inline XML. We should extend support for
vtkView or such.
The Python View definitely has room for improvement, and these proposals make sense. The only thing I’m not sure about is moving the
setup_data to the representation properties. This will move where you set the script in the Properties panel, which may make it harder to find in the UI. You could probably list it last in the representation so that it appears close to the View section in the Properties panel.
As a long-time user of python matplotlib, I find this quite nice!
Is the goal to expose:
- only the matplotlib render window (so all the configuration stays inside the python script)
- the matplotlib parameters so no python script is used
If 1. developping/debugging the script (inside the property panel) will be hard and a solution as an external python plugin seems better
If 2. this seems like a trendemous amount of work, and would be redundant with the existing “raw” plots from paraview (4. Displaying data — ParaView Documentation 5.11.0 documentation)
@ltetrel not sure what you mean.
PythonView script should return a
vtkImageData that is displayed directly in the view (and its not gonna change). We provide some python utility functions for data conversion, so it easier to use other tools like matplotlib inside the script to generate the final image.
What I suggest is to let the user initialize some python variable from the GUI. It is up to the dev to choose which variable to expose and to synchronize the name in the GUI and the name in the python script.