Skip to content

ndv.views.bases #

Abstract base classes for views and viewable objects.

Classes:

  • ArrayCanvas

    ABC for canvases that show array data.

  • ArrayView

    ABC for ND Array viewers widget.

  • CanvasElement

    Protocol defining an interactive element on the Canvas.

  • HistogramCanvas

    A histogram-based view for LookUp Table (LUT) adjustment.

  • LutView

    Manages LUT properties (contrast, colormap, etc...) in a view object.

  • Mouseable

    Mixin class for objects that can be interacted with using the mouse.

  • Viewable

    ABC representing anything that can be viewed on screen.

ArrayCanvas #

Bases: GraphicsCanvas

ABC for canvases that show array data.

Methods:

  • canvas_to_world

    Map XY canvas position (pixels) to XYZ coordinate in world space.

  • close

    Close the view/widget.

  • frontend_widget

    Return the native object backing the viewable objects.

  • set_visible

    Sets the visibility of the view/widget itself.

canvas_to_world abstractmethod #

canvas_to_world(
    pos_xy: tuple[float, float],
) -> tuple[float, float, float]

Map XY canvas position (pixels) to XYZ coordinate in world space.

Source code in ndv/views/bases/_graphics/_canvas.py
35
36
37
38
39
@abstractmethod
def canvas_to_world(
    self, pos_xy: tuple[float, float]
) -> tuple[float, float, float]:
    """Map XY canvas position (pixels) to XYZ coordinate in world space."""

close abstractmethod #

close() -> None

Close the view/widget.

Source code in ndv/views/bases/_view_base.py
19
20
21
@abstractmethod
def close(self) -> None:
    """Close the view/widget."""

frontend_widget abstractmethod #

frontend_widget() -> Any

Return the native object backing the viewable objects.

Source code in ndv/views/bases/_view_base.py
11
12
13
@abstractmethod
def frontend_widget(self) -> Any:
    """Return the native object backing the viewable objects."""

set_visible abstractmethod #

set_visible(visible: bool) -> None

Sets the visibility of the view/widget itself.

Source code in ndv/views/bases/_view_base.py
15
16
17
@abstractmethod
def set_visible(self, visible: bool) -> None:
    """Sets the visibility of the view/widget itself."""

ArrayView #

ArrayView(
    canvas_widget: Any,
    model: _ArrayDataDisplayModel,
    **kwargs: Any,
)

Bases: Viewable

ABC for ND Array viewers widget.

Currently, this is the "main" widget that contains the array display and all the controls for interacting with the array, includings sliders, LUTs, and histograms.

Methods:

  • close

    Close the view/widget.

  • frontend_widget

    Return the native object backing the viewable objects.

  • set_visible

    Sets the visibility of the view/widget itself.

Source code in ndv/views/bases/_array_view.py
36
37
38
39
@abstractmethod
def __init__(
    self, canvas_widget: Any, model: _ArrayDataDisplayModel, **kwargs: Any
) -> None: ...

close abstractmethod #

close() -> None

Close the view/widget.

Source code in ndv/views/bases/_view_base.py
19
20
21
@abstractmethod
def close(self) -> None:
    """Close the view/widget."""

frontend_widget abstractmethod #

frontend_widget() -> Any

Return the native object backing the viewable objects.

Source code in ndv/views/bases/_view_base.py
11
12
13
@abstractmethod
def frontend_widget(self) -> Any:
    """Return the native object backing the viewable objects."""

set_visible abstractmethod #

set_visible(visible: bool) -> None

Sets the visibility of the view/widget itself.

Source code in ndv/views/bases/_view_base.py
15
16
17
@abstractmethod
def set_visible(self, visible: bool) -> None:
    """Sets the visibility of the view/widget itself."""

CanvasElement #

Bases: Mouseable

Protocol defining an interactive element on the Canvas.

Methods:

  • can_select

    Defines whether the element can be selected.

  • cursor_at

    Returns the element's cursor preference at the provided position.

  • move

    Behavior executed throughout a "move" operation.

  • remove

    Removes the element from the canvas.

  • selected

    Returns element selection status.

  • set_selected

    Sets element selection status.

  • set_visible

    Sets element visibility.

  • start_move

    Behavior executed at the beginning of a "move" operation.

  • visible

    Defines whether the element is visible on the canvas.

can_select abstractmethod #

can_select() -> bool

Defines whether the element can be selected.

Source code in ndv/views/bases/_graphics/_canvas_elements.py
28
29
30
@abstractmethod
def can_select(self) -> bool:
    """Defines whether the element can be selected."""

cursor_at #

cursor_at(pos: Sequence[float]) -> CursorType | None

Returns the element's cursor preference at the provided position.

Source code in ndv/views/bases/_graphics/_canvas_elements.py
40
41
def cursor_at(self, pos: Sequence[float]) -> CursorType | None:
    """Returns the element's cursor preference at the provided position."""

move #

move(pos: Sequence[float]) -> None

Behavior executed throughout a "move" operation.

In layman's terms, this is the behavior executed during the "drag" of a "click-and-drag".

Source code in ndv/views/bases/_graphics/_canvas_elements.py
51
52
53
54
55
56
57
def move(self, pos: Sequence[float]) -> None:
    """
    Behavior executed throughout a "move" operation.

    In layman's terms, this is the behavior executed during the "drag"
    of a "click-and-drag".
    """

remove #

remove() -> None

Removes the element from the canvas.

Source code in ndv/views/bases/_graphics/_canvas_elements.py
59
60
def remove(self) -> None:
    """Removes the element from the canvas."""

selected abstractmethod #

selected() -> bool

Returns element selection status.

Source code in ndv/views/bases/_graphics/_canvas_elements.py
32
33
34
@abstractmethod
def selected(self) -> bool:
    """Returns element selection status."""

set_selected abstractmethod #

set_selected(selected: bool) -> None

Sets element selection status.

Source code in ndv/views/bases/_graphics/_canvas_elements.py
36
37
38
@abstractmethod
def set_selected(self, selected: bool) -> None:
    """Sets element selection status."""

set_visible abstractmethod #

set_visible(visible: bool) -> None

Sets element visibility.

Source code in ndv/views/bases/_graphics/_canvas_elements.py
24
25
26
@abstractmethod
def set_visible(self, visible: bool) -> None:
    """Sets element visibility."""

start_move #

start_move(pos: Sequence[float]) -> None

Behavior executed at the beginning of a "move" operation.

In layman's terms, this is the behavior executed during the the "click" of a "click-and-drag".

Source code in ndv/views/bases/_graphics/_canvas_elements.py
43
44
45
46
47
48
49
def start_move(self, pos: Sequence[float]) -> None:
    """
    Behavior executed at the beginning of a "move" operation.

    In layman's terms, this is the behavior executed during the the "click"
    of a "click-and-drag".
    """

visible abstractmethod #

visible() -> bool

Defines whether the element is visible on the canvas.

Source code in ndv/views/bases/_graphics/_canvas_elements.py
20
21
22
@abstractmethod
def visible(self) -> bool:
    """Defines whether the element is visible on the canvas."""

HistogramCanvas #

Bases: GraphicsCanvas, LutView

A histogram-based view for LookUp Table (LUT) adjustment.

Methods:

canvas_to_world abstractmethod #

canvas_to_world(
    pos_xy: tuple[float, float],
) -> tuple[float, float, float]

Map XY canvas position (pixels) to XYZ coordinate in world space.

Source code in ndv/views/bases/_graphics/_canvas.py
35
36
37
38
39
@abstractmethod
def canvas_to_world(
    self, pos_xy: tuple[float, float]
) -> tuple[float, float, float]:
    """Map XY canvas position (pixels) to XYZ coordinate in world space."""

close abstractmethod #

close() -> None

Close the view/widget.

Source code in ndv/views/bases/_view_base.py
19
20
21
@abstractmethod
def close(self) -> None:
    """Close the view/widget."""

frontend_widget abstractmethod #

frontend_widget() -> Any

Return the native object backing the viewable objects.

Source code in ndv/views/bases/_view_base.py
11
12
13
@abstractmethod
def frontend_widget(self) -> Any:
    """Return the native object backing the viewable objects."""

set_auto_scale abstractmethod #

set_auto_scale(checked: bool) -> None

