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