question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Theme updates should update more things

See original GitHub issue

tl; 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: Screenshot from 2022-01-07 22-05-28 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:open
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adeakcommented, Jan 12, 2022

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.

1reaction
MatthewFlammcommented, Jan 11, 2022

Do we agree that updating the theme should change things like renderer background colours?

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Update WordPress Theme without Losing Customization
Updating a WordPress theme overwrites all your customization. Learn how to update a WordPress theme without losing customization.
Read more >
How to Update a WordPress Theme – Your Safe and In-Depth ...
Don't throw away all your customizations just because of an incompatible update ! Learn how to perform updates safely with this guide ...
Read more >
How to Update a WordPress Theme in 6 Steps or Less
Below, we'll cover why you need to regularly update your theme, ... Many theme updates, for example, are focused on reducing the weight...
Read more >
How To Update a WordPress Theme - Kinsta®
The most important reason to ensure that the code in your site is always updated is security. A significant proportion of updates to...
Read more >
How To Safely Update WordPress Theme Without Losing ...
Another important reason why you need to look into updating your WordPress website is that there are high chances thet developer might add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found