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.

export_figure([path, scale, flash])

Export an image of the full extent of the displayed layer data.

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: ~PyQt5.QtWidgets.QWidget | Widget, *, name: str = '', area: str | None = None, allowed_areas: ~collections.abc.Sequence[str] | None = None, shortcut=<object object>, add_vertical_stretch=True, tabify: bool = False, menu: ~qtpy.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 the 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 localization.

  • tabify (bool) – Flag to tabify dock widget or not.

  • menu (QMenu, optional) – Menu bar to add toggle action to. If None nothing added to menu.

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: str | None = None, tabify: bool = False) tuple[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

  • tabify (bool) – Flag to tabify dock widget or not.

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.

export_figure(path: str | None = None, scale: float = 1, flash=True) ndarray[source]#

Export an image of the full extent of the displayed layer data.

This function finds a tight boundary around the data, resets the view around that boundary (and, when scale=1, such that 1 captured pixel is equivalent to one data pixel), takes a screenshot, then restores the previous zoom and canvas sizes. Currently, only works when 2 dimensions are displayed.

Parameters:
  • path (str, optional) – Filename for saving screenshot image.

  • scale (float) – Scale factor used to increase resolution of canvas for the screenshot. By default, a scale of 1.

  • flash (bool) – Flag to indicate whether flash animation should be shown after the screenshot was captured. 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

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 provided widget.

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

  • menu (QMenu, optional) – Menu bar to remove toggle action from. If None nothing removed from menu.

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 includes 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.