Skip to content

Instantly share code, notes, and snippets.

@schaunwheeler
Last active August 29, 2015 14:20
Show Gist options
  • Save schaunwheeler/0a0b7f79018ed65d56aa to your computer and use it in GitHub Desktop.
Save schaunwheeler/0a0b7f79018ed65d56aa to your computer and use it in GitHub Desktop.
from bokeh.properties import Instance, List, Bool
from bokeh.models.widgets.buttons import Button
from bokeh.models.widgets.markups import Paragraph
from bokeh.models.widgets.layouts import VBox, HBox, VBoxForm
from bokeh.server.app import bokeh_app
from bokeh.server.utils.plugins import object_page
from bokeh.plotting import curdoc
class MenuChange(VBox):
extra_generated_classes = [["MenuChange", "MenuChange", "VBox"]]
jsmodel = "VBox"
# layout boxes
mainrow_children_on = List(Instance(Button))
mainrow_children_off = List(Instance(Button))
otherrow_children_on = List(Instance(VBox))
otherrow_children_off = List(Instance(VBox))
mainrow = Instance(HBox)
otherrow = Instance(VBox)
input_box = Instance(VBoxForm)
paragraph = Instance(Paragraph)
menu_open = Bool(default=False)
# inputs
menu_submit = Instance(Button)
menu_toggle = Instance(Button)
menu_reset = Instance(Button)
def __init__(self, *args, **kwargs):
super(MenuChange, self).__init__(*args, **kwargs)
@classmethod
def create(cls):
obj = cls()
obj.input_box = VBoxForm()
obj.mainrow = HBox()
obj.otherrow = VBox()
obj.make_inputs()
obj.set_children()
return obj
def make_inputs(self):
self.menu_submit = Button(label='Submit', type='warning')
self.menu_toggle = Button(label='Select plot criteria', type='primary')
self.menu_reset = Button(label='Reset')
self.paragraph = Paragraph()
self.mainrow_children_on = [self.menu_submit, self.menu_toggle, self.menu_reset]
self.mainrow_children_off = [self.menu_toggle]
self.otherrow_children_off = [VBox(children=[self.paragraph])]
self.otherrow_children_on = [VBox(children=[self.paragraph])]
self.input_box.children = [self.mainrow, self.otherrow]
def set_children(self):
self.children = [self.input_box]
self.input_box.children = [self.mainrow, self.otherrow]
if self.menu_open:
self.menu_toggle.label = 'Cancel'
self.menu_toggle.type = 'default'
self.paragraph.text = 'Menu toggled on'
self.mainrow.children = self.mainrow_children_on
self.otherrow.children = self.otherrow_children_on
else:
self.menu_toggle.label = 'Select plot criteria'
self.menu_toggle.type = 'primary'
self.paragraph.text = 'Menu toggled off'
self.mainrow.children = self.mainrow_children_off
self.otherrow.children = self.otherrow_children_off
curdoc().add(self)
def toggle_menu(self):
self.menu_open = not self.menu_open
self.set_children()
def submit_menu(self):
self.toggle_menu()
def reset_menu(self):
self.__init__()
def setup_events(self):
super(MenuChange, self).setup_events()
if self.menu_submit:
self.menu_submit.on_click(self.submit_menu)
if self.menu_toggle:
self.menu_toggle.on_click(self.toggle_menu)
if self.menu_reset:
self.menu_reset.on_click(self.reset_menu)
@bokeh_app.route("/bokeh/menu_change/")
@object_page("menu_change")
def make_menu():
app = MenuChange.create()
return app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment