napari icon indicating copy to clipboard operation
napari copied to clipboard

Consider ability to 'upgrade' `ViewerModel` to full `Viewer`

Open DragaDoncila opened this issue 11 months ago • 7 comments

🧰 Task

Currently, we have a single provider for the napari Viewer. This provider is used when plugin widgets request a Viewer, but also internally.

Under the hood, the provider just calls and returns the current_viewer:

def current_viewer() -> Optional[Viewer]:
    """Return the currently active napari viewer."""
    try:
        from napari._qt.qt_main_window import _QtMainWindow
    except ImportError:
        return None
    else:
        return _QtMainWindow.current_viewer()

This means even though the Viewer can exist in headless mode, the Viewer provider only works when qt and the window are present.

Do we envisage a world where a plugin (or other API user) might want the headless viewer injected if the qt one is unavailable e.g. chaining commands, computing stuff on layers before showing the viewer, idk. If we think that's a valid use case, we should consider adding a provider for the headless viewer, with a lower weighting than the one we already have.

DragaDoncila avatar Mar 22 '24 06:03 DragaDoncila