napari.qt.Window

class napari.qt.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

File menu.

Type

qtpy.QtWidgets.QMenu

help_menu

Help menu.

Type

qtpy.QtWidgets.QMenu

main_menu

Main menubar.

Type

qtpy.QtWidgets.QMainWindow.menuBar

view_menu

View menu.

Type

qtpy.QtWidgets.QMenu

window_menu

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

activate()[source]

Make the viewer the currently active window.

add_dock_widget(widget: typing.Union[PyQt5.QtWidgets.QWidget, Widget], *, name: str = '', area: str = 'right', allowed_areas: typing.Optional[typing.Sequence[str]] = None, shortcut=<object object>, add_vertical_stretch=True, menu=None, tabify: bool = False)[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.

Returns

dock_widgetdock_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_widgetdock_widget that can pass viewer events.

Return type

QtViewerDockWidget

add_plugin_dock_widget(plugin_name: str, widget_name: Optional[str] = None, tabify: bool = False) Tuple[napari._qt.widgets.qt_viewer_dock_widget.QtViewerDockWidget, Any][source]

Add plugin dock widget if not already added.

Parameters
  • plugin_name (str) – Name of a plugin providing a widget

  • widget_name (str, optional) – Name of a widget provided by plugin_name. If None, and the specified plugin provides only a single widget, that widget will be returned, otherwise a ValueError will be raised, by default None

Returns

A 2-tuple containing (the DockWidget instance, the plugin widget instance).

Return type

tuple

clipboard(flash=True, canvas_only=False)[source]

Copy screenshot of current viewer to the clipboard.

Parameters
  • 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.

close()[source]

Close the viewer window and cleanup sub-widgets.

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: PyQt5.QtWidgets.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 provided widget.

Parameters

widget (QWidget | str) – If widget == ‘all’, all docked widgets will be removed.

resize(width, height)[source]

Resize the window.

Parameters
  • width (int) – Width in logical pixels.

  • height (int) – Height in logical pixels.

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

set_geometry(left, top, width, height)[source]

Set the geometry of the widget

Parameters
  • 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.

show(*, block=False)[source]

Resize, show, and bring forward the window.

Raises

RuntimeError – If the viewer.window has already been closed and deleted.