registering core widgets

Sylvain Corlay 12 years ago committed by Sylvain Corlay
parent e5b347804a
commit 18e77a090a

@ -1,4 +1,4 @@
from .widget import Widget, DOMWidget, CallbackDispatcher
from .widget import Widget, DOMWidget, CallbackDispatcher, register
from .widget_bool import Checkbox, ToggleButton
from .widget_button import Button

@ -78,7 +78,7 @@ def _show_traceback(method):
def register(key=None):
def wrap(widget):
l = key if key is not None else widget._model_name.default_value
l = key if key is not None else widget._view_name.default_value
Widget.widget_types[l] = widget
return widget
return wrap

@ -13,13 +13,14 @@ Represents a boolean using a widget.
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from .widget import DOMWidget
from .widget import DOMWidget, register
from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum
from IPython.utils.warn import DeprecatedClass
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
@register()
class _Bool(DOMWidget):
"""A base class for creating widgets that represent booleans."""
value = Bool(False, help="Bool value", sync=True)
@ -27,11 +28,13 @@ class _Bool(DOMWidget):
disabled = Bool(False, help="Enable or disable user changes.", sync=True)
@register()
class Checkbox(_Bool):
"""Displays a boolean `value`."""
_view_name = Unicode('CheckboxView', sync=True)
@register()
class ToggleButton(_Bool):
"""Displays a boolean `value`."""

@ -6,10 +6,11 @@ Represents a container that can be used to group other widgets.
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
from .widget import DOMWidget
from .widget import DOMWidget, register
from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum
from IPython.utils.warn import DeprecatedClass
@register()
class Box(DOMWidget):
"""Displays multiple widgets in a group."""
_view_name = Unicode('BoxView', sync=True)
@ -44,6 +45,7 @@ class Box(DOMWidget):
child._handle_displayed()
@register()
class Popup(Box):
"""Displays multiple widgets in an in page popup div."""
_view_name = Unicode('PopupView', sync=True)
@ -52,6 +54,7 @@ class Popup(Box):
button_text = Unicode(sync=True)
@register()
class FlexBox(Box):
"""Displays multiple widgets using the flexible box model."""
_view_name = Unicode('FlexBoxView', sync=True)

@ -14,13 +14,14 @@ click events on the button and trigger backend code when the clicks are fired.
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from .widget import DOMWidget, CallbackDispatcher
from .widget import DOMWidget, CallbackDispatcher, register
from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum
from IPython.utils.warn import DeprecatedClass
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
@register()
class Button(DOMWidget):
"""Button widget.

@ -13,7 +13,7 @@ Represents an unbounded float using a widget.
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from .widget import DOMWidget
from .widget import DOMWidget, register
from IPython.utils.traitlets import Unicode, CFloat, Bool, CaselessStrEnum, Tuple
from IPython.utils.warn import DeprecatedClass
@ -43,14 +43,17 @@ class _BoundedFloat(_Float):
self.value = min(max(new, self.min), self.max)
@register()
class FloatText(_Float):
_view_name = Unicode('FloatTextView', sync=True)
@register()
class BoundedFloatText(_BoundedFloat):
_view_name = Unicode('FloatTextView', sync=True)
@register()
class FloatSlider(_BoundedFloat):
_view_name = Unicode('FloatSliderView', sync=True)
orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
@ -61,6 +64,7 @@ class FloatSlider(_BoundedFloat):
slider_color = Unicode(sync=True)
@register()
class FloatProgress(_BoundedFloat):
_view_name = Unicode('ProgressView', sync=True)
@ -163,6 +167,7 @@ class _BoundedFloatRange(_FloatRange):
self.lower = low
@register()
class FloatRangeSlider(_BoundedFloatRange):
_view_name = Unicode('FloatSliderView', sync=True)
orientation = CaselessStrEnum(values=['horizontal', 'vertical'],

@ -15,13 +15,14 @@ Represents an image in the frontend using a widget.
#-----------------------------------------------------------------------------
import base64
from .widget import DOMWidget
from .widget import DOMWidget, register
from IPython.utils.traitlets import Unicode, CUnicode, Bytes
from IPython.utils.warn import DeprecatedClass
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
@register()
class Image(DOMWidget):
"""Displays an image as a widget.

