diff --git a/frame.py b/frame.py index 7e0ffba..d7dbd26 100644 --- a/frame.py +++ b/frame.py @@ -3,6 +3,7 @@ from bokeh.models import Button, Div, Spacer CROSS = "🗙" +GEAR = "⚙" class Frame: @@ -14,17 +15,47 @@ class Frame: name = plt.name inner_fig = plt.fig + n_btns = 2 btn_width = 35 - lbl_width = inner_fig.width - btn_width + lbl_width = inner_fig.width - n_btns * btn_width + + self.btn_close = btn_close = Button(label=CROSS, button_type="default", width=btn_width) + self.btn_cfg = btn_cfg = Button(label=GEAR, button_type="default", width=btn_width) - self.btn = btn = Button(label=CROSS, button_type="light", width=btn_width) lbl = Div(text=name, align="center", style={"font-size": "150%"}, width=lbl_width) + header = row(btn_close, btn_cfg, lbl) - self.fig = column(row(btn, lbl), inner_fig, Spacer(height=35)) + self.cfg_dialog = cfg_dialog = column() + cfg_dialog.visible = False + + #TODO: the following is just a dummy + types = ("light", "default", "primary", "success", "warning", "danger") + for t in types: + btn = Button(label=t, button_type=t, height=35) #TODO: why does this need height to be set? (otherwise buttons are only properly sized on NEXT click!) + cfg_dialog.children.append(btn) + + self.btn_cfg.on_click(self.do_click_cfg) + + # wrap fig and cfg such that their container can be hidden during the visibility switch + # wrap with another container to maintain size + # combined gives a relatively smooth (albeit slow) transition between the two states + self.inner = inner = row(inner_fig, cfg_dialog) + size_maintainer = row(inner, min_width=inner_fig.width, min_height=inner_fig.height) #TODO: why min_* ? + + self.fig = column(header, size_maintainer, Spacer(height=35)) def on_click_close(self, *args, **kwargs): - self.btn.on_click(*args, **kwargs) + self.btn_close.on_click(*args, **kwargs) + + def do_click_cfg(self): + self.inner.visible = False + switch_visibility(self.plt.fig, self.cfg_dialog) + self.inner.visible = True + + +def switch_visibility(a, b): + a.visible, b.visible = b.visible, a.visible