Merge pull request #7260 from takluyver/widgetvaluedefaults

Widget values as positional arguments
This commit is contained in:
Jonathan Frederic 2014-12-18 08:05:11 -08:00
commit 196478b765
4 changed files with 21 additions and 5 deletions

View File

@ -26,6 +26,10 @@ class _Bool(DOMWidget):
description = Unicode('', help="Description of the boolean (label).", sync=True)
disabled = Bool(False, help="Enable or disable user changes.", sync=True)
def __init__(self, value=None, **kwargs):
if value is not None:
kwargs['value'] = value
super(_Bool, self).__init__(**kwargs)
@register('IPython.Checkbox')
class Checkbox(_Bool):

View File

@ -25,6 +25,10 @@ class _Float(DOMWidget):
disabled = Bool(False, help="Enable or disable user changes", sync=True)
description = Unicode(help="Description of the value this widget represents", sync=True)
def __init__(self, value=None, **kwargs):
if value is not None:
kwargs['value'] = value
super(_Float, self).__init__(**kwargs)
class _BoundedFloat(_Float):
max = CFloat(100.0, help="Max value", sync=True)
@ -33,7 +37,7 @@ class _BoundedFloat(_Float):
def __init__(self, *pargs, **kwargs):
"""Constructor"""
DOMWidget.__init__(self, *pargs, **kwargs)
super(_BoundedFloat, self).__init__(*pargs, **kwargs)
self._validate('value', None, self.value)
self.on_trait_change(self._validate, ['value', 'min', 'max'])

View File

@ -26,6 +26,10 @@ class _Int(DOMWidget):
disabled = Bool(False, help="Enable or disable user changes", sync=True)
description = Unicode(help="Description of the value this widget represents", sync=True)
def __init__(self, value=None, **kwargs):
if value is not None:
kwargs['value'] = value
super(_Int, self).__init__(**kwargs)
class _BoundedInt(_Int):
"""Base class used to create widgets that represent a int that is bounded
@ -36,7 +40,7 @@ class _BoundedInt(_Int):
def __init__(self, *pargs, **kwargs):
"""Constructor"""
DOMWidget.__init__(self, *pargs, **kwargs)
super(_BoundedInt, self).__init__(*pargs, **kwargs)
self.on_trait_change(self._validate_value, ['value'])
self.on_trait_change(self._handle_max_changed, ['max'])
self.on_trait_change(self._handle_min_changed, ['min'])
@ -104,7 +108,7 @@ class _IntRange(_Int):
if lower_given != upper_given:
raise ValueError("Must specify both 'lower' and 'upper' for range widget")
DOMWidget.__init__(self, *pargs, **kwargs)
super(_IntRange, self).__init__(*pargs, **kwargs)
# ensure the traits match, preferring whichever (if any) was given in kwargs
if value_given:

View File

@ -27,6 +27,10 @@ class _String(DOMWidget):
description = Unicode(help="Description of the value this widget represents", sync=True)
placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True)
def __init__(self, value=None, **kwargs):
if value is not None:
kwargs['value'] = value
super(_String, self).__init__(**kwargs)
@register('IPython.HTML')
class HTML(_String):
@ -55,8 +59,8 @@ class Text(_String):
"""Single line textbox widget."""
_view_name = Unicode('TextView', sync=True)
def __init__(self, **kwargs):
super(Text, self).__init__(**kwargs)
def __init__(self, *args, **kwargs):
super(Text, self).__init__(*args, **kwargs)
self._submission_callbacks = CallbackDispatcher()
self.on_msg(self._handle_string_msg)