Set the autoscale button to checked if checked is True.

Source code in ndv/views/bases/_lut_view.py
23
24
25
@abstractmethod
def set_auto_scale(self, checked: bool) -> None:
    """Set the autoscale button to checked if `checked` is True."""

set_channel_name abstractmethod #

set_channel_name(name: str) -> None

Set the name of the channel to name.

Source code in ndv/views/bases/_lut_view.py
19
20
21
@abstractmethod
def set_channel_name(self, name: str) -> None:
    """Set the name of the channel to `name`."""

set_channel_visible abstractmethod #

set_channel_visible(visible: bool) -> None

Check or uncheck the visibility indicator of the LUT.

Usually corresponds to a checkbox.

Source code in ndv/views/bases/_lut_view.py
41
42
43
44
45
46
@abstractmethod
def set_channel_visible(self, visible: bool) -> None:
    """Check or uncheck the visibility indicator of the LUT.

    Usually corresponds to a checkbox.
    """

set_clims abstractmethod #

set_clims(clims: tuple[float, float]) -> None

Set the (low, high) contrast limits to clims.

Usually this will be a range slider or two text boxes.

Source code in ndv/views/bases/_lut_view.py
34
35
36
37
38
39
@abstractmethod
def set_clims(self, clims: tuple[float, float]) -> None:
    """Set the (low, high) contrast limits to `clims`.

    Usually this will be a range slider or two text boxes.
    """

set_colormap abstractmethod #

set_colormap(cmap: Colormap) -> None

Set the colormap to cmap.

Usually corresponds to a dropdown menu.

Source code in ndv/views/bases/_lut_view.py
27
28
29
30
31
32
@abstractmethod
def set_colormap(self, cmap: cmap.Colormap) -> None:
    """Set the colormap to `cmap`.

    Usually corresponds to a dropdown menu.
    """

set_data #

set_data(values: ndarray, bin_edges: ndarray) -> None

Sets the histogram data.

Properties

values : np.ndarray The histogram values. bin_edges : np.ndarray The bin edges of the histogram.

Source code in ndv/views/bases/_graphics/_canvas.py
83
84
85
86
87
88
89
90
91
92
def set_data(self, values: np.ndarray, bin_edges: np.ndarray) -> None:
    """Sets the histogram data.

    Properties
    ----------
    values : np.ndarray
        The histogram values.
    bin_edges : np.ndarray
        The bin edges of the histogram.
    """

set_gamma #

set_gamma(gamma: float) -> None

Set the gamma value of the LUT.

Source code in ndv/views/bases/_lut_view.py
48
49
50
def set_gamma(self, gamma: float) -> None:
    """Set the gamma value of the LUT."""
    return None

set_log_base #

set_log_base(base: float | None) -> None

Sets the axis scale of the range.

Properties

enabled : bool If true, the range will be displayed with a logarithmic (base 10) scale. If false, the range will be displayed with a linear scale.

Source code in ndv/views/bases/_graphics/_canvas.py
73
74
75
76
77
78
79
80
81
def set_log_base(self, base: float | None) -> None:
    """Sets the axis scale of the range.

    Properties
    ----------
    enabled : bool
        If true, the range will be displayed with a logarithmic (base 10)
        scale. If false, the range will be displayed with a linear scale.
    """

set_vertical #

set_vertical(vertical: bool) -> None

If True, orient axes vertically (x-axis on left).

Source code in ndv/views/bases/_graphics/_canvas.py
70
71
def set_vertical(self, vertical: bool) -> None:
    """If True, orient axes vertically (x-axis on left)."""

set_visible abstractmethod #

set_visible(visible: bool) -> None

Sets the visibility of the view/widget itself.

Source code in ndv/views/bases/_view_base.py
15
16
17
@abstractmethod
def set_visible(self, visible: bool) -> None:
    """Sets the visibility of the view/widget itself."""

LutView #

Bases: Viewable

Manages LUT properties (contrast, colormap, etc...) in a view object.

Methods:

close abstractmethod #

close() -> None

Close the view/widget.

Source code in ndv/views/bases/_view_base.py
19
20
21
@abstractmethod
def close(self) -> None:
    """Close the view/widget."""

