Widgets#

widgets.py — Interactive overlay widget classes.

Each widget has a .callbacks (CallbackRegistry). Register handlers via:

@rect.on_changed        # every drag frame
def live(event): ...

@rect.on_release        # once on mouseup
def done(event): ...

@rect.on_click
def clicked(event): ...

rect.x = 40             # moves widget, sends targeted update to JS
rect.x                  # always reflects current JS position
class anyplotlib.widgets.Widget(wtype, push_fn, **kwargs)[source]#

Bases: object

Base class for all overlay widgets.

Parameters:
  • wtype (str)

  • push_fn (Callable)

set(_push=True, **kwargs)[source]#

Update properties. Sends a targeted event_json update to JS (not a full panel push). Fires on_changed callbacks.

Use _push=False internally (e.g. _update_from_js) to avoid echo.

Parameters:

_push (bool)

Return type:

None

get(key, default=None)[source]#
Parameters:

key (str)

to_dict()[source]#
Return type:

dict

on_changed(fn)[source]#

Decorator: register fn to fire on every drag frame.

Parameters:

fn (Callable)

Return type:

Callable

on_release(fn)[source]#

Decorator: register fn to fire once when drag settles.

Parameters:

fn (Callable)

Return type:

Callable

on_click(fn)[source]#

Decorator: register fn to fire on click.

Parameters:

fn (Callable)

Return type:

Callable

disconnect(cid)[source]#

Remove the callback registered under cid.

Accepts either the integer CID returned by callbacks.connect(), or the decorated function itself (which carries a ._cid attribute).

Return type:

None

property id: str#
class anyplotlib.widgets.RectangleWidget(push_fn, *, x, y, w, h, color='#00e5ff')[source]#

Bases: Widget

class anyplotlib.widgets.CircleWidget(push_fn, *, cx, cy, r, color='#00e5ff')[source]#

Bases: Widget

class anyplotlib.widgets.AnnularWidget(push_fn, *, cx, cy, r_outer, r_inner, color='#00e5ff')[source]#

Bases: Widget

class anyplotlib.widgets.CrosshairWidget(push_fn, *, cx, cy, color='#00e5ff')[source]#

Bases: Widget

class anyplotlib.widgets.PolygonWidget(push_fn, *, vertices, color='#00e5ff')[source]#

Bases: Widget

class anyplotlib.widgets.LabelWidget(push_fn, *, x, y, text='Label', fontsize=14, color='#00e5ff')[source]#

Bases: Widget

class anyplotlib.widgets.VLineWidget(push_fn, *, x, color='#00e5ff')[source]#

Bases: Widget

class anyplotlib.widgets.HLineWidget(push_fn, *, y, color='#00e5ff')[source]#

Bases: Widget

class anyplotlib.widgets.RangeWidget(push_fn, *, x0, x1, color='#00e5ff')[source]#

Bases: Widget