radioviz.views.image_window

Module for image window views and canvas management.

This module provides the view components for displaying images in a dedicated window with support for overlays, context menus, and interactive features. It includes specialized canvas widgets and window containers for handling image data visualization.

Module Attributes

T_SubWindowController

Type of sub-window controller paired with CanvasWindow.

T_Canvas

Type of matplotlib canvas hosted inside CanvasWindow.

Classes

CanvasWindow(controller[, parent])

Base window class for canvas-based views.

ImageWindow(controller[, parent])

Window class for displaying image data with advanced features.

class radioviz.views.image_window.CanvasWindow(controller: T_SubWindowController, parent: QWidget | None = None)[source]

Bases: SubWindow[T_SubWindowController], Generic[T_SubWindowController, T_Canvas]

Base window class for canvas-based views.

This class serves as a base for windows that contain matplotlib canvases, providing common functionality for canvas management and interaction.

Initialize the canvas window.

Parameters:
  • controller (SubWindowController[Any]) – The controller managing this window

  • parent (QWidget, optional) – Parent widget, defaults to None

create_canvas() T_Canvas[source]

Factory hook used to build the matplotlib canvas widget for the window.

Subclasses must override this to provide the concrete canvas type they need.

class radioviz.views.image_window.ImageWindow(controller: ImageWindowController, parent: QWidget | None = None)[source]

Bases: CanvasWindow[ImageWindowController, TiffCanvas]

Window class for displaying image data with advanced features.

This class implements a specialized window for displaying image data with support for overlays, context menus, and interactive point selection. It manages the matplotlib canvas and handles various user interactions.

Initialize the image window.

Parameters:
  • controller (ImageWindowController) – The controller managing this window

  • parent (QWidget, optional) – Parent widget, defaults to None

_apply_axis_label_mode() None[source]

Apply axis label mode to the image axes.

This method updates axis visibility, labels, and tick formatting based on the controller’s axis label mode and pixel size metadata.

_apply_pending_canvas_update() None[source]

Apply the most recent pending canvas update request.

_build_colorbar_signature() tuple[float | None, float | None, str][source]

Build a signature of display properties that affect the colorbar.

Returns:

Tuple of (vmin, vmax, cmap_name).

Return type:

tuple[object, object, object]

_factor_from_density(px_per_screen: float) int[source]

Choose the coarsest factor that still preserves visual information.

Selects the largest allowed scale factor that doesn’t exceed the pixel density threshold to maintain visual quality while optimizing performance.

Parameters:

px_per_screen (float) – Pixels per screen unit in current view

Returns:

The selected scale factor

Return type:

int

_factor_matches_request(factor: int) bool[source]

Check if the given factor matches the current requested factor.

Compares the provided factor against the snapped version of the requested factor.

Parameters:

factor (int) – The factor to check

Returns:

True if factors match, False otherwise

Return type:

bool

_handle_view_change() None[source]

Process view change by updating requested factor and requesting display update.

Calculates the appropriate display resolution factor based on current view and requests an update to the display with that factor.

_on_context(pos: QPoint) None[source]

Handle context menu requests on the canvas.

Parameters:

pos (QPoint) – Position of the context menu request

_on_first_draw(event: Event) None[source]

Handle the first draw event of the canvas.

Connects resize event handler and disconnects first draw handler after first draw. Triggers view change handling after initial drawing.

Parameters:

event (matplotlib.backend_bases.DrawEvent) – The matplotlib draw event

_on_level_ready(factor: int) None[source]

Handle when a requested display level is ready for rendering.

Processes the received image data and updates the canvas display if the factor matches the current request.

Parameters:

factor (int) – The resolution factor for which data is ready

_on_move(ev: object) None[source]

Handle mouse move events on the canvas.

Parameters:

ev (MouseEvent) – The mouse event data

_on_press(event: object) None[source]

Handle mouse press events on the canvas.

Parameters:

event (MouseEvent) – The mouse event data

_on_view_change(event: Event) None[source]

Handle view change events on the axes.

Prevents recursive calls during updates and schedules view change handling.

_request_display_update() None[source]

Request a display update with the current requested factor.

Sends a request to the controller to prepare the appropriate resolution level for display based on the currently requested factor.

_schedule_canvas_update(image: ndarray, factor: int) None[source]

Schedule a canvas update and coalesce rapid updates.

Parameters:
  • image (numpy.ndarray) – The image data to render.

  • factor (int) – The scale factor used for the image.

_update_canvas(image: ndarray, factor: int) None[source]

Update the canvas with the provided image data.

Redraws the image on the canvas with appropriate scaling and maintains current view limits and colorbar.

Parameters:
  • image (numpy.ndarray) – The image data to display

  • factor (int) – The scale factor used for the image

_update_colorbar_if_needed() None[source]

Ensure the colorbar exists and update it only when display properties change.

_update_requested_factor_from_view() None[source]

Calculate the requested display factor based on current view density.

Determines the appropriate scaling factor based on how many pixels per screen unit are currently visible in the view.

Returns:

The calculated display factor

Return type:

int

create_canvas() TiffCanvas[source]

Create the TIFF canvas used by image windows.

Returns:

A newly constructed TIFF canvas

Return type:

TiffCanvas

export_to_path(path: Path) None[source]

Export the current image display to a file.

Saves the current figure displayed in the canvas to the specified path using matplotlib’s savefig functionality.

Parameters:

path (pathlib.Path) – The file path where the image should be saved

handle_point_selection_mode(activate: bool) None[source]

Handle activation of point selection mode.

Enables or disables point selection mode on the canvas and manages toolbar suspension accordingly.

Parameters:

activate (bool) – Whether to activate point selection mode

initialize_overlay_renderer() OverlayRenderer[source]

Initialize the overlay renderer for the canvas.

Creates and configures the overlay renderer to manage visual overlays on the image display.

Returns:

The initialized overlay renderer

Return type:

OverlayRenderer

on_data_state_changed() None[source]

Update the window title when data state changes.

This method is called when the underlying data state changes, such as when the data is modified or saved. It updates the window title to reflect the current persistence status.

set_image_properties() None[source]

Set image properties on the plot.

Updates the clim and other properties of the image plot based on current controller settings.

Raises:

ValueError – If invalid property values are encountered

set_window_title() None[source]

Set the window title based on controller name and dirty state.

Updates the window title to include an asterisk (*) suffix if the controller indicates that the data has been modified but not yet saved. The title is derived from the controller’s name property.

update_canvas() None[source]

Update the canvas with current image settings.

Applies current colormap, interpolation, and level settings to the image and redraws the canvas.

mouse_moved

Signal emitted when mouse is moved over the canvas.

mouse_pressed

Signal emitted when mouse button is pressed on the canvas.

class radioviz.views.image_window.T_Canvas

Type of matplotlib canvas hosted inside CanvasWindow.

alias of TypeVar(‘T_Canvas’, bound=MPLCanvas)

class radioviz.views.image_window.T_SubWindowController

Type of sub-window controller paired with CanvasWindow.

alias of TypeVar(‘T_SubWindowController’, bound=SubWindowController[Any])