Show More
@@ -284,7 +284,8 b' define([' | |||||
284 | return this.create_model({ |
|
284 | return this.create_model({ | |
285 |
model_name: msg.content.data.model_name, |
|
285 | model_name: msg.content.data.model_name, | |
286 |
model_module: msg.content.data.model_module, |
|
286 | model_module: msg.content.data.model_module, | |
287 | comm: comm}).catch(utils.reject("Couldn't create a model.", true)); |
|
287 | comm: comm, | |
|
288 | }).catch(utils.reject("Couldn't create a model.", true)); | |||
288 | }; |
|
289 | }; | |
289 |
|
290 | |||
290 | WidgetManager.prototype.create_model = function (options) { |
|
291 | WidgetManager.prototype.create_model = function (options) { | |
@@ -299,7 +300,8 b' define([' | |||||
299 | * JS: |
|
300 | * JS: | |
300 | * IPython.notebook.kernel.widget_manager.create_model({ |
|
301 | * IPython.notebook.kernel.widget_manager.create_model({ | |
301 |
* model_name: 'WidgetModel', |
|
302 | * model_name: 'WidgetModel', | |
302 |
* widget_class: 'IPython.html.widgets.widget_int.IntSlider' |
|
303 | * widget_class: 'IPython.html.widgets.widget_int.IntSlider' | |
|
304 | * }) | |||
303 |
* |
|
305 | * .then(function(model) { console.log('Create success!', model); }, | |
304 |
* |
|
306 | * $.proxy(console.error, console)); | |
305 | * |
|
307 | * | |
@@ -416,13 +418,8 b' define([' | |||||
416 | var that = this; |
|
418 | var that = this; | |
417 | return this._get_connected_kernel().then(function(kernel) { |
|
419 | return this._get_connected_kernel().then(function(kernel) { | |
418 |
|
420 | |||
419 |
// Recreate all the widget models for the given |
|
421 | // Recreate all the widget models for the given notebook state. | |
420 | // display the views. |
|
422 | var all_models = Promise.all(_.map(Object.keys(state), function (model_id) { | |
421 | that.all_views = []; |
|
|||
422 | var model_ids = Object.keys(state); |
|
|||
423 | for (var i = 0; i < model_ids.length; i++) { |
|
|||
424 | var model_id = model_ids[i]; |
|
|||
425 |
|
||||
426 | // Recreate a comm using the widget's model id (model_id == comm_id). |
|
423 | // Recreate a comm using the widget's model id (model_id == comm_id). | |
427 | var new_comm = new comm.Comm(kernel.widget_manager.comm_target_name, model_id); |
|
424 | var new_comm = new comm.Comm(kernel.widget_manager.comm_target_name, model_id); | |
428 | kernel.comm_manager.register_comm(new_comm); |
|
425 | kernel.comm_manager.register_comm(new_comm); | |
@@ -431,35 +428,30 b' define([' | |||||
431 | // created we don't know yet if the comm is valid so set_comm_live |
|
428 | // created we don't know yet if the comm is valid so set_comm_live | |
432 | // false. Once we receive the first state push from the back-end |
|
429 | // false. Once we receive the first state push from the back-end | |
433 | // we know the comm is alive. |
|
430 | // we know the comm is alive. | |
434 |
|
|
431 | return kernel.widget_manager.create_model({ | |
435 |
comm: new_comm, |
|
432 | comm: new_comm, | |
436 |
model_name: state[model_id].model_name, |
|
433 | model_name: state[model_id].model_name, | |
437 |
model_module: state[model_id].model_module |
|
434 | model_module: state[model_id].model_module, | |
438 | .then(function(model) { |
|
435 | }).then(function(model) { | |
439 |
|
||||
440 | model.set_comm_live(false); |
|
436 | model.set_comm_live(false); | |
441 | var view_promise = Promise.resolve().then(function() { |
|
437 | model.set_state(state[model.id].state); | |
442 |
|
|
438 | return model.request_state().then(function() { | |
443 | }).then(function() { |
|
|||
444 | model.request_state().then(function() { |
|
|||
445 |
|
|
439 | model.set_comm_live(true); | |
|
440 | return model; | |||
446 |
|
|
441 | }); | |
|
442 | }); | |||
|
443 | }, this)); | |||
447 |
|
444 | |||
|
445 | // Display all the views | |||
|
446 | return all_models.then(function(models) { | |||
|
447 | return Promise.all(_.map(models, function(model) { | |||
448 |
|
|
448 | // Display the views of the model. | |
449 | var views = []; |
|
449 | return Promise.all(_.map(state[model.id].views, function(cell_index) { | |
450 | var model_views = state[model.id].views; |
|
|||
451 | for (var j=0; j<model_views.length; j++) { |
|
|||
452 | var cell_index = model_views[j]; |
|
|||
453 |
|
|
450 | var cell = that.notebook.get_cell(cell_index); | |
454 |
|
|
451 | return that.display_view_in_cell(cell, model); | |
455 |
|
|
452 | })); | |
456 | return Promise.all(views); |
|
453 | })); | |
457 | }); |
|
|||
458 | return view_promise; |
|
|||
459 |
|
|
454 | }); | |
460 | that.all_views.push(views); |
|
|||
461 | } |
|
|||
462 | return Promise.all(that.all_views); |
|
|||
463 |
}).catch(utils.reject('Could not set widget manager state.', true)); |
|
455 | }).catch(utils.reject('Could not set widget manager state.', true)); | |
464 | }; |
|
456 | }; | |
465 |
|
457 |
General Comments 0
You need to be logged in to leave comments.
Login now