Callbacks#
callbacks.py#
Event system used by all plot objects and widgets.
EventFlat dataclass carrying all event fields as typed top-level attributes.
CallbackRegistryPer-object handler store. (Full implementation added in Tasks 2-3.)
_EventMixinMixin added to every plot class and widget. (Added in Task 4.)
Classes
Per-object handler store. |
|
A single interactive event with all payload fields as typed attributes. |
Full Reference
- class anyplotlib.callbacks.CallbackRegistry[source]
Bases:
objectPer-object handler store.
Supports: - Priority ordering (
orderkwarg — lower fires first) - Wildcard"*"type receives every dispatched event -stop_propagationon the event halts remaining handlers -disconnect_fn(fn, *types)removes by callback reference -pause_events/hold_eventscontext managers (added in Task 3)- connect(event_type, fn, *, order=0)[source]
Register fn for event_type. Returns integer CID.
- 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).
- fire(event)[source]
Dispatch event to matching handlers (respects pause/hold).
- Parameters:
event (Event)
- Return type:
None
- 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:
objectA 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)
time_stamp (float)
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)
key (str | None)
last_widget_id (str | None)
stop_propagation (bool)
- event_type: str
- source: Any = None
- time_stamp: float
- buttons: int = 0
- stop_propagation: bool = False