diff --git a/kabuki/widgets.py b/kabuki/widgets.py new file mode 100644 index 0000000..24e5beb --- /dev/null +++ b/kabuki/widgets.py @@ -0,0 +1,28 @@ +from bokeh.models import CheckboxGroup +from .buki import Object +from .utils import adjust_margin + + +class Checkbox(Object): + + def __init__(self, *args, label=None, **kwargs): + labels = [label] if label is not None else None + cg = CheckboxGroup(*args, labels=labels, **kwargs) + adjust_margin(cg, left=5) + super().__init__(cg) + + @property + def active(self): + return bool(self.layout.active) + + @active.setter + def active(self, value): + self.layout.active = [0] if value else [] + + def on_click(self, handler): + def wrapper(state): + handler(bool(state)) + self.layout.on_click(wrapper) + + +