From 03673f28681ce2fcd61083f705532ae11136eae6 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Wed, 9 Jun 2021 11:19:24 +0200 Subject: [PATCH] added single checkbox widget that can substitute for Toggle --- kabuki/widgets.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 kabuki/widgets.py 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) + + +