diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py index df69558..831e762 100644 --- a/IPython/html/widgets/widget.py +++ b/IPython/html/widgets/widget.py @@ -30,8 +30,6 @@ class Widget(LoggingConfigurable): widget_construction_callback = None widgets = {} - keys = ['view_name'] # TODO: Sync = True - def on_widget_constructed(callback): """Class method, registers a callback to be called when a widget is constructed. The callback must have the following signature: @@ -49,7 +47,7 @@ class Widget(LoggingConfigurable): model_name = Unicode('widget', help="""Name of the backbone model registered in the front-end to create and sync this widget with.""") view_name = Unicode(help="""Default view registered in the front-end - to use to represent the widget.""") + to use to represent the widget.""", sync=True) @contextmanager def property_lock(self, key, value): @@ -69,6 +67,15 @@ class Widget(LoggingConfigurable): return key != self._property_lock[0] or \ value != self._property_lock[1] + @property + def keys(self): + if self._keys is None: + self._keys = [] + for trait_name in self.trait_names(): + if self.trait_metadata(trait_name, 'sync'): + self._keys.append(trait_name) + return self._keys + # Private/protected declarations _comm = Instance('IPython.kernel.comm.Comm') @@ -79,6 +86,7 @@ class Widget(LoggingConfigurable): self._property_lock = (None, None) self._display_callbacks = [] self._msg_callbacks = [] + self._keys = None super(Widget, self).__init__(**kwargs) self.on_trait_change(self._handle_property_changed, self.keys) diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index f2984c0..e67efb3 100644 --- a/IPython/html/widgets/widget_bool.py +++ b/IPython/html/widgets/widget_bool.py @@ -24,8 +24,7 @@ class BoolWidget(DOMWidget): view_name = Unicode('CheckboxView') # Model Keys - keys = ['value', 'description', 'disabled'] + DOMWidget.keys - value = Bool(False, help="Bool value") - description = Unicode('', help="Description of the boolean (label).") - disabled = Bool(False, help="Enable or disable user changes.") + 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) \ No newline at end of file diff --git a/IPython/html/widgets/widget_button.py b/IPython/html/widgets/widget_button.py index adce730..0f09381 100644 --- a/IPython/html/widgets/widget_button.py +++ b/IPython/html/widgets/widget_button.py @@ -28,9 +28,8 @@ class ButtonWidget(DOMWidget): view_name = Unicode('ButtonView') # Keys - keys = ['description', 'disabled'] + DOMWidget.keys - description = Unicode('', help="Description of the button (label).") - disabled = Bool(False, help="Enable or disable user changes.") + description = Unicode('', help="Description of the button (label).", sync=True) + disabled = Bool(False, help="Enable or disable user changes.", sync=True) def __init__(self, **kwargs): diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index ae89546..049f8f3 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -25,8 +25,7 @@ class ContainerWidget(DOMWidget): # Keys, all private and managed by helper methods. Flexible box model # classes... - keys = ['description', 'button_text', 'children'] + DOMWidget.keys # TODO: Use add/remove_class - children = List(Instance(DOMWidget)) + children = List(Instance(DOMWidget), sync=True) - description = Unicode() - button_text = Unicode() + description = Unicode(sync=True) + button_text = Unicode(sync=True) diff --git a/IPython/html/widgets/widget_float.py b/IPython/html/widgets/widget_float.py index c4b9f8b..e2ff8e3 100644 --- a/IPython/html/widgets/widget_float.py +++ b/IPython/html/widgets/widget_float.py @@ -24,7 +24,6 @@ class FloatWidget(DOMWidget): view_name = Unicode('FloatTextView') # Keys - keys = ['value', 'disabled', 'description'] + DOMWidget.keys - value = Float(0.0, help="Float value") - disabled = Bool(False, help="Enable or disable user changes") - description = Unicode(help="Description of the value this widget represents") + value = Float(0.0, help="Float value", 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) diff --git a/IPython/html/widgets/widget_float_range.py b/IPython/html/widgets/widget_float_range.py index 4326338..1105c06 100644 --- a/IPython/html/widgets/widget_float_range.py +++ b/IPython/html/widgets/widget_float_range.py @@ -24,11 +24,10 @@ class FloatRangeWidget(DOMWidget): view_name = Unicode('FloatSliderView') # Keys - keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + DOMWidget.keys - value = Float(0.0, help="Float value") - max = Float(100.0, help="Max value") - min = Float(0.0, help="Min value") - disabled = Bool(False, help="Enable or disable user changes") - step = Float(0.1, help="Minimum step that the value can take (ignored by some views)") - orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)") - description = Unicode(help="Description of the value this widget represents") + 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) diff --git a/IPython/html/widgets/widget_image.py b/IPython/html/widgets/widget_image.py index d7557b7..7442fe7 100644 --- a/IPython/html/widgets/widget_image.py +++ b/IPython/html/widgets/widget_image.py @@ -27,11 +27,10 @@ class ImageWidget(DOMWidget): view_name = Unicode('ImageView') # Define the custom state properties to sync with the front-end - keys = ['format', 'width', 'height', '_b64value'] + DOMWidget.keys - format = Unicode('png') - width = Unicode() # TODO: C unicode - height = Unicode() - _b64value = Unicode() + format = Unicode('png', sync=True) + width = Unicode(sync=True) # TODO: C unicode + height = Unicode(sync=True) + _b64value = Unicode(sync=True) value = Bytes() def _value_changed(self, name, old, new): diff --git a/IPython/html/widgets/widget_int.py b/IPython/html/widgets/widget_int.py index e03dafb..d7c255d 100644 --- a/IPython/html/widgets/widget_int.py +++ b/IPython/html/widgets/widget_int.py @@ -24,7 +24,6 @@ class IntWidget(DOMWidget): view_name = Unicode('IntTextView') # Keys - keys = ['value', 'disabled', 'description'] + DOMWidget.keys - value = Int(0, help="Int value") - disabled = Bool(False, help="Enable or disable user changes") - description = Unicode(help="Description of the value this widget represents") + value = Int(0, help="Int value", 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) diff --git a/IPython/html/widgets/widget_int_range.py b/IPython/html/widgets/widget_int_range.py index 819bc4a..9aa9d11 100644 --- a/IPython/html/widgets/widget_int_range.py +++ b/IPython/html/widgets/widget_int_range.py @@ -24,11 +24,10 @@ class IntRangeWidget(DOMWidget): view_name = Unicode('IntSliderView') # Keys - keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + DOMWidget.keys - value = Int(0, help="Int value") - max = Int(100, help="Max value") - min = Int(0, help="Min value") - disabled = Bool(False, help="Enable or disable user changes") - step = Int(1, help="Minimum step that the value can take (ignored by some views)") - orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)") - description = Unicode(help="Description of the value this widget represents") + value = Int(0, help="Int value", sync=True) + max = Int(100, help="Max value", sync=True) + 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) diff --git a/IPython/html/widgets/widget_selection.py b/IPython/html/widgets/widget_selection.py index 91256d6..b477bc9 100644 --- a/IPython/html/widgets/widget_selection.py +++ b/IPython/html/widgets/widget_selection.py @@ -24,9 +24,8 @@ class SelectionWidget(DOMWidget): view_name = Unicode('DropdownView') # Keys - keys = ['value', 'values', 'disabled', 'description'] + DOMWidget.keys - value = Unicode(help="Selected value") # TODO: Any support - values = List(help="List of values the user can select") - disabled = Bool(False, help="Enable or disable user changes") - description = Unicode(help="Description of the value this widget represents") + 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 diff --git a/IPython/html/widgets/widget_selectioncontainer.py b/IPython/html/widgets/widget_selectioncontainer.py index efb0ba8..d941621 100644 --- a/IPython/html/widgets/widget_selectioncontainer.py +++ b/IPython/html/widgets/widget_selectioncontainer.py @@ -25,9 +25,8 @@ class SelectionContainerWidget(DOMWidget): view_name = Unicode('TabView') # Keys - keys = ['_titles', 'selected_index', 'children'] + DOMWidget.keys - _titles = Dict(help="Titles of the pages") - selected_index = Int(0) + _titles = Dict(help="Titles of the pages", sync=True) + selected_index = Int(0, sync=True) children = List(Instance(DOMWidget)) diff --git a/IPython/html/widgets/widget_string.py b/IPython/html/widgets/widget_string.py index 35c099a..4b8d27a 100644 --- a/IPython/html/widgets/widget_string.py +++ b/IPython/html/widgets/widget_string.py @@ -27,10 +27,9 @@ class StringWidget(DOMWidget): view_name = Unicode('TextBoxView') # Keys - keys = ['value', 'disabled', 'description'] + DOMWidget.keys - value = Unicode(help="String value") - disabled = Bool(False, help="Enable or disable user changes") - description = Unicode(help="Description of the value this widget represents") + value = Unicode(help="String value", 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) def __init__(self, **kwargs):