Source code for bokeh.models.widgets.buttons
''' Various kinds of button widgets.
'''
from __future__ import absolute_import
from ...core.enums import ButtonType
from ...core.has_props import abstract, HasProps
from ...core.properties import Bool, Enum, Instance, Int, List, Override, String, Tuple
from ..callbacks import Callback
from .icons import AbstractIcon
from .widget import Widget
[docs]class Toggle(AbstractButton):
''' A two-state toggle button.
'''
label = Override(default="Toggle")
active = Bool(False, help="""
The initial state of a button. Also used to trigger ``on_click`` event
handler.
""")
[docs] def on_click(self, handler):
""" Set up a handler for button state changes (clicks).
Args:
handler (func) : handler function to call when button is toggled.
Returns:
None
"""
self.on_change('active', lambda attr, old, new: handler(new))
[docs] def js_on_click(self, handler):
""" Set up a JavaScript handler for button state changes (clicks). """
self.js_on_change('active', handler)
[docs]class Dropdown(AbstractButton):
''' A dropdown button.
'''
label = Override(default="Dropdown")
value = String(help="""
A private property used to trigger ``on_click`` event handler.
""")
default_value = String(help="""
The default value, otherwise the first item in ``menu`` will be used.
""")
menu = List(Tuple(String, String), help="""
Button's dropdown menu consisting of entries containing item's text and
value name. Use ``None`` as a menu separator.
""")
[docs] def on_click(self, handler):
''' Set up a handler for button or menu item clicks.
Args:
handler (func) : handler function to call when button is activated.
Returns:
None
'''
self.on_change('value', lambda attr, old, new: handler(new))
[docs] def js_on_click(self, handler):
''' Set up a JavaScript handler for button or menu item clicks. '''
self.js_on_change('value', handler)