frontend_widget abstractmethod #

frontend_widget() -> Any

Return the native object backing the viewable objects.

Source code in ndv/views/bases/_view_base.py
11
12
13
@abstractmethod
def frontend_widget(self) -> Any:
    """Return the native object backing the viewable objects."""

set_auto_scale abstractmethod #

set_auto_scale(checked: bool) -> None

Set the autoscale button to checked if checked is True.

Source code in ndv/views/bases/_lut_view.py
23
24
25
@abstractmethod
def set_auto_scale(self, checked: bool) -> None:
    """Set the autoscale button to checked if `checked` is True."""

set_channel_name abstractmethod #

set_channel_name(name: str) -> None

Set the name of the channel to name.

Source code in ndv/views/bases/_lut_view.py
19
20
21
@abstractmethod
def set_channel_name(self, name: str) -> None:
    """Set the name of the channel to `name`."""

set_channel_visible abstractmethod #

set_channel_visible(visible: bool) -> None

Check or uncheck the visibility indicator of the LUT.

Usually corresponds to a checkbox.

Source code in ndv/views/bases/_lut_view.py
41
42
43
44
45
46
@abstractmethod
def set_channel_visible(self, visible: bool) -> None:
    """Check or uncheck the visibility indicator of the LUT.

    Usually corresponds to a checkbox.
    """

set_clims abstractmethod #

set_clims(clims: tuple[float, float]) -> None

Set the (low, high) contrast limits to clims.

Usually this will be a range slider or two text boxes.

Source code in ndv/views/bases/_lut_view.py
34
35
36
37
38
39
@abstractmethod
def set_clims(self, clims: tuple[float, float]) -> None:
    """Set the (low, high) contrast limits to `clims`.

    Usually this will be a range slider or two text boxes.
    """

set_colormap abstractmethod #

set_colormap(cmap: Colormap) -> None

Set the colormap to cmap.

Usually corresponds to a dropdown menu.

Source code in ndv/views/bases/_lut_view.py
27
28
29
30
31
32
@abstractmethod
def set_colormap(self, cmap: cmap.Colormap) -> None:
    """Set the colormap to `cmap`.

    Usually corresponds to a dropdown menu.
    """

set_gamma #

set_gamma(gamma: float) -> None

Set the gamma value of the LUT.

Source code in ndv/views/bases/_lut_view.py
48
49
50
def set_gamma(self, gamma: float) -> None:
    """Set the gamma value of the LUT."""
    return None

set_visible abstractmethod #

set_visible(visible: bool) -> None

Sets the visibility of the view/widget itself.

Source code in ndv/views/bases/_view_base.py
15
16
17
@abstractmethod
def set_visible(self, visible: bool) -> None:
    """Sets the visibility of the view/widget itself."""

Mouseable #

Mixin class for objects that can be interacted with using the mouse.

The signals here are to be emitted by the view object that inherits this class; usually by intercepting native mouse events with filter_mouse_events.

The methods allow the object to handle its own mouse events before emitting the signals. If the method returns True, the event is considered handled and should not be passed to the next receiver in the chain.

Viewable #

Bases: ABC

ABC representing anything that can be viewed on screen.

For example, a widget, a window, a frame, canvas, etc.

Methods:

  • close

    Close the view/widget.

  • frontend_widget

    Return the native object backing the viewable objects.

  • set_visible

    Sets the visibility of the view/widget itself.

close abstractmethod #

close() -> None

Close the view/widget.

Source code in ndv/views/bases/_view_base.py
19
20
21
@abstractmethod
def close(self) -> None:
    """Close the view/widget."""

frontend_widget abstractmethod #

frontend_widget() -> Any

Return the native object backing the viewable objects.

Source code in ndv/views/bases/_view_base.py
11
12
13
@abstractmethod
def frontend_widget(self) -> Any:
    """Return the native object backing the viewable objects."""

set_visible abstractmethod #

set_visible(visible: bool) -> None

Sets the visibility of the view/widget itself.

Source code in ndv/views/bases/_view_base.py
15
16
17
@abstractmethod
def set_visible(self, visible: bool) -> None:
    """Sets the visibility of the view/widget itself."""