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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider ability to 'upgrade' ViewerModel to full Viewer #6768

Open
DragaDoncila opened this issue Mar 22, 2024 · 7 comments
Open

Consider ability to 'upgrade' ViewerModel to full Viewer #6768

DragaDoncila opened this issue Mar 22, 2024 · 7 comments
Labels

Comments

@DragaDoncila
Copy link
Contributor

馃О 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.

@Czaki
Copy link
Collaborator

Czaki commented Mar 22, 2024

I think that we should promote using ViewerModel in headless mode.

@lucyleeow
Copy link
Contributor

But we never instantiate a ViewerModel in napari? What do you mean @Czaki ?

@lucyleeow
Copy link
Contributor

Or do you mean headless users should always instantiate ViewerModel and we thus should never inject viewer in headless mode?

@Czaki
Copy link
Collaborator

Czaki commented Mar 23, 2024

For current usage we provide active viewer (last focused). How will you determine which viewer use?

@lucyleeow
Copy link
Contributor

True. So no non qt viewer injection then?

@Czaki
Copy link
Collaborator

Czaki commented Mar 23, 2024

I think than in headless mode, user should provide own injection.

@DragaDoncila
Copy link
Contributor Author

I'm on board with disambiguating the use of napari.Viewer as both headless and GUI modes in favour of using ViewerModel in headless mode and napari.Viewer in GUI mode. In that case there should never be any need for plugins/users to need napari to perform injection for them, I think? However, I do think we need a way for a ViewerModel to be "upgraded" to a full Viewer somehow - maybe via an overloaded constructor so like Viewer(my_model) or maybe like viewer = napari.Viewer.from_model(my_model)?

@lucyleeow lucyleeow changed the title Consider adding a provider for Viewer in headless mode Consider ability to 'upgrade' ViewerModel to full Viewer May 7, 2024
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

3 participants