anyplotlib.Widget#
- class anyplotlib.Widget(wtype, push_fn, **kwargs)[source]#
Bases:
objectBase class for all overlay widgets.
Provides attribute-based state access, callbacks for interaction events, and automatic synchronization with the JavaScript renderer.
- Parameters:
- callbacks#
Event callback registry. Register handlers via: -
@widget.on_changed— fires on every drag frame -@widget.on_release— fires once when drag settles -@widget.on_click— fires on click event- Type:
- set(_push=True, **kwargs)[source]#
Update properties and send targeted update to JavaScript.
- Parameters:
- Return type:
None
Notes
Updates are sent as targeted widget updates, not full panel re-renders. This is more efficient for frequent updates during dragging.
- to_dict()[source]#
Return a dict copy of the widget state.
- Returns:
All widget properties including id and type.
- Return type:
- on_changed(fn)[source]#
Decorator: register fn to fire on every drag frame.
Use this for high-frequency updates (keep handler fast).
- Parameters:
fn (Callable) – Handler function receiving an Event.
- Returns:
The decorated function.
- Return type:
Callable
- on_release(fn)[source]#
Decorator: register fn to fire once when drag settles.
Use this for expensive operations triggered after user stops dragging.
- Parameters:
fn (Callable) – Handler function receiving an Event.
- Returns:
The decorated function.
- Return type:
Callable
- on_click(fn)[source]#
Decorator: register fn to fire on widget click.
- Parameters:
fn (Callable) – Handler function receiving an Event.
- Returns:
The decorated function.
- Return type:
Callable
- disconnect(cid)[source]#
Remove the callback registered under cid.
- Parameters:
cid (int or Callable) – Either the integer CID returned by
callbacks.connect(), or the decorated function itself (carries a._cidattribute).- Return type:
None