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

Exclude animation dock widget from viewer screenshot #23

Open
sofroniewn opened this issue Jan 30, 2021 · 6 comments
Open

Exclude animation dock widget from viewer screenshot #23

sofroniewn opened this issue Jan 30, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@sofroniewn
Copy link
Collaborator

One thing that might be nice is to figure out how to exclude the animation dock widget from the viewer screenshot if it is not wanted. I guess the widget can always be undocked, but it is something we might want to consider

@alisterburt
Copy link
Collaborator

I guess the use case is for creating animations showing how to do things in the viewer/the effect of changing things in the viewer? Makes sense, will have a think

@alisterburt
Copy link
Collaborator

@katherine-hutchings @cormsby626 this would be a slightly more technical place to contribute which could be fun!

The whole dock widget will need to be hidden, not just the AnimationWidget which lives inside the dock widget - something like
viewer.window._dock_widgets['animation: Wizard'].hide()
viewer.window._dock_widgets['animation: Wizard'].show()
will get us going but it would be good to see if we can achieve this using the public API... maybe @tlambert03 or @DragaDoncila knows if there is a nice public API for hiding dock widgets?

As before, feel free to ping me any time if you choose to take this on, either here or on the napari zulip

@tlambert03
Copy link
Contributor

tlambert03 commented Aug 26, 2022

maybe @tlambert03 or @DragaDoncila knows if there is a nice public API for hiding dock widgets?

nope, but I'd say it's ultimately the same request as napari/napari#2203 and napari/napari#3944 (which needs someone to love it)

@katherine-hutchings
Copy link
Contributor

Hi Guys I had a go at implementing this in the way suggested, however it did not seem to work as expected.

Hiding the instance of QtViewerDockWidget from the integrated ipython console works as expected, but when this is called during the animate method the canvas does not resize itself to take up the extra space.
image

I tried to make a minimal example in napari, but could not reproduce so the issue must be something to do with napari-animation.

import napari
from magicgui import magicgui

viewer = napari.Viewer()

widget_name = 'widget'

@magicgui
def my_func():
    viewer.window._dock_widgets[widget_name].hide()


viewer.window.add_dock_widget(my_func, name=widget_name)
napari.run()

@tlambert03 @Czaki - @alisterburt mentioned you guys know a lot about Qt, is this something you immediately know the cause of?

@tlambert03
Copy link
Contributor

yeah, hiding a specific dock widget will do just that: hide the dock widget. But what you really need to manipulate here is the QMainWindow instance itself... specifically, with removeDockWidget and restoreDockWidget. You could do this with a context manager

from contextlib import contextmanager

@contextmanager
def hidden_dock_widget(window: QMainWindow, widget: QDockWidget):
    window.removeDockWidget(widget)
    try:
        yield
    finally:
        window.restoreDockWidget(widget)
with hidden_dock_widget(viewer.window._qt_window, your_dock_widget):
    # render

@katherine-hutchings
Copy link
Contributor

Thank you very much, I will look into this :)

@psobolewskiPhD psobolewskiPhD added the enhancement New feature or request label Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants