From 827311cf3788c0d659634d30ca7b6c20f81cda99 2014-12-17 20:45:58 From: Jason Goad Date: 2014-12-17 20:45:58 Subject: [PATCH] added value positional argument to applicable widgets --- diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index e21ad3d..a6f1ff5 100644 --- a/IPython/html/widgets/widget_bool.py +++ b/IPython/html/widgets/widget_bool.py @@ -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): diff --git a/IPython/html/widgets/widget_float.py b/IPython/html/widgets/widget_float.py index eab4f66..506fb03 100644 --- a/IPython/html/widgets/widget_float.py +++ b/IPython/html/widgets/widget_float.py @@ -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']) diff --git a/IPython/html/widgets/widget_int.py b/IPython/html/widgets/widget_int.py index 9a36b88..985fa86 100644 --- a/IPython/html/widgets/widget_int.py +++ b/IPython/html/widgets/widget_int.py @@ -40,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']) @@ -108,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(_BoundedInt, self).__init__(*pargs, **kwargs) # ensure the traits match, preferring whichever (if any) was given in kwargs if value_given: diff --git a/IPython/html/widgets/widget_string.py b/IPython/html/widgets/widget_string.py index 30245a2..a20dcbc 100644 --- a/IPython/html/widgets/widget_string.py +++ b/IPython/html/widgets/widget_string.py @@ -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, *parg, **kwargs): + super(Text, self).__init__(*parg, **kwargs) self._submission_callbacks = CallbackDispatcher() self.on_msg(self._handle_string_msg)