notebook/IPython/html/widgets/widget_bool.py

72 lines
2.5 KiB
Python
Raw Normal View History

"""Bool class.
2013-10-26 02:31:48 +08:00
Represents a boolean using a widget.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
2014-09-18 05:04:03 +08:00
from .widget import DOMWidget, register
2014-08-27 08:26:05 +08:00
from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum
from IPython.utils.warn import DeprecatedClass
2013-10-19 02:08:47 +08:00
2013-10-26 02:31:48 +08:00
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
class _Bool(DOMWidget):
"""A base class for creating widgets that represent booleans."""
2014-01-14 23:15:19 +08:00
value = Bool(False, help="Bool value", sync=True)
description = Unicode('', help="Description of the boolean (label).", sync=True)
2014-01-14 23:15:19 +08:00
disabled = Bool(False, help="Enable or disable user changes.", sync=True)
2014-01-15 00:24:35 +08:00
def __init__(self, value=None, **kwargs):
if value is not None:
kwargs['value'] = value
super(_Bool, self).__init__(**kwargs)
2014-01-16 22:20:04 +08:00
2014-10-14 09:45:16 +08:00
@register('IPython.Checkbox')
class Checkbox(_Bool):
"""Displays a boolean `value` in the form of a checkbox.
Parameters
----------
value : {True,False}
value of the checkbox: True-checked, False-unchecked
description : str
description displayed next to the checkbox
"""
_view_name = Unicode('CheckboxView', sync=True)
2014-01-22 08:44:57 +08:00
2014-10-14 09:45:16 +08:00
@register('IPython.ToggleButton')
class ToggleButton(_Bool):
"""Displays a boolean `value` in the form of a toggle button.
Parameters
----------
value : {True,False}
value of the toggle button: True-pressed, False-unpressed
description : str
description displayed next to the button
"""
2014-04-20 08:06:41 +08:00
_view_name = Unicode('ToggleButtonView', sync=True)
2014-11-14 03:04:06 +08:00
tooltip = Unicode(help="Tooltip caption of the toggle button.", sync=True)
button_style = CaselessStrEnum(
values=['primary', 'success', 'info', 'warning', 'danger', ''],
default_value='', allow_none=True, sync=True, help="""Use a
predefined styling for the button.""")
# Remove in IPython 4.0
2014-08-21 00:34:05 +08:00
CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget')
ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget')