From 7bcced9da01ad55d71e2338dc38c3faa49d13784 Mon Sep 17 00:00:00 2001 From: Jason Goad Date: Sat, 27 Sep 2014 12:14:21 -0700 Subject: [PATCH 1/4] widget fix? --- IPython/html/widgets/widget_int.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/IPython/html/widgets/widget_int.py b/IPython/html/widgets/widget_int.py index 582ae0304..9a36b88a8 100644 --- a/IPython/html/widgets/widget_int.py +++ b/IPython/html/widgets/widget_int.py @@ -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 From cda015340c41225c25de551bd5cf45f539204000 Mon Sep 17 00:00:00 2001 From: Jason Goad Date: Sat, 27 Sep 2014 13:07:42 -0700 Subject: [PATCH 2/4] added value positional argument to applicable widgets --- IPython/html/widgets/widget_bool.py | 4 ++++ IPython/html/widgets/widget_float.py | 6 +++++- IPython/html/widgets/widget_int.py | 4 ++-- IPython/html/widgets/widget_string.py | 8 ++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index e21ad3d99..a6f1ff55f 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 eab4f6663..506fb0300 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 9a36b88a8..985fa86cf 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 30245a2d8..a20dcbcea 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) From cbb685b314d3dab55fb576e75362da6a6d535262 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 17 Dec 2014 12:47:04 -0800 Subject: [PATCH 3/4] Fix copy-pasted super() call --- IPython/html/widgets/widget_int.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/html/widgets/widget_int.py b/IPython/html/widgets/widget_int.py index 985fa86cf..ff6efdcce 100644 --- a/IPython/html/widgets/widget_int.py +++ b/IPython/html/widgets/widget_int.py @@ -108,7 +108,7 @@ class _IntRange(_Int): if lower_given != upper_given: raise ValueError("Must specify both 'lower' and 'upper' for range widget") - super(_BoundedInt, self).__init__(*pargs, **kwargs) + super(_IntRange, self).__init__(*pargs, **kwargs) # ensure the traits match, preferring whichever (if any) was given in kwargs if value_given: From 9c0fb7bf6863b49ff13db99a3aa61474924cdd61 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 17 Dec 2014 12:47:56 -0800 Subject: [PATCH 4/4] Use more conventional *args naming over *parg --- IPython/html/widgets/widget_string.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IPython/html/widgets/widget_string.py b/IPython/html/widgets/widget_string.py index a20dcbcea..96d7d4408 100644 --- a/IPython/html/widgets/widget_string.py +++ b/IPython/html/widgets/widget_string.py @@ -59,8 +59,8 @@ class Text(_String): """Single line textbox widget.""" _view_name = Unicode('TextView', sync=True) - def __init__(self, *parg, **kwargs): - super(Text, self).__init__(*parg, **kwargs) + def __init__(self, *args, **kwargs): + super(Text, self).__init__(*args, **kwargs) self._submission_callbacks = CallbackDispatcher() self.on_msg(self._handle_string_msg)