Callbacks#
callbacks.py#
Lightweight two-class event system used by every plot object and widget.
CallbackRegistryPer-object store of named callbacks. Every plot object and widget exposes
on_changed,on_release,on_click,on_key,on_line_hover, andon_line_clickdecorator methods that connect handlers through this registry.EventImmutable data-carrier passed to every callback. All keys in the raw JS payload are accessible as attributes (
event.zoom,event.cx, etc.) in addition to the typedevent_type,source, anddatafields.
Example
fig, ax = apl.subplots(1, 1)
plot = ax.imshow(data)
@plot.on_release
def on_settle(event):
print(f"zoom={event.zoom:.2f} center=({event.center_x:.3f}, {event.center_y:.3f})")
Classes
Per-object registry for on_click / on_changed / on_release / on_key / on_line_hover / on_line_click callbacks. |
|
A single interactive event. |
Full Reference
- class anyplotlib.callbacks.CallbackRegistry[source]
Bases:
objectPer-object registry for on_click / on_changed / on_release / on_key / on_line_hover / on_line_click callbacks.
- connect(event_type, fn)[source]
Register fn for event_type. Returns integer CID.
- disconnect(cid)[source]
Remove handler for cid. Silent if not found.
- Parameters:
cid (int)
- Return type:
None
- fire(event)[source]
Dispatch event to all handlers matching event.event_type.
- Return type:
None
- class anyplotlib.callbacks.Event(event_type, source, data=<factory>)[source]
Bases:
objectA single interactive event.
- Event_type:
one of
on_click/on_changed/on_release/on_key/on_line_hover/on_line_click- Source:
the originating Python object (Widget, Plot, or None)
- Data:
full state dict; all keys also accessible as
event.x- Parameters:
For
on_line_hoverandon_line_clickevents the data dict contains:line_id–Nonefor the primary line, or the 8-char ID string assigned byPlot1D.add_line().x– data-space x coordinate of the nearest point on the line.y– data-space y coordinate of the nearest point on the line.
- event_type: str
- source: Any
- data: dict