Skip to content

Commit 797e460

Browse files
committed
Try custom scrapers
1 parent 0be3f7b commit 797e460

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

docs/conf.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# import os
1414
# import sys
1515
# sys.path.insert(0, os.path.abspath('.'))
16-
import qtgallery
16+
from sphinx_gallery import scrapers
1717

1818
# -- Project information -----------------------------------------------------
1919

@@ -33,22 +33,59 @@
3333
"sphinx_automodapi.automodapi",
3434
"sphinx_automodapi.smart_resolver",
3535
"sphinx.ext.intersphinx",
36-
"qtgallery",
3736
]
3837

38+
39+
def reset_napari(gallery_conf, fname):
40+
from napari.settings import get_settings
41+
from qtpy.QtWidgets import QApplication
42+
43+
settings = get_settings()
44+
settings.appearance.theme = "dark"
45+
46+
# Disabling `QApplication.exec_` means example scripts can call `exec_`
47+
# (scripts work when run normally) without blocking example execution by
48+
# sphinx-gallery. (from qtgallery)
49+
QApplication.exec_ = lambda _: None
50+
51+
52+
def napari_scraper(block, block_vars, gallery_conf):
53+
"""Basic napari window scraper.
54+
55+
Looks for any QtMainWindow instances and takes a screenshot of them.
56+
57+
`app.processEvents()` allows Qt events to propagateo and prevents hanging.
58+
"""
59+
import napari
60+
61+
imgpath_iter = block_vars["image_path_iterator"]
62+
63+
if app := napari.qt.get_app():
64+
app.processEvents()
65+
else:
66+
return ""
67+
68+
img_paths = []
69+
for win, img_path in zip(
70+
reversed(napari._qt.qt_main_window._QtMainWindow._instances),
71+
imgpath_iter,
72+
):
73+
img_paths.append(img_path)
74+
win._window.screenshot(img_path, canvas_only=False)
75+
76+
napari.Viewer.close_all()
77+
app.processEvents()
78+
79+
return scrapers.figure_rst(img_paths, gallery_conf["src_dir"])
80+
81+
3982
sphinx_gallery_conf = {
4083
"filename_pattern": ".",
41-
"image_scrapers": (qtgallery.qtscraper,),
42-
"reset_modules": (qtgallery.reset_qapp,),
84+
"image_scrapers": (napari_scraper,),
85+
"reset_modules": (reset_napari,),
4386
}
4487
suppress_warnings = ["config.cache"]
4588

46-
qtgallery_conf = {
47-
"xvfb_size": (640, 480),
48-
"xvfb_color_depth": 24,
49-
"xfvb_use_xauth": False,
50-
"xfvb_extra_args": [],
51-
}
5289

5390
numpydoc_show_class_members = False
5491
automodapi_inheritance_diagram = True

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ docs =
5151
numpydoc
5252
pydantic<2
5353
pydata-sphinx-theme
54-
qtgallery
5554
sphinx
5655
sphinx-automodapi
5756
sphinx-gallery

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy