##// END OF EJS Templates
sync=True isntead of a keys list
Jonathan Frederic -
Show More
@@ -30,8 +30,6 b' class Widget(LoggingConfigurable):'
30 widget_construction_callback = None
30 widget_construction_callback = None
31 widgets = {}
31 widgets = {}
32
32
33 keys = ['view_name'] # TODO: Sync = True
34
35 def on_widget_constructed(callback):
33 def on_widget_constructed(callback):
36 """Class method, registers a callback to be called when a widget is
34 """Class method, registers a callback to be called when a widget is
37 constructed. The callback must have the following signature:
35 constructed. The callback must have the following signature:
@@ -49,7 +47,7 b' class Widget(LoggingConfigurable):'
49 model_name = Unicode('widget', help="""Name of the backbone model
47 model_name = Unicode('widget', help="""Name of the backbone model
50 registered in the front-end to create and sync this widget with.""")
48 registered in the front-end to create and sync this widget with.""")
51 view_name = Unicode(help="""Default view registered in the front-end
49 view_name = Unicode(help="""Default view registered in the front-end
52 to use to represent the widget.""")
50 to use to represent the widget.""", sync=True)
53
51
54 @contextmanager
52 @contextmanager
55 def property_lock(self, key, value):
53 def property_lock(self, key, value):
@@ -69,6 +67,15 b' class Widget(LoggingConfigurable):'
69 return key != self._property_lock[0] or \
67 return key != self._property_lock[0] or \
70 value != self._property_lock[1]
68 value != self._property_lock[1]
71
69
70 @property
71 def keys(self):
72 if self._keys is None:
73 self._keys = []
74 for trait_name in self.trait_names():
75 if self.trait_metadata(trait_name, 'sync'):
76 self._keys.append(trait_name)
77 return self._keys
78
72 # Private/protected declarations
79 # Private/protected declarations
73 _comm = Instance('IPython.kernel.comm.Comm')
80 _comm = Instance('IPython.kernel.comm.Comm')
74
81
@@ -79,6 +86,7 b' class Widget(LoggingConfigurable):'
79 self._property_lock = (None, None)
86 self._property_lock = (None, None)
80 self._display_callbacks = []
87 self._display_callbacks = []
81 self._msg_callbacks = []
88 self._msg_callbacks = []
89 self._keys = None
82 super(Widget, self).__init__(**kwargs)
90 super(Widget, self).__init__(**kwargs)
83
91
84 self.on_trait_change(self._handle_property_changed, self.keys)
92 self.on_trait_change(self._handle_property_changed, self.keys)
@@ -24,8 +24,7 b' class BoolWidget(DOMWidget):'
24 view_name = Unicode('CheckboxView')
24 view_name = Unicode('CheckboxView')
25
25
26 # Model Keys
26 # Model Keys
27 keys = ['value', 'description', 'disabled'] + DOMWidget.keys
27 value = Bool(False, help="Bool value", sync=True)
28 value = Bool(False, help="Bool value")
28 description = Unicode('', help="Description of the boolean (label).", sync=True)
29 description = Unicode('', help="Description of the boolean (label).")
29 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
30 disabled = Bool(False, help="Enable or disable user changes.")
31 No newline at end of file
30
@@ -28,9 +28,8 b' class ButtonWidget(DOMWidget):'
28 view_name = Unicode('ButtonView')
28 view_name = Unicode('ButtonView')
29
29
30 # Keys
30 # Keys
31 keys = ['description', 'disabled'] + DOMWidget.keys
31 description = Unicode('', help="Description of the button (label).", sync=True)
32 description = Unicode('', help="Description of the button (label).")
32 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
33 disabled = Bool(False, help="Enable or disable user changes.")
34
33
35
34
36 def __init__(self, **kwargs):
35 def __init__(self, **kwargs):
@@ -25,8 +25,7 b' class ContainerWidget(DOMWidget):'
25
25
26 # Keys, all private and managed by helper methods. Flexible box model
26 # Keys, all private and managed by helper methods. Flexible box model
27 # classes...
27 # classes...
28 keys = ['description', 'button_text', 'children'] + DOMWidget.keys # TODO: Use add/remove_class
28 children = List(Instance(DOMWidget), sync=True)
29 children = List(Instance(DOMWidget))
30
29
31 description = Unicode()
30 description = Unicode(sync=True)
32 button_text = Unicode()
31 button_text = Unicode(sync=True)
@@ -24,7 +24,6 b' class FloatWidget(DOMWidget):'
24 view_name = Unicode('FloatTextView')
24 view_name = Unicode('FloatTextView')
25
25
26 # Keys
26 # Keys
27 keys = ['value', 'disabled', 'description'] + DOMWidget.keys
27 value = Float(0.0, help="Float value", sync=True)
28 value = Float(0.0, help="Float value")
28 disabled = Bool(False, help="Enable or disable user changes", sync=True)
29 disabled = Bool(False, help="Enable or disable user changes")
29 description = Unicode(help="Description of the value this widget represents", sync=True)
30 description = Unicode(help="Description of the value this widget represents")
@@ -24,11 +24,10 b' class FloatRangeWidget(DOMWidget):'
24 view_name = Unicode('FloatSliderView')
24 view_name = Unicode('FloatSliderView')
25
25
26 # Keys
26 # Keys
27 keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + DOMWidget.keys
27 value = Float(0.0, help="Float value", sync=True)
28 value = Float(0.0, help="Float value")
28 max = Float(100.0, help="Max value", sync=True)
29 max = Float(100.0, help="Max value")
29 min = Float(0.0, help="Min value", sync=True)
30 min = Float(0.0, help="Min value")
30 disabled = Bool(False, help="Enable or disable user changes", sync=True)
31 disabled = Bool(False, help="Enable or disable user changes")
31 step = Float(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True)
32 step = Float(0.1, help="Minimum step that the value can take (ignored by some views)")
32 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True)
33 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)")
33 description = Unicode(help="Description of the value this widget represents", sync=True)
34 description = Unicode(help="Description of the value this widget represents")
@@ -27,11 +27,10 b' class ImageWidget(DOMWidget):'
27 view_name = Unicode('ImageView')
27 view_name = Unicode('ImageView')
28
28
29 # Define the custom state properties to sync with the front-end
29 # Define the custom state properties to sync with the front-end
30 keys = ['format', 'width', 'height', '_b64value'] + DOMWidget.keys
30 format = Unicode('png', sync=True)
31 format = Unicode('png')
31 width = Unicode(sync=True) # TODO: C unicode
32 width = Unicode() # TODO: C unicode
32 height = Unicode(sync=True)
33 height = Unicode()
33 _b64value = Unicode(sync=True)
34 _b64value = Unicode()
35
34
36 value = Bytes()
35 value = Bytes()
37 def _value_changed(self, name, old, new):
36 def _value_changed(self, name, old, new):
@@ -24,7 +24,6 b' class IntWidget(DOMWidget):'
24 view_name = Unicode('IntTextView')
24 view_name = Unicode('IntTextView')
25
25
26 # Keys
26 # Keys
27 keys = ['value', 'disabled', 'description'] + DOMWidget.keys
27 value = Int(0, help="Int value", sync=True)
28 value = Int(0, help="Int value")
28 disabled = Bool(False, help="Enable or disable user changes", sync=True)
29 disabled = Bool(False, help="Enable or disable user changes")
29 description = Unicode(help="Description of the value this widget represents", sync=True)
30 description = Unicode(help="Description of the value this widget represents")
@@ -24,11 +24,10 b' class IntRangeWidget(DOMWidget):'
24 view_name = Unicode('IntSliderView')
24 view_name = Unicode('IntSliderView')
25
25
26 # Keys
26 # Keys
27 keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + DOMWidget.keys
27 value = Int(0, help="Int value", sync=True)
28 value = Int(0, help="Int value")
28 max = Int(100, help="Max value", sync=True)
29 max = Int(100, help="Max value")
29 min = Int(0, help="Min value", sync=True)
30 min = Int(0, help="Min value")
30 disabled = Bool(False, help="Enable or disable user changes", sync=True)
31 disabled = Bool(False, help="Enable or disable user changes")
31 step = Int(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
32 step = Int(1, help="Minimum step that the value can take (ignored by some views)")
32 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True)
33 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)")
33 description = Unicode(help="Description of the value this widget represents", sync=True)
34 description = Unicode(help="Description of the value this widget represents")
@@ -24,9 +24,8 b' class SelectionWidget(DOMWidget):'
24 view_name = Unicode('DropdownView')
24 view_name = Unicode('DropdownView')
25
25
26 # Keys
26 # Keys
27 keys = ['value', 'values', 'disabled', 'description'] + DOMWidget.keys
27 value = Unicode(help="Selected value", sync=True) # TODO: Any support
28 value = Unicode(help="Selected value") # TODO: Any support
28 values = List(help="List of values the user can select", sync=True)
29 values = List(help="List of values the user can select")
29 disabled = Bool(False, help="Enable or disable user changes", sync=True)
30 disabled = Bool(False, help="Enable or disable user changes")
30 description = Unicode(help="Description of the value this widget represents", sync=True)
31 description = Unicode(help="Description of the value this widget represents")
32 No newline at end of file
31
@@ -25,9 +25,8 b' class SelectionContainerWidget(DOMWidget):'
25 view_name = Unicode('TabView')
25 view_name = Unicode('TabView')
26
26
27 # Keys
27 # Keys
28 keys = ['_titles', 'selected_index', 'children'] + DOMWidget.keys
28 _titles = Dict(help="Titles of the pages", sync=True)
29 _titles = Dict(help="Titles of the pages")
29 selected_index = Int(0, sync=True)
30 selected_index = Int(0)
31
30
32 children = List(Instance(DOMWidget))
31 children = List(Instance(DOMWidget))
33
32
@@ -27,10 +27,9 b' class StringWidget(DOMWidget):'
27 view_name = Unicode('TextBoxView')
27 view_name = Unicode('TextBoxView')
28
28
29 # Keys
29 # Keys
30 keys = ['value', 'disabled', 'description'] + DOMWidget.keys
30 value = Unicode(help="String value", sync=True)
31 value = Unicode(help="String value")
31 disabled = Bool(False, help="Enable or disable user changes", sync=True)
32 disabled = Bool(False, help="Enable or disable user changes")
32 description = Unicode(help="Description of the value this widget represents", sync=True)
33 description = Unicode(help="Description of the value this widget represents")
34
33
35
34
36 def __init__(self, **kwargs):
35 def __init__(self, **kwargs):
General Comments 0
You need to be logged in to leave comments. Login now