Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gallery scraper: enable preserving viewer between code cells. #527

Open
psobolewskiPhD opened this issue Nov 21, 2024 · 1 comment
Open
Labels

Comments

@psobolewskiPhD
Copy link
Member

🧰 Task

This issue stems from the discussion here: napari/napari#7319 (comment)
Essentially, the idea was to make a notebook example that involves multiple steps each using the same viewer.
As it turns out, the scraper runs for each block, takes a screenshot, and then the viewer is cleaned up, so any following cells referring to it cause exceptions.

One can work around it by calling a new viewer in each cell, as done here:
https://github.com/napari/napari/blob/main/examples/dynamic-projections-dask.py
This looks good:
https://napari.org/stable/gallery/dynamic-projections-dask.html#sphx-glr-gallery-dynamic-projections-dask-py
But the actual notebook is awkward and not how a notebook would be used locally?

Ideally, the scraper would work the same way as jupytext/jupyter book parsing of notebooks in our workshop repo, e.g.
https://napari.org/napari-workshop-template/notebooks/spot_detection.html

Here the viewer persists until closed and nbscreenshot can be used to show viewer states.

@lucyleeow
Copy link
Collaborator

Some details on how to implement single viewer for each example:

The current scraper looks for any QtMainWindow instances and takes a screenshot of all of them. AFAICT we can still do this if we persist the viewer between code blocks.

To clean up the viewer we can use the Sphinx-Gallery config reset_modules, which lets you add a function to run (before|after|before and after) each example.

Taking a look at the examples, the following use code block splitters, which may need to be amended if we change how the screenshot-er works:

  • dynamic-projections-dask.py
  • surface_multi_texture.py
  • vortex.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants