|
13 | 13 | # import os
|
14 | 14 | # import sys
|
15 | 15 | # sys.path.insert(0, os.path.abspath('.'))
|
16 |
| -import qtgallery |
| 16 | +from sphinx_gallery import scrapers |
17 | 17 |
|
18 | 18 | # -- Project information -----------------------------------------------------
|
19 | 19 |
|
|
33 | 33 | "sphinx_automodapi.automodapi",
|
34 | 34 | "sphinx_automodapi.smart_resolver",
|
35 | 35 | "sphinx.ext.intersphinx",
|
36 |
| - "qtgallery", |
37 | 36 | ]
|
38 | 37 |
|
| 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 | + |
39 | 82 | sphinx_gallery_conf = {
|
40 | 83 | "filename_pattern": ".",
|
41 |
| - "image_scrapers": (qtgallery.qtscraper,), |
42 |
| - "reset_modules": (qtgallery.reset_qapp,), |
| 84 | + "image_scrapers": (napari_scraper,), |
| 85 | + "reset_modules": (reset_napari,), |
43 | 86 | }
|
44 | 87 | suppress_warnings = ["config.cache"]
|
45 | 88 |
|
46 |
| -qtgallery_conf = { |
47 |
| - "xvfb_size": (640, 480), |
48 |
| - "xvfb_color_depth": 24, |
49 |
| - "xfvb_use_xauth": False, |
50 |
| - "xfvb_extra_args": [], |
51 |
| -} |
52 | 89 |
|
53 | 90 | numpydoc_show_class_members = False
|
54 | 91 | automodapi_inheritance_diagram = True
|
|
0 commit comments