diff --git a/IPython/html/widgets/__init__.py b/IPython/html/widgets/__init__.py index 69b5dee..e641254 100644 --- a/IPython/html/widgets/__init__.py +++ b/IPython/html/widgets/__init__.py @@ -1,13 +1,13 @@ from .widget import Widget, DOMWidget -from .widget_bool import BoolWidget +from .widget_bool import CheckBoxWidget, ToggleButtonWidget from .widget_button import ButtonWidget -from .widget_container import ContainerWidget -from .widget_float import FloatWidget -from .widget_float_range import FloatRangeWidget +from .widget_container import ContainerWidget, ModalWidget +from .widget_float import FloatTextWidget +from .widget_float_range import BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget from .widget_image import ImageWidget -from .widget_int import IntWidget -from .widget_int_range import IntRangeWidget -from .widget_selection import SelectionWidget -from .widget_selectioncontainer import SelectionContainerWidget -from .widget_string import StringWidget +from .widget_int import IntTextWidget +from .widget_int_range import BoundedIntTextWidget, IntSliderWidget, IntProgressWidget +from .widget_selection import RadioButtonsWidget, ToggleButtonsWidget, DropdownWidget, ListBoxWidget +from .widget_selectioncontainer import TabWidget, AccordionWidget +from .widget_string import HTMLWidget, LatexWidget, TextBoxWidget, TextAreaWidget diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index 98e03b3..830f55a 100644 --- a/IPython/html/widgets/widget_bool.py +++ b/IPython/html/widgets/widget_bool.py @@ -19,11 +19,14 @@ from IPython.utils.traitlets import Unicode, Bool, List #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class BoolWidget(DOMWidget): - view_name = Unicode('CheckboxView', sync=True) +class CheckBoxWidget(DOMWidget): + view_name = Unicode('CheckBoxView', sync=True) # Model Keys value = Bool(False, help="Bool value", sync=True) description = Unicode('', help="Description of the boolean (label).", sync=True) disabled = Bool(False, help="Enable or disable user changes.", sync=True) + +class ToggleButtonWidget(CheckboxWidget): + view_name = Unicode('ToggleButtonView', sync=True) \ No newline at end of file diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index af29188..b1aa4ae 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -28,3 +28,6 @@ class ContainerWidget(DOMWidget): description = Unicode(sync=True) button_text = Unicode(sync=True) + +class ModalWidget(ContainerWidget): + view_name = Unicode('ModalView', sync=True) diff --git a/IPython/html/widgets/widget_float.py b/IPython/html/widgets/widget_float.py index dc0a63c..4979e34 100644 --- a/IPython/html/widgets/widget_float.py +++ b/IPython/html/widgets/widget_float.py @@ -19,7 +19,7 @@ from IPython.utils.traitlets import Unicode, Float, Bool, List #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class FloatWidget(DOMWidget): +class FloatTextWidget(DOMWidget): view_name = Unicode('FloatTextView', sync=True) # Keys diff --git a/IPython/html/widgets/widget_float_range.py b/IPython/html/widgets/widget_float_range.py index 18d17e7..49a619f 100644 --- a/IPython/html/widgets/widget_float_range.py +++ b/IPython/html/widgets/widget_float_range.py @@ -19,14 +19,20 @@ from IPython.utils.traitlets import Unicode, Float, Bool, List #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class FloatRangeWidget(DOMWidget): - view_name = Unicode('FloatSliderView', sync=True) - - # Keys +class BoundedFloatTextWidget(DOMWidget): + view_name = Unicode('FloatTextView', sync=True) value = Float(0.0, help="Float value", sync=True) max = Float(100.0, help="Max value", sync=True) min = Float(0.0, help="Min value", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) step = Float(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True) - orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True) description = Unicode(help="Description of the value this widget represents", sync=True) + + +class FloatSliderWidget(BoundedFloatTextWidget): + view_name = Unicode('FloatSliderView', sync=True) + orientation = Unicode(u'horizontal', help="Vertical or horizontal.", sync=True) + + +class FloatProgressWidget(BoundedFloatTextWidget): + view_name = Unicode('ProgressView', sync=True) diff --git a/IPython/html/widgets/widget_int.py b/IPython/html/widgets/widget_int.py index b3218ea..104d1fe 100644 --- a/IPython/html/widgets/widget_int.py +++ b/IPython/html/widgets/widget_int.py @@ -19,7 +19,7 @@ from IPython.utils.traitlets import Unicode, Int, Bool, List #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class IntWidget(DOMWidget): +class IntTextWidget(DOMWidget): view_name = Unicode('IntTextView', sync=True) # Keys diff --git a/IPython/html/widgets/widget_int_range.py b/IPython/html/widgets/widget_int_range.py index f810cb3..4f16e4c 100644 --- a/IPython/html/widgets/widget_int_range.py +++ b/IPython/html/widgets/widget_int_range.py @@ -19,8 +19,8 @@ from IPython.utils.traitlets import Unicode, Int, Bool, List #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class IntRangeWidget(DOMWidget): - view_name = Unicode('IntSliderView', sync=True) +class BoundedIntTextWidget(DOMWidget): + view_name = Unicode('IntTextView', sync=True) # Keys value = Int(0, help="Int value", sync=True) @@ -28,5 +28,13 @@ class IntRangeWidget(DOMWidget): min = Int(0, help="Min value", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) step = Int(1, help="Minimum step that the value can take (ignored by some views)", sync=True) - orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True) description = Unicode(help="Description of the value this widget represents", sync=True) + + +class IntSliderWidget(BoundedIntTextWidget): + view_name = Unicode('IntSliderView', sync=True) + orientation = Unicode(u'horizontal', help="Vertical or horizontal.", sync=True) + + +class IntProgressWidget(BoundedIntTextWidget): + view_name = Unicode('ProgressView', sync=True) diff --git a/IPython/html/widgets/widget_selection.py b/IPython/html/widgets/widget_selection.py index 2989394..f818963 100644 --- a/IPython/html/widgets/widget_selection.py +++ b/IPython/html/widgets/widget_selection.py @@ -19,12 +19,23 @@ from IPython.utils.traitlets import Unicode, List, Bool #----------------------------------------------------------------------------- # SelectionWidget #----------------------------------------------------------------------------- -class SelectionWidget(DOMWidget): - view_name = Unicode('DropdownView', sync=True) +class ToggleButtonsWidget(DOMWidget): + view_name = Unicode('ToggleButtonsView', sync=True) # Keys value = Unicode(help="Selected value", sync=True) # TODO: Any support values = List(help="List of values the user can select", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) description = Unicode(help="Description of the value this widget represents", sync=True) - \ No newline at end of file + + +class DropdownWidget(SelectionWidget): + view_name = Unicode('DropdownView', sync=True) + + +class RadioButtonsWidget(SelectionWidget): + view_name = Unicode('RadioButtonsView', sync=True) + + +class ListBoxWidget(SelectionWidget): + view_name = Unicode('ListBoxView', sync=True) diff --git a/IPython/html/widgets/widget_selectioncontainer.py b/IPython/html/widgets/widget_selectioncontainer.py index 0b237d4..3283e31 100644 --- a/IPython/html/widgets/widget_selectioncontainer.py +++ b/IPython/html/widgets/widget_selectioncontainer.py @@ -20,8 +20,8 @@ from IPython.utils.traitlets import Unicode, Dict, Int, List, Instance #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class SelectionContainerWidget(DOMWidget): - view_name = Unicode('TabView', sync=True) +class AccordionWidget(DOMWidget): + view_name = Unicode('AccordionView', sync=True) # Keys _titles = Dict(help="Titles of the pages", sync=True) @@ -54,3 +54,7 @@ class SelectionContainerWidget(DOMWidget): return self._titles[index] else: return None + + +class TabWidget(AccordionWidget): + view_name = Unicode('TabView', sync=True) diff --git a/IPython/html/widgets/widget_string.py b/IPython/html/widgets/widget_string.py index a96186c..9be458d 100644 --- a/IPython/html/widgets/widget_string.py +++ b/IPython/html/widgets/widget_string.py @@ -22,8 +22,8 @@ from IPython.utils.traitlets import Unicode, Bool, List, Int #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class StringWidget(DOMWidget): - view_name = Unicode('TextBoxView', sync=True) +class HTMLWidget(DOMWidget): + view_name = Unicode('HTMLView', sync=True) # Keys value = Unicode(help="String value", sync=True) @@ -31,16 +31,25 @@ class StringWidget(DOMWidget): description = Unicode(help="Description of the value this widget represents", sync=True) - def __init__(self, **kwargs): - super(StringWidget, self).__init__(**kwargs) - self._submission_callbacks = [] - self.on_msg(self._handle_string_msg) +class LatexWidget(HTMLWidget): + view_name = Unicode('LatexView', sync=True) + +class TextAreaWidget(HTMLWidget): + view_name = Unicode('TextAreaView', sync=True) def scroll_to_bottom(self): self.send({"method": "scroll_to_bottom"}) +class TextBoxWidget(HTMLWidget): + view_name = Unicode('TextBoxView', sync=True) + + def __init__(self, **kwargs): + super(StringWidget, self).__init__(**kwargs) + self._submission_callbacks = [] + self.on_msg(self._handle_string_msg) + def _handle_string_msg(self, content): """Handle a msg from the front-end @@ -49,8 +58,8 @@ class StringWidget(DOMWidget): content: dict Content of the msg.""" if 'event' in content and content['event'] == 'submit': - self._handle_submit() - + for handler in self._submission_callbacks: + handler(self) def on_submit(self, callback, remove=False): """Register a callback to handle text submission (triggered when the @@ -67,25 +76,19 @@ class StringWidget(DOMWidget): if remove and callback in self._submission_callbacks: self._submission_callbacks.remove(callback) elif not remove and not callback in self._submission_callbacks: - self._submission_callbacks.append(callback) - - - def _handle_submit(self): - """Handles when a string widget view is submitted.""" - for handler in self._submission_callbacks: - if callable(handler): - argspec = inspect.getargspec(handler) + if callable(callback): + argspec = inspect.getargspec(callback) nargs = len(argspec[0]) # Bound methods have an additional 'self' argument - if isinstance(handler, types.MethodType): + if isinstance(callback, types.MethodType): nargs -= 1 # Call the callback if nargs == 0: - handler() + self._submission_callbacks.append(lambda sender: callback()) elif nargs == 1: - handler(self) + self._submission_callbacks.append(callback) else: raise TypeError('StringWidget submit callback must ' \ 'accept 0 or 1 arguments.')