Callbacks#

callbacks.py#

Event system used by all plot objects and widgets.

Event

Flat dataclass carrying all event fields as typed top-level attributes.

CallbackRegistry

Per-object handler store. (Full implementation added in Tasks 2-3.)

_EventMixin

Mixin added to every plot class and widget. (Added in Task 4.)

Classes

CallbackRegistry

Per-object handler store.

Event

A single interactive event with all payload fields as typed attributes.

Full Reference

class anyplotlib.callbacks.CallbackRegistry[source]

Bases: object

Per-object handler store.

Supports: - Priority ordering (order kwarg — lower fires first) - Wildcard "*" type receives every dispatched event - stop_propagation on the event halts remaining handlers - disconnect_fn(fn, *types) removes by callback reference - pause_events / hold_events context managers (added in Task 3)

connect(event_type, fn, *, order=0)[source]

Register fn for event_type. Returns integer CID.

Parameters:
Return type:

int

disconnect(cid)[source]

Remove handler by CID. Silent if not found.

Parameters:

cid (int)

Return type:

None

disconnect_fn(fn, *types)[source]

Remove fn from the given types (all types if none given).

Parameters:
Return type:

None

fire(event)[source]

Dispatch event to matching handlers (respects pause/hold).

Parameters:

event (Event)

Return type:

None

pause_events(*types)[source]

Suppress events of the given types while inside this context. All types are paused when called with no arguments. Pause wins over hold for the same type.

Parameters:

types (str)

hold_events(*types)[source]

Buffer events of the given types; flush when the outermost hold exits. All types are held when called with no arguments.

Parameters:

types (str)

class anyplotlib.callbacks.Event(event_type, source=None, time_stamp=<factory>, modifiers=<factory>, x=None, y=None, button=None, buttons=0, xdata=None, ydata=None, ray=None, line_id=None, dwell_ms=None, bar_index=None, value=None, x_label=None, group_index=None, dx=None, dy=None, zoom=None, center_x=None, center_y=None, image_width=None, image_height=None, display_width=None, display_height=None, azimuth=None, elevation=None, key=None, last_widget_id=None, source_panel_id=None, target_panel_id=None, inset_id=None, anchor=None, w_frac=None, h_frac=None, target=None, stop_propagation=False)[source]

Bases: object

A single interactive event with all payload fields as typed attributes.

Universal fields (every event):

event_type, source, time_stamp, modifiers

Pointer fields (pointer_* and double_click events):

x, y — canvas coordinates within the panel (float pixels) button — 0=left 1=middle 2=right; None on move/enter/leave/settled buttons — bitmask of currently held buttons xdata, ydata — data-space coordinates (None for Plot3D) ray — Plot3D only: {“origin”: […], “direction”: […]} line_id — Plot1D only: set when pointer is over a line dwell_ms — pointer_settled only: actual dwell time target — double_click only: hit chrome element, or None for plot-area (title/x_label/x_ticks/y_label/y_ticks/colorbar_label/legend)

PlotBar extra fields (pointer_down only):

bar_index, value, x_label, group_index

Wheel fields:

dx, dy — scroll deltas

Key fields:

key — key name e.g. “q”, “Enter”, “ArrowLeft” last_widget_id — id of the last widget the user clicked, or None

Panel-swap fields (figure-level panel_swap events):

source_panel_id, target_panel_id — the two panel ids dragged between

Inset drag/resize fields (figure-level inset_geometry_change events):

inset_id — the inset panel id anchor — new top-left position [fx, fy] in figure fractions w_frac, h_frac — new size in figure fractions

Propagation:

stop_propagation — set True inside a handler to halt remaining handlers

Parameters:
  • event_type (str)

  • source (Any)

  • time_stamp (float)

  • modifiers (list[str])

  • x (float | None)

  • y (float | None)

  • button (int | None)

  • buttons (int)

  • xdata (float | None)

  • ydata (float | None)

  • ray (dict | None)

  • line_id (str | None)

  • dwell_ms (float | None)

  • bar_index (int | None)

  • value (float | None)

  • x_label (str | None)

  • group_index (int | None)

  • dx (float | None)

  • dy (float | None)

  • zoom (float | None)

  • center_x (float | None)

  • center_y (float | None)

  • image_width (int | None)

  • image_height (int | None)

  • display_width (int | None)

  • display_height (int | None)

  • azimuth (float | None)

  • elevation (float | None)

  • key (str | None)

  • last_widget_id (str | None)

  • source_panel_id (str | None)

  • target_panel_id (str | None)

  • inset_id (str | None)

  • anchor (list | None)

  • w_frac (float | None)

  • h_frac (float | None)

  • target (str | None)

  • stop_propagation (bool)

event_type: str
source: Any = None
time_stamp: float
modifiers: list[str]
x: float | None = None
y: float | None = None
button: int | None = None
buttons: int = 0
xdata: float | None = None
ydata: float | None = None
ray: dict | None = None
line_id: str | None = None
dwell_ms: float | None = None
bar_index: int | None = None
value: float | None = None
x_label: str | None = None
group_index: int | None = None
dx: float | None = None
dy: float | None = None
zoom: float | None = None
center_x: float | None = None
center_y: float | None = None
image_width: int | None = None
image_height: int | None = None
display_width: int | None = None
display_height: int | None = None
azimuth: float | None = None
elevation: float | None = None
key: str | None = None
last_widget_id: str | None = None
source_panel_id: str | None = None
target_panel_id: str | None = None
inset_id: str | None = None
anchor: list | None = None
w_frac: float | None = None
h_frac: float | None = None
target: str | None = None
stop_propagation: bool = False