@ -13,7 +13,7 @@ Represents an unbounded int using a widget.
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from .widget import DOMWidget
from .widget import DOMWidget, register
from IPython.utils.traitlets import Unicode, CInt, Bool, CaselessStrEnum, Tuple
from IPython.utils.warn import DeprecatedClass
@ -56,16 +56,19 @@ class _BoundedInt(_Int):
if new > self.max:
raise ValueError("setting min > max")
@register()
class IntText(_Int):
"""Textbox widget that represents a int."""
_view_name = Unicode('IntTextView', sync=True)
@register()
class BoundedIntText(_BoundedInt):
"""Textbox widget that represents a int bounded by a minimum and maximum value."""
_view_name = Unicode('IntTextView', sync=True)
@register()
class IntSlider(_BoundedInt):
"""Slider widget that represents a int bounded by a minimum and maximum value."""
_view_name = Unicode('IntSliderView', sync=True)
@ -77,6 +80,7 @@ class IntSlider(_BoundedInt):
slider_color = Unicode(sync=True)
@register()
class IntProgress(_BoundedInt):
"""Progress bar that represents a int bounded by a minimum and maximum value."""
_view_name = Unicode('ProgressView', sync=True)
@ -176,6 +180,7 @@ class _BoundedIntRange(_IntRange):
self.upper = high
self.lower = low
@register()
class IntRangeSlider(_BoundedIntRange):
_view_name = Unicode('IntSliderView', sync=True)
orientation = CaselessStrEnum(values=['horizontal', 'vertical'],

@ -17,7 +17,7 @@ Represents an enumeration using a widget.
from collections import OrderedDict
from threading import Lock
from .widget import DOMWidget
from .widget import DOMWidget, register
from IPython.utils.traitlets import Unicode, List, Bool, Any, Dict, TraitError, CaselessStrEnum
from IPython.utils.py3compat import unicode_type
from IPython.utils.warn import DeprecatedClass
@ -114,6 +114,7 @@ class _Selection(DOMWidget):
self.value_lock.release()
@register()
class ToggleButtons(_Selection):
"""Group of toggle buttons that represent an enumeration. Only one toggle
button can be toggled at any point in time."""
@ -124,7 +125,7 @@ class ToggleButtons(_Selection):
default_value='', allow_none=True, sync=True, help="""Use a
predefined styling for the buttons.""")
@register()
class Dropdown(_Selection):
"""Allows you to select a single item from a dropdown."""
_view_name = Unicode('DropdownView', sync=True)
@ -134,13 +135,15 @@ class Dropdown(_Selection):
default_value='', allow_none=True, sync=True, help="""Use a
predefined styling for the buttons.""")
@register()
class RadioButtons(_Selection):
"""Group of radio buttons that represent an enumeration. Only one radio
button can be toggled at any point in time."""
_view_name = Unicode('RadioButtonsView', sync=True)
@register()
class Select(_Selection):
"""Listbox that only allows one item to be selected at any given time."""
_view_name = Unicode('SelectView', sync=True)

@ -14,7 +14,7 @@ pages.
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from .widget_box import Box
from .widget_box import Box, register
from IPython.utils.traitlets import Unicode, Dict, CInt
from IPython.utils.warn import DeprecatedClass
@ -51,12 +51,13 @@ class _SelectionContainer(Box):
else:
return None
@register()
class Accordion(_SelectionContainer):
"""Displays children each on a separate accordion page."""
_view_name = Unicode('AccordionView', sync=True)
@register()
class Tab(_SelectionContainer):
"""Displays children each on a separate accordion tab."""
_view_name = Unicode('TabView', sync=True)

@ -13,7 +13,7 @@ Represents a unicode string using a widget.
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from .widget import DOMWidget, CallbackDispatcher
from .widget import DOMWidget, CallbackDispatcher, register
from IPython.utils.traitlets import Unicode, Bool
from IPython.utils.warn import DeprecatedClass
@ -28,17 +28,20 @@ class _String(DOMWidget):
placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True)
@register()
class HTML(_String):
"""Renders the string `value` as HTML."""
_view_name = Unicode('HTMLView', sync=True)
@register()
class Latex(_String):
"""Renders math inside the string `value` as Latex (requires $ $ or $$ $$
and similar latex tags)."""
_view_name = Unicode('LatexView', sync=True)
@register()
class Textarea(_String):
"""Multiline text area widget."""
_view_name = Unicode('TextareaView', sync=True)
@ -47,6 +50,7 @@ class Textarea(_String):
self.send({"method": "scroll_to_bottom"})
@register()
class Text(_String):
"""Single line textbox widget."""
_view_name = Unicode('TextView', sync=True)

Loading…
Cancel
Save