2014-07-19 03:47:33 +08:00
|
|
|
"""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
|
2014-07-19 03:47:33 +08:00
|
|
|
from IPython.utils.warn import DeprecatedClass
|
2013-10-19 02:08:47 +08:00
|
|
|
|
2013-10-26 02:31:48 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Classes
|
|
|
|
#-----------------------------------------------------------------------------
|
2014-07-19 03:47:33 +08:00
|
|
|
class _Bool(DOMWidget):
|
2014-07-22 02:37:42 +08:00
|
|
|
"""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)
|
2014-07-22 02:37:42 +08:00
|
|
|
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
|
|
|
|
2014-09-28 04:07:42 +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')
|
2014-07-19 03:47:33 +08:00
|
|
|
class Checkbox(_Bool):
|
2014-12-01 02:27:47 +08:00
|
|
|
"""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
|
|
|
|
"""
|
2014-01-29 04:51:24 +08:00
|
|
|
_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')
|
2014-07-19 03:47:33 +08:00
|
|
|
class ToggleButton(_Bool):
|
2014-12-01 02:27:47 +08:00
|
|
|
"""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
|
|
|
|
2014-07-22 02:37:42 +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)
|
2014-07-22 02:37:42 +08:00
|
|
|
|
2014-08-27 07:49:13 +08:00
|
|
|
button_style = CaselessStrEnum(
|
|
|
|
values=['primary', 'success', 'info', 'warning', 'danger', ''],
|
|
|
|
default_value='', allow_none=True, sync=True, help="""Use a
|
|
|
|
predefined styling for the button.""")
|
|
|
|
|
2014-07-22 02:37:42 +08:00
|
|
|
|
|
|
|
# Remove in IPython 4.0
|
2014-08-21 00:34:05 +08:00
|
|
|
CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget')
|
2014-07-19 03:47:33 +08:00
|
|
|
ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget')
|