#-----------------------------------------------------------------------------# Copyright (c) 2012 - 2022, Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------''''''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsfromtypingimportTYPE_CHECKING,Callable,ListasTList# Bokeh importsfrom...core.has_propsimportabstractfrom...core.propertiesimport(Bool,Enum,Int,List,Nullable,String,)from.buttonsimportButtonLikefrom.widgetimportWidgetifTYPE_CHECKING:from..callbacksimportCallback#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('AbstractGroup','ButtonGroup','CheckboxButtonGroup','CheckboxGroup','Group','RadioButtonGroup','RadioGroup',)#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------
[docs]@abstractclassAbstractGroup(Widget):''' Abstract base class for all kinds of groups. '''labels=List(String,help=""" List of text labels contained in this group. """)
[docs]defon_click(self,handler:Callable[[int],None]|Callable[[TList[int]],None])->None:''' Set up a handler for button check/radio box clicks including the selected indices. Args: handler (func) : handler function to call when button is clicked. Returns: None '''self.on_change('active',lambdaattr,old,new:handler(new))
[docs]defjs_on_click(self,handler:Callback)->None:''' Set up a handler for button check/radio box clicks including the selected indices. '''self.js_on_change('active',handler)
[docs]@abstractclassButtonGroup(AbstractGroup,ButtonLike):''' Abstract base class for groups with items rendered as buttons. '''orientation=Enum("horizontal","vertical",help=""" Orient the button group either horizontally (default) or vertically. """)
[docs]@abstractclassGroup(AbstractGroup):''' Abstract base class for groups with items rendered as check/radio boxes. '''inline=Bool(False,help=""" Should items be arrange vertically (``False``) or horizontally in-line (``True``). """)
#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]classCheckboxGroup(Group):''' A group of check boxes. '''active=List(Int,help=""" The list of indices of selected check boxes. """)
[docs]classRadioGroup(Group):''' A group of radio boxes. '''active=Nullable(Int,help=""" The index of the selected radio box, or ``None`` if nothing is selected. """)
[docs]classCheckboxButtonGroup(ButtonGroup):''' A group of check boxes rendered as toggle buttons. '''active=List(Int,help=""" The list of indices of selected check boxes. """)
[docs]classRadioButtonGroup(ButtonGroup):''' A group of radio boxes rendered as toggle buttons. '''active=Nullable(Int,help=""" The index of the selected radio box, or ``None`` if nothing is selected. """)