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, key=None, last_widget_id=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

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

Propagation:

stop_propagation — set True inside a handler to halt remaining handlers

Parameters:
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
key: str | None = None
last_widget_id: str | None = None
stop_propagation: bool = False