radioviz.services.mpl_helpers
Helper utilities for bridging Matplotlib and Qt interactions.
This module provides utilities to manage Matplotlib navigation modes and handle context menu events between Qt widgets and Matplotlib canvases.
Classes
|
Helper to bridge Qt context menu events with Matplotlib interaction state. |
|
Temporarily suspends Matplotlib navigation mode to allow Qt interactions. |
- class radioviz.services.mpl_helpers.MplContextMenuBridge(canvas: Any)[source]
Bases:
objectHelper to bridge Qt context menu events with Matplotlib interaction state.
This class handles the conversion of Qt context menu events to Matplotlib coordinates and ensures proper interaction state management when context menus are triggered over Matplotlib canvases.
Initialize the MplContextMenuBridge.
- Parameters:
canvas (matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg) – The Matplotlib canvas to bridge events for
- _cancel_mpl_interaction(canvas_pos_qt: QPoint) None[source]
Cancel ongoing Matplotlib interaction at the given position.
Injects a synthetic mouse release event to cancel any active pan/zoom operations in Matplotlib.
- Parameters:
canvas_pos_qt (QPoint) – Position in canvas coordinates
- handle_context_request(source_widget: Any, pos: QPoint) QPoint[source]
Handle a context menu request from a Qt widget.
Converts Qt widget coordinates to global coordinates and then to Matplotlib canvas coordinates. Cancels any ongoing Matplotlib interaction if the click is within the canvas area.
- Parameters:
source_widget (QWidget) – The Qt widget that triggered the context menu
pos (QPoint) – The position of the context menu trigger in widget coordinates
- Returns:
The global position of the context menu
- Return type:
QPoint
Bases:
objectTemporarily suspends Matplotlib navigation mode to allow Qt interactions.
This class is used to temporarily disable Matplotlib’s navigation mode when Qt-specific operations need to take precedence, such as handling context menus or custom interactions.
Initialize the NavigationModeSuspender.
- Parameters:
toolbar (matplotlib.backends.backend_qt5agg.NavigationToolbar2QT) – The Matplotlib toolbar to suspend mode for
Restore the previously saved navigation mode.
Restores the navigation mode that was active before suspension.
Suspend the current navigation mode.
Saves the current mode and sets it to NONE to prevent Matplotlib from intercepting mouse events during Qt operations.