napari.window.Window#
- class napari.window.Window(viewer: Viewer, *, show: bool = True)[source]#
Bases:
object
Application window that contains the menu bar and viewer.
- Parameters:
viewer (napari.components.ViewerModel) – Contained viewer widget.
File menu.
- Type:
qtpy.QtWidgets.QMenu
Help menu.
- Type:
qtpy.QtWidgets.QMenu
Main menubar.
- Type:
qtpy.QtWidgets.QMainWindow.menuBar
View menu.
- Type:
qtpy.QtWidgets.QMenu
Window menu.
- Type:
qtpy.QtWidgets.QMenu
Methods
activate
()Make the viewer the currently active window.
add_dock_widget
(widget, *[, name, area, ...])Convenience method to add a QDockWidget to the main window.
add_function_widget
(function, *[, ...])Turn a function into a dock widget via magicgui.
add_plugin_dock_widget
(plugin_name[, ...])Add plugin dock widget if not already added.
clipboard
([flash, canvas_only])Copy screenshot of current viewer to the clipboard.
close
()Close the viewer window and cleanup sub-widgets.
geometry
()Get the geometry of the widget
remove_dock_widget
(widget[, menu])Removes specified dock widget.
resize
(width, height)Resize the window.
screenshot
([path, size, scale, flash, ...])Take currently displayed viewer and convert to an image array.
set_geometry
(left, top, width, height)Set the geometry of the widget
show
(*[, block])Resize, show, and bring forward the window.
Attributes
qt_viewer
Details
- add_dock_widget(widget: ~PySide2.QtWidgets.QWidget | Widget, *, name: str = '', area: str = 'right', allowed_areas: ~typing.Sequence[str] | None = None, shortcut=<object object>, add_vertical_stretch=True, tabify: bool = False, menu: ~PySide2.QtWidgets.QMenu | None = None)[source]#
Convenience method to add a QDockWidget to the main window.
If name is not provided a generic name will be addded to avoid saveState warnings on close.
- Parameters:
widget (QWidget) – widget will be added as QDockWidget’s main widget.
name (str, optional) – Name of dock widget to appear in window menu.
area (str) – Side of the main window to which the new dock widget will be added. Must be in {‘left’, ‘right’, ‘top’, ‘bottom’}
allowed_areas (list[str], optional) – Areas, relative to main window, that the widget is allowed dock. Each item in list must be in {‘left’, ‘right’, ‘top’, ‘bottom’} By default, all areas are allowed.
shortcut (str, optional) – Keyboard shortcut to appear in dropdown menu.
add_vertical_stretch (bool, optional) –
Whether to add stretch to the bottom of vertical widgets (pushing widgets up towards the top of the allotted area, instead of letting them distribute across the vertical space). By default, True.
Deprecated since version 0.4.8: The shortcut parameter is deprecated since version 0.4.8, please use the action and shortcut manager APIs. The new action manager and shortcut API allow user configuration and localisation.
tabify (bool) – Flag to tabify dockwidget or not.
menu (QMenu, optional) – Menu bar to add toggle action to. If None nothing added to menu.
- Returns:
dock_widget – dock_widget that can pass viewer events.
- Return type:
QtViewerDockWidget
- add_function_widget(function, *, magic_kwargs=None, name: str = '', area=None, allowed_areas=None, shortcut=<object object>)[source]#
Turn a function into a dock widget via magicgui.
- Parameters:
function (callable) – Function that you want to add.
magic_kwargs (dict, optional) – Keyword arguments to
magicgui.magicgui()
that can be used to specify widget.name (str, optional) – Name of dock widget to appear in window menu.
area (str, optional) – Side of the main window to which the new dock widget will be added. Must be in {‘left’, ‘right’, ‘top’, ‘bottom’}. If not provided the default will be determined by the widget.layout, with ‘vertical’ layouts appearing on the right, otherwise on the bottom.
allowed_areas (list[str], optional) – Areas, relative to main window, that the widget is allowed dock. Each item in list must be in {‘left’, ‘right’, ‘top’, ‘bottom’} By default, only provided areas is allowed.
shortcut (str, optional) – Keyboard shortcut to appear in dropdown menu.
- Returns:
dock_widget – dock_widget that can pass viewer events.
- Return type:
QtViewerDockWidget
- add_plugin_dock_widget(plugin_name: str, widget_name: str | None = None, tabify: bool = False) Tuple[QtViewerDockWidget, Any] [source]#
Add plugin dock widget if not already added.
- Parameters:
- Returns:
A 2-tuple containing (the DockWidget instance, the plugin widget instance).
- Return type:
- clipboard(flash=True, canvas_only=False)[source]#
Copy screenshot of current viewer to the clipboard.
- geometry() Tuple[int, int, int, int] [source]#
Get the geometry of the widget
- Returns:
left (int) – X coordinate of the upper left border.
top (int) – Y coordinate of the upper left border.
width (int) – Width of the rectangle shape of the window.
height (int) – Height of the rectangle shape of the window.
- remove_dock_widget(widget: QWidget, menu=None)[source]#
Removes specified dock widget.
If a QDockWidget is not provided, the existing QDockWidgets will be searched for one whose inner widget (
.widget()
) is the providedwidget
.- Parameters:
widget (QWidget | str) – If widget == ‘all’, all docked widgets will be removed.
- screenshot(path=None, size=None, scale=None, flash=True, canvas_only=False)[source]#
Take currently displayed viewer and convert to an image array.
- Parameters:
path (str) – Filename for saving screenshot image.
size (tuple (int, int)) – Size (resolution) of the screenshot. By default, the currently displayed size. Only used if canvas_only is True.
scale (float) – Scale factor used to increase resolution of canvas for the screenshot. By default, the currently displayed resolution. Only used if canvas_only is True.
flash (bool) – Flag to indicate whether flash animation should be shown after the screenshot was captured.
canvas_only (bool) – If True, screenshot shows only the image display canvas, and if False include the napari viewer frame in the screenshot, By default, True.
- Returns:
image – Numpy array of type ubyte and shape (h, w, 4). Index [0, 0] is the upper-left corner of the rendered region.
- Return type:
array
- show(*, block=False)[source]#
Resize, show, and bring forward the window.
- Raises:
RuntimeError – If the viewer.window has already been closed and deleted.