added single checkbox widget that can substitute for Toggle

This commit is contained in:
2021-06-09 11:19:24 +02:00
parent 3dfce8f5e5
commit 03673f2868
+28
View File
@@ -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)