radioviz.tools.flip_image_tool

Flip image tool implementation.

This tool provides horizontal and vertical flipping of images. The flip can be applied either in-place to the current image or by creating a derived image. The implementation follows the standard tool workflow, executing the flip in a background thread and using a tool session for lifecycle management.

The module implements the following components:

Added in version 1.1.0.

Functions

flip_image_worker(request)

Flip an image in a background thread.

Classes

FlipImageRequest(image, flip_mode)

Parameters required to compute an image flip.

FlipImageResult(image, flip_mode)

Output payload of the flip worker.

FlipImageTool()

Tool entry point for flipping images.

FlipImageToolController(tool_ctx, tool)

Controller for horizontal/vertical image flips.

FlipImageToolSession(tool_controller, ...)

Session handling a single flip operation.

class radioviz.tools.flip_image_tool.FlipImageRequest(image: ndarray, flip_mode: str)[source]

Bases: object

Parameters required to compute an image flip.

Variables:
  • image (np.ndarray) – Input image data.

  • flip_mode (str) – Flip mode, either 'horizontal' or 'vertical'.

class radioviz.tools.flip_image_tool.FlipImageResult(image: ndarray, flip_mode: str)[source]

Bases: object

Output payload of the flip worker.

Variables:
  • image (np.ndarray) – Flipped image data.

  • flip_mode (str) – Flip mode applied.

class radioviz.tools.flip_image_tool.FlipImageTool[source]

Bases: Tool[FlipImageToolController]

Tool entry point for flipping images.

Variables:
  • id (uuid.UUID) – Unique identifier for this tool instance.

  • tool_id (str) – String identifier used for tool registration and lookup.

  • name (str) – Human-readable name displayed in menus and dialogs.

  • description (str) – Brief description of the tool’s functionality.

  • _controller (Optional[FlipImageToolController]) – The controller instance created by this tool.

Initialize the flip image tool.

create_controller(ctx: ToolContext) FlipImageToolController[source]

Create and return the tool controller.

Parameters:

ctx (ToolContext) – The tool context providing access to application services.

Returns:

The created tool controller.

Return type:

FlipImageToolController

description: str = 'Flip an image horizontally or vertically.'

Tooltip or description

name: str = 'Flip Image'

Human-readable name

tool_id: str = 'flipimage'

Unique identifier of the tool

class radioviz.tools.flip_image_tool.FlipImageToolController(tool_ctx: ToolContext, tool: Tool[FlipImageToolController])[source]

Bases: ToolController[ImageWindowController, FlipImageToolSession]

Controller for horizontal/vertical image flips.

This controller manages flip sessions, dependency tracking for in-place modifications, and committing flip results.

Variables:
  • active_session (Optional[FlipImageToolSession]) – The currently active flip session, if any.

  • procedure_can_start (ActionDescriptor) – Action descriptor controlling menu enablement.

Initialize the flip tool controller.

Parameters:
  • tool_ctx (ToolContext) – The tool context providing access to application services.

  • tool (Tool) – The tool instance that owns this controller.

_create_new_image(image_controller: ImageWindowController, request: FlipImageRequest, result: FlipImageResult) None[source]

Create a new image window with the flipped image.

Parameters:
_dependent_derived_images(image_controller: ImageWindowController) list[ImageWindowController][source]

Find all derived images that depend on the given image.

Parameters:

image_controller (ImageWindowController) – The image controller to find dependents for.

Returns:

List of derived image controllers that depend on the given image.

Return type:

list[ImageWindowController]

_invalidate_dependencies(image_controller: ImageWindowController) None[source]

Invalidate and close all items that depend on the given image.

Parameters:

image_controller (ImageWindowController) – The image controller whose dependencies should be invalidated.

_on_active_image_changed(new_window_controller: SubWindowController[Any] | None) None[source]

Handle changes to the active image controller.

Parameters:

new_window_controller (SubWindowController) – The newly active sub-window controller.

