##// END OF EJS Templates
Fixed & separated output_area -> widget_area logic
Jonathan Frederic -
Show More
@@ -1,454 +1,463 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2013 The IPython Development Team
2 // Copyright (C) 2013 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // WidgetModel, WidgetView, and WidgetManager
9 // WidgetModel, WidgetView, and WidgetManager
10 //============================================================================
10 //============================================================================
11 /**
11 /**
12 * Base Widget classes
12 * Base Widget classes
13 * @module IPython
13 * @module IPython
14 * @namespace IPython
14 * @namespace IPython
15 * @submodule widget
15 * @submodule widget
16 */
16 */
17
17
18 "use strict";
18 "use strict";
19
19
20 // Use require.js 'define' method so that require.js is intelligent enough to
20 // Use require.js 'define' method so that require.js is intelligent enough to
21 // syncronously load everything within this file when it is being 'required'
21 // syncronously load everything within this file when it is being 'required'
22 // elsewhere.
22 // elsewhere.
23 define(["components/underscore/underscore-min",
23 define(["components/underscore/underscore-min",
24 "components/backbone/backbone-min",
24 "components/backbone/backbone-min",
25 ], function(){
25 ], function(){
26
26
27 // Only run once on a notebook.
27 // Only run once on a notebook.
28 if (IPython.notebook.widget_manager == undefined) {
28 if (IPython.notebook.widget_manager == undefined) {
29
29
30 //--------------------------------------------------------------------
30 //--------------------------------------------------------------------
31 // WidgetModel class
31 // WidgetModel class
32 //--------------------------------------------------------------------
32 //--------------------------------------------------------------------
33 var WidgetModel = Backbone.Model.extend({
33 var WidgetModel = Backbone.Model.extend({
34 constructor: function(comm_manager, comm, widget_view_types) {
34 constructor: function(comm_manager, comm, widget_view_types) {
35 this.comm_manager = comm_manager;
35 this.comm_manager = comm_manager;
36 this.widget_view_types = widget_view_types;
36 this.widget_view_types = widget_view_types;
37 this.pending_msgs = 0;
37 this.pending_msgs = 0;
38 this.msg_throttle = 3;
38 this.msg_throttle = 3;
39 this.msg_buffer = {};
39 this.msg_buffer = {};
40 this.views = {};
40 this.views = {};
41
41
42 // Remember comm associated with the model.
42 // Remember comm associated with the model.
43 this.comm = comm;
43 this.comm = comm;
44 comm.model = this;
44 comm.model = this;
45
45
46 // Hook comm messages up to model.
46 // Hook comm messages up to model.
47 comm.on_close($.proxy(this.handle_comm_closed, this));
47 comm.on_close($.proxy(this.handle_comm_closed, this));
48 comm.on_msg($.proxy(this.handle_comm_msg, this));
48 comm.on_msg($.proxy(this.handle_comm_msg, this));
49
49
50 return Backbone.Model.apply(this);
50 return Backbone.Model.apply(this);
51 },
51 },
52
52
53
53
54 update_other_views: function(caller) {
54 update_other_views: function(caller) {
55 this.last_modified_view = caller;
55 this.last_modified_view = caller;
56 this.save(this.changedAttributes(), {patch: true});
56 this.save(this.changedAttributes(), {patch: true});
57
57
58 for (var output_area in this.views) {
58 for (var output_area in this.views) {
59 var views = this.views[output_area];
59 var views = this.views[output_area];
60 for (var view_index in views) {
60 for (var view_index in views) {
61 var view = views[view_index];
61 var view = views[view_index];
62 if (view !== caller) {
62 if (view !== caller) {
63 view.update();
63 view.update();
64 }
64 }
65 }
65 }
66 }
66 }
67 },
67 },
68
68
69
69
70 handle_status: function (output_area, msg) {
70 handle_status: function (output_area, msg) {
71 //execution_state : ('busy', 'idle', 'starting')
71 //execution_state : ('busy', 'idle', 'starting')
72 if (msg.content.execution_state=='idle') {
72 if (msg.content.execution_state=='idle') {
73
73
74 // Send buffer if this message caused another message to be
74 // Send buffer if this message caused another message to be
75 // throttled.
75 // throttled.
76 if (this.msg_throttle == this.pending_msgs &&
76 if (this.msg_throttle == this.pending_msgs &&
77 this.msg_buffer.length > 0) {
77 this.msg_buffer.length > 0) {
78
78
79 var output_area = this._get_msg_output_area(msg);
79 var output_area = this._get_msg_output_area(msg);
80 var callbacks = this._make_callbacks(output_area);
80 var callbacks = this._make_callbacks(output_area);
81 var data = {sync_method: 'patch', sync_data: this.msg_buffer};
81 var data = {sync_method: 'patch', sync_data: this.msg_buffer};
82 comm.send(data, callbacks);
82 comm.send(data, callbacks);
83 this.msg_buffer = {};
83 this.msg_buffer = {};
84 } else {
84 } else {
85
85
86 // Only decrease the pending message count if the buffer
86 // Only decrease the pending message count if the buffer
87 // doesn't get flushed (sent).
87 // doesn't get flushed (sent).
88 --this.pending_msgs;
88 --this.pending_msgs;
89 }
89 }
90 }
90 }
91 },
91 },
92
92
93
93
94 // Custom syncronization logic.
94 // Custom syncronization logic.
95 handle_sync: function (method, options) {
95 handle_sync: function (method, options) {
96 var model_json = this.toJSON();
96 var model_json = this.toJSON();
97
97
98 // Only send updated state if the state hasn't been changed
98 // Only send updated state if the state hasn't been changed
99 // during an update.
99 // during an update.
100 if (!this.updating) {
100 if (!this.updating) {
101 if (this.pending_msgs >= this.msg_throttle) {
101 if (this.pending_msgs >= this.msg_throttle) {
102 // The throttle has been exceeded, buffer the current msg so
102 // The throttle has been exceeded, buffer the current msg so
103 // it can be sent once the kernel has finished processing
103 // it can be sent once the kernel has finished processing
104 // some of the existing messages.
104 // some of the existing messages.
105 if (method=='patch') {
105 if (method=='patch') {
106 for (var attr in options.attrs) {
106 for (var attr in options.attrs) {
107 this.msg_buffer[attr] = options.attrs[attr];
107 this.msg_buffer[attr] = options.attrs[attr];
108 }
108 }
109 } else {
109 } else {
110 this.msg_buffer = $.extend({}, model_json); // Copy
110 this.msg_buffer = $.extend({}, model_json); // Copy
111 }
111 }
112
112
113 } else {
113 } else {
114 // We haven't exceeded the throttle, send the message like
114 // We haven't exceeded the throttle, send the message like
115 // normal. If this is a patch operation, just send the
115 // normal. If this is a patch operation, just send the
116 // changes.
116 // changes.
117 var send_json = model_json;
117 var send_json = model_json;
118 if (method=='patch') {
118 if (method=='patch') {
119 send_json = {};
119 send_json = {};
120 for (var attr in options.attrs) {
120 for (var attr in options.attrs) {
121 send_json[attr] = options.attrs[attr];
121 send_json[attr] = options.attrs[attr];
122 }
122 }
123 }
123 }
124
124
125 var data = {sync_method: method, sync_data: send_json};
125 var data = {sync_method: method, sync_data: send_json};
126 var output_area = this.last_modified_view.output_area;
126 var output_area = this.last_modified_view.output_area;
127 var callbacks = this._make_callbacks(output_area);
127 var callbacks = this._make_callbacks(output_area);
128 this.comm.send(data, callbacks);
128 this.comm.send(data, callbacks);
129 this.pending_msgs++;
129 this.pending_msgs++;
130 }
130 }
131 }
131 }
132
132
133 // Since the comm is a one-way communication, assume the message
133 // Since the comm is a one-way communication, assume the message
134 // arrived.
134 // arrived.
135 return model_json;
135 return model_json;
136 },
136 },
137
137
138
138
139 // Handle incomming comm msg.
139 // Handle incomming comm msg.
140 handle_comm_msg: function (msg) {
140 handle_comm_msg: function (msg) {
141 var method = msg.content.data.method;
141 var method = msg.content.data.method;
142 switch (method){
142 switch (method){
143 case 'display':
143 case 'display':
144
144
145 // Try to get the cell index.
145 // Try to get the cell index.
146 var output_area = this._get_output_area(msg.parent_header.msg_id);
146 var output_area = this._get_output_area(msg.parent_header.msg_id);
147 if (output_area == null) {
147 if (output_area == null) {
148 console.log("Could not determine where the display" +
148 console.log("Could not determine where the display" +
149 " message was from. Widget will not be displayed")
149 " message was from. Widget will not be displayed")
150 } else {
150 } else {
151 this.display_view(msg.content.data.view_name,
151 this.display_view(msg.content.data.view_name,
152 msg.content.data.parent,
152 msg.content.data.parent,
153 output_area);
153 output_area);
154 }
154 }
155 break;
155 break;
156 case 'update':
156 case 'update':
157 this.handle_update(msg.content.data.state);
157 this.handle_update(msg.content.data.state);
158 break;
158 break;
159 }
159 }
160 },
160 },
161
161
162
162
163 // Handle when a widget is updated via the python side.
163 // Handle when a widget is updated via the python side.
164 handle_update: function (state) {
164 handle_update: function (state) {
165 this.updating = true;
165 this.updating = true;
166 try {
166 try {
167 for (var key in state) {
167 for (var key in state) {
168 if (state.hasOwnProperty(key)) {
168 if (state.hasOwnProperty(key)) {
169 if (key == "_css"){
169 if (key == "_css"){
170 this.css = state[key];
170 this.css = state[key];
171 } else {
171 } else {
172 this.set(key, state[key]);
172 this.set(key, state[key]);
173 }
173 }
174 }
174 }
175 }
175 }
176 this.id = this.comm.comm_id;
176 this.id = this.comm.comm_id;
177 this.save();
177 this.save();
178 } finally {
178 } finally {
179 this.updating = false;
179 this.updating = false;
180 }
180 }
181 },
181 },
182
182
183
183
184 // Handle when a widget is closed.
184 // Handle when a widget is closed.
185 handle_comm_closed: function (msg) {
185 handle_comm_closed: function (msg) {
186 for (var output_area in this.views) {
186 for (var output_area in this.views) {
187 var views = this.views[output_area];
187 var views = this.views[output_area];
188 for (var view_index in views) {
188 for (var view_index in views) {
189 var view = views[view_index];
189 var view = views[view_index];
190 view.remove();
190 view.remove();
191 }
191 }
192 }
192 }
193 },
193 },
194
194
195
195
196 // Create view that represents the model.
196 // Create view that represents the model.
197 display_view: function (view_name, parent_comm_id, output_area) {
197 display_view: function (view_name, parent_comm_id, output_area) {
198 var new_views = [];
198 var new_views = [];
199
199
200 var displayed = false;
200 var displayed = false;
201 if (parent_comm_id != undefined) {
201 if (parent_comm_id != undefined) {
202 var parent_comm = this.comm_manager.comms[parent_comm_id];
202 var parent_comm = this.comm_manager.comms[parent_comm_id];
203 var parent_model = parent_comm.model;
203 var parent_model = parent_comm.model;
204 var parent_views = parent_model.views[output_area];
204 var parent_views = parent_model.views[output_area];
205 for (var parent_view_index in parent_views) {
205 for (var parent_view_index in parent_views) {
206 var parent_view = parent_views[parent_view_index];
206 var parent_view = parent_views[parent_view_index];
207 if (parent_view.display_child != undefined) {
207 if (parent_view.display_child != undefined) {
208 var view = this._create_view(view_name, output_area);
208 var view = this._create_view(view_name, output_area);
209 new_views.push(view);
209 new_views.push(view);
210 parent_view.display_child(view);
210 parent_view.display_child(view);
211 displayed = true;
211 displayed = true;
212 }
212 }
213 }
213 }
214 }
214 }
215
215
216 if (!displayed) {
216 if (!displayed) {
217 // No parent view is defined or exists. Add the view's
217 // No parent view is defined or exists. Add the view's
218 // element to cell's widget div.
218 // element to cell's widget div.
219 var view = this._create_view(view_name, output_area);
219 var view = this._create_view(view_name, output_area);
220 new_views.push(view);
220 new_views.push(view);
221 output_area.element.find('.widget-area').find('.widget-subarea')
221 this._get_widget_area_element(output_area, true)
222 .append(view.$el)
222 .append(view.$el);
223 .parent().show(); // Show the widget_area (parent of widget_subarea)
224
223
225 }
224 }
226
225
227 for (var view_index in new_views) {
226 for (var view_index in new_views) {
228 var view = new_views[view_index];
227 var view = new_views[view_index];
229 view.update();
228 view.update();
230 }
229 }
231 },
230 },
232
231
233
232
234 // Create a view
233 // Create a view
235 _create_view: function (view_name, output_area) {
234 _create_view: function (view_name, output_area) {
236 var view = new this.widget_view_types[view_name]({model: this});
235 var view = new this.widget_view_types[view_name]({model: this});
237 view.render();
236 view.render();
238 if (this.views[output_area]==undefined) {
237 if (this.views[output_area]==undefined) {
239 this.views[output_area] = []
238 this.views[output_area] = []
240 }
239 }
241 this.views[output_area].push(view);
240 this.views[output_area].push(view);
242 view.output_area = output_area;
241 view.output_area = output_area;
243
242
244 // Handle when the view element is remove from the page.
243 // Handle when the view element is remove from the page.
245 var that = this;
244 var that = this;
246 view.$el.on("remove", function(){
245 view.$el.on("remove", function(){
247 var index = that.views[output_area].indexOf(view);
246 var index = that.views[output_area].indexOf(view);
248 if (index > -1) {
247 if (index > -1) {
249 that.views[output_area].splice(index, 1);
248 that.views[output_area].splice(index, 1);
250 }
249 }
251 view.remove(); // Clean-up view
250 view.remove(); // Clean-up view
252 if (that.views[output_area].length()==0) {
251 if (that.views[output_area].length()==0) {
253 delete that.views[output_area];
252 delete that.views[output_area];
254 }
253 }
255
254
256 // Close the comm if there are no views left.
255 // Close the comm if there are no views left.
257 if (that.views.length()==0) {
256 if (that.views.length()==0) {
258 that.comm.close();
257 that.comm.close();
259 }
258 }
260 });
259 });
261 return view;
260 return view;
262 },
261 },
263
262
264
263
265 // Build a callback dict.
264 // Build a callback dict.
266 _make_callbacks: function (output_area) {
265 _make_callbacks: function (output_area) {
267 var callbacks = {};
266 var callbacks = {};
268 if (output_area != null) {
267 if (output_area != null) {
269 var that = this;
268 var that = this;
270 callbacks = {
269 callbacks = {
271 iopub : {
270 iopub : {
272 output : $.proxy(output_area.handle_output, output_area),
271 output : $.proxy(output_area.handle_output, output_area),
273 clear_output : $.proxy(output_area.handle_clear_output, output_area),
272 clear_output : $.proxy(output_area.handle_clear_output, output_area),
274 status : function(msg){
273 status : function(msg){
275 that.handle_status(output_area, msg);
274 that.handle_status(output_area, msg);
276 },
275 },
277 get_output_area : function() {
276 get_output_area : function() {
278 if (that.last_modified_view != undefined &&
277 if (that.last_modified_view != undefined &&
279 that.last_modified_view.output_area != undefined) {
278 that.last_modified_view.output_area != undefined) {
280 return that.last_modified_view.output_area;
279 return that.last_modified_view.output_area;
281 } else {
280 } else {
282 return null
281 return null
283 }
282 }
284 },
283 },
285 },
284 },
286 };
285 };
287 }
286 }
288 return callbacks;
287 return callbacks;
289 },
288 },
290
289
291
290
292 // Get the cell index corresponding to the msg_id.
291 // Get the output area corresponding to the msg_id.
293 // output_area is a JQuery DOM element handle that has widget_area
292 // output_area is an instance of
294 // and nested widget_subarea elements.
295 _get_output_area: function (msg_id) {
293 _get_output_area: function (msg_id) {
296
294
297 // First, guess cell.execute triggered
295 // First, guess cell.execute triggered
298 var cells = IPython.notebook.get_cells();
296 var cells = IPython.notebook.get_cells();
299 for (var cell_index in cells) {
297 for (var cell_index in cells) {
300 if (cells[cell_index].last_msg_id == msg_id) {
298 if (cells[cell_index].last_msg_id == msg_id) {
301 var cell = IPython.notebook.get_cell(cell_index)
299 var cell = IPython.notebook.get_cell(cell_index)
302 return cell.output_area;
300 return cell.output_area;
303 }
301 }
304 }
302 }
305
303
306 // Second, guess widget triggered
304 // Second, guess widget triggered
307 var callbacks = this.comm_manager.kernel.get_callbacks_for_msg(msg_id)
305 var callbacks = this.comm_manager.kernel.get_callbacks_for_msg(msg_id)
308 if (callbacks != undefined && callbacks.iopub != undefined && callbacks.iopub.get_output_area != undefined) {
306 if (callbacks != undefined && callbacks.iopub != undefined && callbacks.iopub.get_output_area != undefined) {
309 var output_area = callbacks.iopub.get_output_area();
307 var output_area = callbacks.iopub.get_output_area();
310 if (output_area != null) {
308 if (output_area != null) {
311 return output_area;
309 return output_area;
312 }
310 }
313 }
311 }
314
312
315 // Not triggered by a widget or a cell
313 // Not triggered by a widget or a cell
316 return null;
314 return null;
317 },
315 },
318
316
317 // Gets widget output area (as a JQuery element) from the
318 // output_area (Ipython.OutputArea instance)
319 _get_widget_area_element: function (output_area, show) {
320 var widget_area = output_area.element
321 .parent() // output_wrapper
322 .parent() // cell
323 .find('.widget-area');
324 if (show) { widget_area.show(); }
325 return widget_area.find('.widget-subarea');
326 },
327
319 });
328 });
320
329
321
330
322 //--------------------------------------------------------------------
331 //--------------------------------------------------------------------
323 // WidgetView class
332 // WidgetView class
324 //--------------------------------------------------------------------
333 //--------------------------------------------------------------------
325 var WidgetView = Backbone.View.extend({
334 var WidgetView = Backbone.View.extend({
326
335
327 initialize: function() {
336 initialize: function() {
328 this.visible = true;
337 this.visible = true;
329 this.model.on('change',this.update,this);
338 this.model.on('change',this.update,this);
330 this._add_class_calls = this.model.get('_add_class')[0];
339 this._add_class_calls = this.model.get('_add_class')[0];
331 this._remove_class_calls = this.model.get('_remove_class')[0];
340 this._remove_class_calls = this.model.get('_remove_class')[0];
332 },
341 },
333
342
334 update: function() {
343 update: function() {
335 if (this.model.get('visible') != undefined) {
344 if (this.model.get('visible') != undefined) {
336 if (this.visible != this.model.get('visible')) {
345 if (this.visible != this.model.get('visible')) {
337 this.visible = this.model.get('visible');
346 this.visible = this.model.get('visible');
338 if (this.visible) {
347 if (this.visible) {
339 this.$el.show();
348 this.$el.show();
340 } else {
349 } else {
341 this.$el.hide();
350 this.$el.hide();
342 }
351 }
343 }
352 }
344 }
353 }
345
354
346 if (this.model.css != undefined) {
355 if (this.model.css != undefined) {
347 for (var selector in this.model.css) {
356 for (var selector in this.model.css) {
348 if (this.model.css.hasOwnProperty(selector)) {
357 if (this.model.css.hasOwnProperty(selector)) {
349
358
350 // Apply the css traits to all elements that match the selector.
359 // Apply the css traits to all elements that match the selector.
351 var elements = this.get_selector_element(selector);
360 var elements = this.get_selector_element(selector);
352 if (elements.length > 0) {
361 if (elements.length > 0) {
353 var css_traits = this.model.css[selector];
362 var css_traits = this.model.css[selector];
354 for (var css_key in css_traits) {
363 for (var css_key in css_traits) {
355 if (css_traits.hasOwnProperty(css_key)) {
364 if (css_traits.hasOwnProperty(css_key)) {
356 elements.css(css_key, css_traits[css_key]);
365 elements.css(css_key, css_traits[css_key]);
357 }
366 }
358 }
367 }
359 }
368 }
360 }
369 }
361 }
370 }
362 }
371 }
363
372
364 var add_class = this.model.get('_add_class');
373 var add_class = this.model.get('_add_class');
365 if (add_class != undefined){
374 if (add_class != undefined){
366 var add_class_calls = add_class[0];
375 var add_class_calls = add_class[0];
367 if (add_class_calls > this._add_class_calls) {
376 if (add_class_calls > this._add_class_calls) {
368 this._add_class_calls = add_class_calls;
377 this._add_class_calls = add_class_calls;
369 var elements = this.get_selector_element(add_class[1]);
378 var elements = this.get_selector_element(add_class[1]);
370 if (elements.length > 0) {
379 if (elements.length > 0) {
371 elements.addClass(add_class[2]);
380 elements.addClass(add_class[2]);
372 }
381 }
373 }
382 }
374 }
383 }
375
384
376 var remove_class = this.model.get('_remove_class');
385 var remove_class = this.model.get('_remove_class');
377 if (remove_class != undefined){
386 if (remove_class != undefined){
378 var remove_class_calls = remove_class[0];
387 var remove_class_calls = remove_class[0];
379 if (remove_class_calls > this._remove_class_calls) {
388 if (remove_class_calls > this._remove_class_calls) {
380 this._remove_class_calls = remove_class_calls;
389 this._remove_class_calls = remove_class_calls;
381 var elements = this.get_selector_element(remove_class[1]);
390 var elements = this.get_selector_element(remove_class[1]);
382 if (elements.length > 0) {
391 if (elements.length > 0) {
383 elements.removeClass(remove_class[2]);
392 elements.removeClass(remove_class[2]);
384 }
393 }
385 }
394 }
386 }
395 }
387 },
396 },
388
397
389 get_selector_element: function(selector) {
398 get_selector_element: function(selector) {
390 // Get the elements via the css selector. If the selector is
399 // Get the elements via the css selector. If the selector is
391 // blank, apply the style to the $el_to_style element. If
400 // blank, apply the style to the $el_to_style element. If
392 // the $el_to_style element is not defined, use apply the
401 // the $el_to_style element is not defined, use apply the
393 // style to the view's element.
402 // style to the view's element.
394 var elements = this.$el.find(selector);
403 var elements = this.$el.find(selector);
395 if (selector=='') {
404 if (selector=='') {
396 if (this.$el_to_style == undefined) {
405 if (this.$el_to_style == undefined) {
397 elements = this.$el;
406 elements = this.$el;
398 } else {
407 } else {
399 elements = this.$el_to_style;
408 elements = this.$el_to_style;
400 }
409 }
401 }
410 }
402 return elements;
411 return elements;
403 },
412 },
404 });
413 });
405
414
406
415
407 //--------------------------------------------------------------------
416 //--------------------------------------------------------------------
408 // WidgetManager class
417 // WidgetManager class
409 //--------------------------------------------------------------------
418 //--------------------------------------------------------------------
410 var WidgetManager = function(comm_manager){
419 var WidgetManager = function(comm_manager){
411 this.comm_manager = comm_manager;
420 this.comm_manager = comm_manager;
412 this.widget_model_types = {};
421 this.widget_model_types = {};
413 this.widget_view_types = {};
422 this.widget_view_types = {};
414
423
415 var that = this;
424 var that = this;
416 Backbone.sync = function(method, model, options, error) {
425 Backbone.sync = function(method, model, options, error) {
417 var result = model.handle_sync(method, options);
426 var result = model.handle_sync(method, options);
418 if (options.success) {
427 if (options.success) {
419 options.success(result);
428 options.success(result);
420 }
429 }
421 };
430 };
422 }
431 }
423
432
424
433
425 WidgetManager.prototype.register_widget_model = function (widget_model_name, widget_model_type) {
434 WidgetManager.prototype.register_widget_model = function (widget_model_name, widget_model_type) {
426 // Register the widget with the comm manager. Make sure to pass this object's context
435 // Register the widget with the comm manager. Make sure to pass this object's context
427 // in so `this` works in the call back.
436 // in so `this` works in the call back.
428 this.comm_manager.register_target(widget_model_name, $.proxy(this.handle_com_open, this));
437 this.comm_manager.register_target(widget_model_name, $.proxy(this.handle_com_open, this));
429 this.widget_model_types[widget_model_name] = widget_model_type;
438 this.widget_model_types[widget_model_name] = widget_model_type;
430 }
439 }
431
440
432
441
433 WidgetManager.prototype.register_widget_view = function (widget_view_name, widget_view_type) {
442 WidgetManager.prototype.register_widget_view = function (widget_view_name, widget_view_type) {
434 this.widget_view_types[widget_view_name] = widget_view_type;
443 this.widget_view_types[widget_view_name] = widget_view_type;
435 }
444 }
436
445
437
446
438 WidgetManager.prototype.handle_com_open = function (comm, msg) {
447 WidgetManager.prototype.handle_com_open = function (comm, msg) {
439 var widget_type_name = msg.content.target_name;
448 var widget_type_name = msg.content.target_name;
440 var widget_model = new this.widget_model_types[widget_type_name](this.comm_manager, comm, this.widget_view_types);
449 var widget_model = new this.widget_model_types[widget_type_name](this.comm_manager, comm, this.widget_view_types);
441 }
450 }
442
451
443
452
444 //--------------------------------------------------------------------
453 //--------------------------------------------------------------------
445 // Init code
454 // Init code
446 //--------------------------------------------------------------------
455 //--------------------------------------------------------------------
447 IPython.WidgetManager = WidgetManager;
456 IPython.WidgetManager = WidgetManager;
448 IPython.WidgetModel = WidgetModel;
457 IPython.WidgetModel = WidgetModel;
449 IPython.WidgetView = WidgetView;
458 IPython.WidgetView = WidgetView;
450
459
451 IPython.notebook.widget_manager = new WidgetManager(IPython.notebook.kernel.comm_manager);
460 IPython.notebook.widget_manager = new WidgetManager(IPython.notebook.kernel.comm_manager);
452
461
453 };
462 };
454 });
463 });
General Comments 0
You need to be logged in to leave comments. Login now