Theme updates should update more things
See original GitHub issuetl; dr
This doesn’t make the background dark:
import pyvista as pv
plotter = pv.Plotter()
# plotter = pv.Plotter(theme=pv.themes.DarkTheme()) # this would work
plotter.theme = pv.themes.DarkTheme()
plotter.add_mesh(pv.Dodecahedron())
plotter.show()
Prologue
I first noticed that the example for Plotter.theme
doesn’t actually work:
Note the blatant lack of dark theme in the figure.
I first found https://github.com/pyvista/pyvista/pull/2003 but even after fixing that I realised that theme updates don’t change a lot of things in plots. In other words, pl = pv.Plotter(theme=DarkTheme())
works, pl = pv.Plotter(); pl.theme = DarkTheme()
only partly.
There are bits and pieces in BasePlotter.__init__()
, e.g.
https://github.com/pyvista/pyvista/blob/1990b018fc82c4fcce2c7d5fcee3dece33a42821/pyvista/plotting/plotting.py#L258-L264
and Plotter.__init__()
, e.g.
https://github.com/pyvista/pyvista/blob/1990b018fc82c4fcce2c7d5fcee3dece33a42821/pyvista/plotting/plotting.py#L4519-L4536
For example, self.set_background()
defers to self.renderers.set_background()
which dispatches to self.renderer.set_background()
, which uses the Renderer
’s _theme
attribute which is a reference to the parent Plotter
’s theme. However, when we update a Plotter
’s theme using the setter, https://github.com/pyvista/pyvista/blob/1990b018fc82c4fcce2c7d5fcee3dece33a42821/pyvista/plotting/plotting.py#L284-L290
we’re updating the theme but we aren’t calling a bunch of methods that were called in the various __init__()
s (among them self.set_background()
).
Question
Do we agree that updating the theme should change things like renderer background colours? If we do, we need to identify these theme-specific initialization calls, move them to a private method, and call it both in the __init__()
s and after updating themes. It gets even muddier due to both BasePlotter
and Plotter
being involved. (Side note: pyvistaqt.BackgroundPlotter
doesn’t seem to support per-plotter theming at all, alas.)
Any thoughts on how we could tackle this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
OK, if we remove the setter we should probably create a deep copy of the theme passed in and make the theme a read-only property (actually, looking at the implementation we’re probably already doing the copy, but it might not be deep). Then we only have to explicitly document that the theme’s configuration matters at the time of instantiating the plotter.
I’ll look at theme usage in plotting.py anyway, just to try and get an impression of the various places it’s used. But I agree that pinning the use of the theme to a single point will make for behaviour that’s a lot easier to argue about.
Why do we have a setter here unless this is true? This is to say that I agree. Your suggestion on implementation seems good to me and standardizing the internal API as much as possible makes sense to me too.