activate(flip_mode: str = 'horizontal', output_mode: str = 'new_image') None[source]

Activate the tool and start a flip session.

Parameters:
  • flip_mode (str) – Flip mode to apply.

  • output_mode (str) – Output mode, either 'new_image' or 'in_place'.

commit_result(image_controller: ImageWindowController, request: FlipImageRequest, result: FlipImageResult, output_mode: str) None[source]

Commit the flip result to the image controller.

Parameters:
  • image_controller (ImageWindowController) – The image controller to commit the result to.

  • request (FlipImageRequest) – The original flip request parameters.

  • result (FlipImageResult) – The flip result containing the flipped image.

  • output_mode (str) – The output mode, either 'new_image' or 'in_place'.

count_inplace_dependencies(image_controller: ImageWindowController) int[source]

Count the number of items that depend on the given image.

Parameters:

image_controller (ImageWindowController) – The image controller to check dependencies for.

Returns:

The total count of dependent items.

Return type:

int

create_dock(parent_window: QWidget) None[source]

Create a dock widget for this tool.

This tool does not use a dock widget, so this method returns None.

Parameters:

parent_window – The parent window to attach the dock to.

Returns:

None, as this tool does not use a dock.

create_session(window_controller: ImageWindowController, flip_mode: str = 'horizontal', output_mode: str = 'new_image') FlipImageToolSession[source]

Create a new flip session for the given window controller.

Parameters:
  • window_controller (SubWindowController) – The window controller to create a session for.

  • flip_mode (str) – Flip mode to apply.

  • output_mode (str) – Output mode to use.

Returns:

A new FlipImageToolSession instance.

Return type:

FlipImageToolSession

inplace_dependency_summary(image_controller: ImageWindowController) str[source]

Generate a summary of items that depend on the given image.

Parameters:

image_controller (ImageWindowController) – The image controller to get dependencies for.

Returns:

A formatted string summarizing the dependent items.

Return type:

str

menu_specs() List[ToolMenuSpec][source]

Get the menu specifications for this tool.

Returns:

List of menu specifications defining the tool’s menu entries.

Return type:

List[ToolMenuSpec]

class radioviz.tools.flip_image_tool.FlipImageToolSession(tool_controller: FlipImageToolController, window_controller: ImageWindowController, flip_mode: str, output_mode: str)[source]

Bases: BaseToolSession[FlipImageToolController, ImageWindowController]

Session handling a single flip operation.

Variables:

dialog_window (Optional[object]) – Optional dialog window (unused for this tool).

Initialize a new flip tool session.

Parameters:
  • tool_controller (FlipImageToolController) – The tool controller that owns this session.

  • window_controller (SubWindowController) – The image window controller to operate on.

  • flip_mode (str) – Flip mode to apply.

  • output_mode (str) – Output mode, either 'new_image' or 'in_place'.

Raises:

TypeError – If window_controller is not an ImageWindowController.

_on_error(error: Exception) None[source]

Handle errors from the flip worker.

Parameters:

error (Exception) – The exception that was raised by the worker.

_on_result_ready(result: FlipImageResult) None[source]

Handle successful completion of the flip worker.

Parameters:

result (FlipImageResult) – The flip result containing the flipped image.

on_cancel(reason: str) None[source]

Cancel the flip session.

Parameters:

reason (str) – The reason for cancellation.

on_finish() None[source]

Finish the flip session successfully.

on_start() None[source]

Start the flip session.

Creates the flip request, checks in-place dependencies if needed, and starts the background worker.

radioviz.tools.flip_image_tool.flip_image_worker(request: FlipImageRequest) FlipImageResult[source]

Flip an image in a background thread.

Parameters:

request (FlipImageRequest) – Parameters required to compute an image flip.

Returns:

Result containing the flipped image and flip mode.

Return type:

FlipImageResult

Raises:

ValueError – If an unknown flip mode is requested.