##// END OF EJS Templates
Dev meeting Jan 2014, widget review day 2
Jonathan Frederic -
Show More
@@ -27,7 +27,7 b''
27
27
28 // Backbone.sync method must be in widgetmanager.js file instead of
28 // Backbone.sync method must be in widgetmanager.js file instead of
29 // widget.js so it can be overwritten for different contexts.
29 // widget.js so it can be overwritten for different contexts.
30 Backbone.sync = function (method, model, options, error) {
30 Backbone.sync = function (method, model, options) {
31 var result = model._handle_sync(method, options);
31 var result = model._handle_sync(method, options);
32 if (options.success) {
32 if (options.success) {
33 options.success(result);
33 options.success(result);
@@ -51,6 +51,7 b''
51
51
52 // Register already-registered widget model types with the comm manager.
52 // Register already-registered widget model types with the comm manager.
53 for (var widget_model_name in this._model_types) {
53 for (var widget_model_name in this._model_types) {
54 // TODO: Should not be a for.
54 this.comm_manager.register_target(widget_model_name, $.proxy(this._handle_comm_open, this));
55 this.comm_manager.register_target(widget_model_name, $.proxy(this._handle_comm_open, this));
55 }
56 }
56 };
57 };
@@ -16,34 +16,6 b''
16
16
17 define(["notebook/js/widgets/widget"], function(widget_manager) {
17 define(["notebook/js/widgets/widget"], function(widget_manager) {
18
18
19 var set_flex_property = function(element, property_name, enabled) {
20 if (enabled) {
21 element.addClass(property_name);
22 } else {
23 element.removeClass(property_name);
24 }
25 };
26
27 var set_flex_properties = function(context, element) {
28
29 // Apply flexible box model properties by adding and removing
30 // corrosponding CSS classes.
31 // Defined in IPython/html/static/base/less/flexbox.less
32 set_flex_property(element, 'vbox', context.model.get('_vbox'));
33 set_flex_property(element, 'hbox', context.model.get('_hbox'));
34 set_flex_property(element, 'start', context.model.get('_pack_start'));
35 set_flex_property(element, 'center', context.model.get('_pack_center'));
36 set_flex_property(element, 'end', context.model.get('_pack_end'));
37 set_flex_property(element, 'align-start', context.model.get('_align_start'));
38 set_flex_property(element, 'align-center', context.model.get('_align_center'));
39 set_flex_property(element, 'align-end', context.model.get('_align_end'));
40 set_flex_property(element, 'box-flex0', context.model.get('_flex0'));
41 set_flex_property(element, 'box-flex1', context.model.get('_flex1'));
42 set_flex_property(element, 'box-flex2', context.model.get('_flex2'));
43 };
44
45
46
47 var ContainerModel = IPython.WidgetModel.extend({});
19 var ContainerModel = IPython.WidgetModel.extend({});
48 widget_manager.register_widget_model('ContainerWidgetModel', ContainerModel);
20 widget_manager.register_widget_model('ContainerWidgetModel', ContainerModel);
49
21
@@ -73,7 +45,6 b' define(["notebook/js/widgets/widget"], function(widget_manager) {'
73 //
45 //
74 // Called when the model is changed. The model may have been
46 // Called when the model is changed. The model may have been
75 // changed by another view or by a state update from the back-end.
47 // changed by another view or by a state update from the back-end.
76 set_flex_properties(this, this.$el);
77 return ContainerView.__super__.update.apply(this);
48 return ContainerView.__super__.update.apply(this);
78 },
49 },
79 });
50 });
@@ -233,8 +204,6 b' define(["notebook/js/widgets/widget"], function(widget_manager) {'
233 //
204 //
234 // Called when the model is changed. The model may have been
205 // Called when the model is changed. The model may have been
235 // changed by another view or by a state update from the back-end.
206 // changed by another view or by a state update from the back-end.
236 set_flex_properties(this, this.$body);
237
238 var description = this.model.get('description');
207 var description = this.model.get('description');
239 description = description.replace(/ /g, ' ', 'm');
208 description = description.replace(/ /g, ' ', 'm');
240 description = description.replace(/\n/g, '<br>\n', 'm');
209 description = description.replace(/\n/g, '<br>\n', 'm');
@@ -11,8 +11,9 b' casper.notebook_test(function () {'
11
11
12 var floatrange_index = this.append_cell(
12 var floatrange_index = this.append_cell(
13 'floatrange = widgets.FloatRangeWidget()\n' +
13 'floatrange = widgets.FloatRangeWidget()\n' +
14 'floatrange2 = widgets.FloatRangeWidget()\n' +
14 'display(floatrange)\n' +
15 'display(floatrange)\n' +
15 'display(floatrange, view_name="FloatTextView")\n' +
16 'display(floatrange2)\n' +
16 'print("Success")\n');
17 'print("Success")\n');
17 this.execute_cell_then(floatrange_index, function(index){
18 this.execute_cell_then(floatrange_index, function(index){
18
19
@@ -327,7 +327,7 b' class DOMWidget(Widget):'
327 # Private/protected declarations
327 # Private/protected declarations
328 _css = Dict() # Internal CSS property dict
328 _css = Dict() # Internal CSS property dict
329
329
330 keys = ['visible', '_css'] + Widget.keys
330 keys = ['visible', '_css'] + Widget.keys # TODO
331
331
332 def get_css(self, key, selector=""):
332 def get_css(self, key, selector=""):
333 """Get a CSS property of the widget.
333 """Get a CSS property of the widget.
@@ -25,179 +25,8 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 = ['_vbox', '_hbox', '_align_start', '_align_end', '_align_center',
28 keys = ['description', 'button_text', 'children'] + DOMWidget.keys # TODO: Use add/remove_class
29 '_pack_start', '_pack_end', '_pack_center', '_flex0', '_flex1',
30 '_flex2', 'description', 'button_text',
31 'children'] + DOMWidget.keys
32 children = List(Instance(DOMWidget))
29 children = List(Instance(DOMWidget))
33
30
34 description = Unicode()
31 description = Unicode()
35 button_text = Unicode()
32 button_text = Unicode()
36 _hbox = Bool(False)
37 _vbox = Bool(False)
38 _align_start = Bool(False)
39 _align_end = Bool(False)
40 _align_center = Bool(False)
41 _pack_start = Bool(False)
42 _pack_end = Bool(False)
43 _pack_center = Bool(False)
44 _flex0 = Bool(False)
45 _flex1 = Bool(False)
46 _flex2 = Bool(False)
47
48 def hbox(self, enabled=True):
49 """Make this container an hbox. Automatically disables conflicting
50 features.
51
52 Parameters
53 ----------
54 enabled: bool (optional)
55 Enabled or disable the hbox feature of the container, defaults to
56 True."""
57 self._hbox = enabled
58 if enabled:
59 self._vbox = False
60
61 def vbox(self, enabled=True):
62 """Make this container an vbox. Automatically disables conflicting
63 features.
64
65 Parameters
66 ----------
67 enabled: bool (optional)
68 Enabled or disable the vbox feature of the container, defaults to
69 True."""
70 self._vbox = enabled
71 if enabled:
72 self._hbox = False
73
74 def align_start(self, enabled=True):
75 """Make the contents of this container align to the start of the axis.
76 Automatically disables conflicting alignments.
77
78 Parameters
79 ----------
80 enabled: bool (optional)
81 Enabled or disable the start alignment of the container, defaults to
82 True."""
83 self._align_start = enabled
84 if enabled:
85 self._align_end = False
86 self._align_center = False
87
88 def align_end(self, enabled=True):
89 """Make the contents of this container align to the end of the axis.
90 Automatically disables conflicting alignments.
91
92 Parameters
93 ----------
94 enabled: bool (optional)
95 Enabled or disable the end alignment of the container, defaults to
96 True."""
97 self._align_end = enabled
98 if enabled:
99 self._align_start = False
100 self._align_center = False
101
102 def align_center(self, enabled=True):
103 """Make the contents of this container align to the center of the axis.
104 Automatically disables conflicting alignments.
105
106 Parameters
107 ----------
108 enabled: bool (optional)
109 Enabled or disable the center alignment of the container, defaults to
110 True."""
111 self._align_center = enabled
112 if enabled:
113 self._align_start = False
114 self._align_end = False
115
116
117 def pack_start(self, enabled=True):
118 """Make the contents of this container pack to the start of the axis.
119 Automatically disables conflicting packings.
120
121 Parameters
122 ----------
123 enabled: bool (optional)
124 Enabled or disable the start packing of the container, defaults to
125 True."""
126 self._pack_start = enabled
127 if enabled:
128 self._pack_end = False
129 self._pack_center = False
130
131 def pack_end(self, enabled=True):
132 """Make the contents of this container pack to the end of the axis.
133 Automatically disables conflicting packings.
134
135 Parameters
136 ----------
137 enabled: bool (optional)
138 Enabled or disable the end packing of the container, defaults to
139 True."""
140 self._pack_end = enabled
141 if enabled:
142 self._pack_start = False
143 self._pack_center = False
144
145 def pack_center(self, enabled=True):
146 """Make the contents of this container pack to the center of the axis.
147 Automatically disables conflicting packings.
148
149 Parameters
150 ----------
151 enabled: bool (optional)
152 Enabled or disable the center packing of the container, defaults to
153 True."""
154 self._pack_center = enabled
155 if enabled:
156 self._pack_start = False
157 self._pack_end = False
158
159
160 def flex0(self, enabled=True):
161 """Put this container in flex0 mode. Automatically disables conflicting
162 flex modes. See the widget tutorial part 5 example notebook for more
163 information.
164
165 Parameters
166 ----------
167 enabled: bool (optional)
168 Enabled or disable the flex0 attribute of the container, defaults to
169 True."""
170 self._flex0 = enabled
171 if enabled:
172 self._flex1 = False
173 self._flex2 = False
174
175 def flex1(self, enabled=True):
176 """Put this container in flex1 mode. Automatically disables conflicting
177 flex modes. See the widget tutorial part 5 example notebook for more
178 information.
179
180 Parameters
181 ----------
182 enabled: bool (optional)
183 Enabled or disable the flex1 attribute of the container, defaults to
184 True."""
185 self._flex1 = enabled
186 if enabled:
187 self._flex0 = False
188 self._flex2 = False
189
190 def flex2(self, enabled=True):
191 """Put this container in flex2 mode. Automatically disables conflicting
192 flex modes. See the widget tutorial part 5 example notebook for more
193 information.
194
195 Parameters
196 ----------
197 enabled: bool (optional)
198 Enabled or disable the flex2 attribute of the container, defaults to
199 True."""
200 self._flex2 = enabled
201 if enabled:
202 self._flex0 = False
203 self._flex1 = False
@@ -29,7 +29,7 b' class ImageWidget(DOMWidget):'
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 keys = ['format', 'width', 'height', '_b64value'] + DOMWidget.keys
31 format = Unicode('png')
31 format = Unicode('png')
32 width = Unicode()
32 width = Unicode() # TODO: C unicode
33 height = Unicode()
33 height = Unicode()
34 _b64value = Unicode()
34 _b64value = Unicode()
35
35
@@ -25,7 +25,7 b' class SelectionWidget(DOMWidget):'
25
25
26 # Keys
26 # Keys
27 keys = ['value', 'values', 'disabled', 'description'] + DOMWidget.keys
27 keys = ['value', 'values', 'disabled', 'description'] + DOMWidget.keys
28 value = Unicode(help="Selected value")
28 value = Unicode(help="Selected value") # TODO: Any support
29 values = List(help="List of values the user can select")
29 values = List(help="List of values the user can select")
30 disabled = Bool(False, help="Enable or disable user changes")
30 disabled = Bool(False, help="Enable or disable user changes")
31 description = Unicode(help="Description of the value this widget represents")
31 description = Unicode(help="Description of the value this widget represents")
General Comments 0
You need to be logged in to leave comments. Login now