Show More
@@ -0,0 +1,36 b'' | |||||
|
1 | // Test the widget manager. | |||
|
2 | casper.notebook_test(function () { | |||
|
3 | var index; | |||
|
4 | var slider = {}; | |||
|
5 | ||||
|
6 | this.then(function () { | |||
|
7 | ||||
|
8 | // Check if the WidgetManager class is defined. | |||
|
9 | this.test.assert(this.evaluate(function() { | |||
|
10 | return IPython.WidgetManager !== undefined; | |||
|
11 | }), 'WidgetManager class is defined'); | |||
|
12 | ||||
|
13 | // Check if the widget manager has been instantiated. | |||
|
14 | this.test.assert(this.evaluate(function() { | |||
|
15 | return IPython.notebook.kernel.widget_manager !== undefined; | |||
|
16 | }), 'Notebook widget manager instantiated'); | |||
|
17 | ||||
|
18 | // Try creating a widget from Javascript. | |||
|
19 | slider.id = this.evaluate(function() { | |||
|
20 | var slider = IPython.notebook.kernel.widget_manager.create_model({ | |||
|
21 | model_name: 'WidgetModel', | |||
|
22 | target_name: 'IPython.html.widgets.widget_int.IntSlider', | |||
|
23 | init_state_callback: function(model) { console.log('Create success!', model); }}); | |||
|
24 | return slider.id; | |||
|
25 | }); | |||
|
26 | }); | |||
|
27 | ||||
|
28 | index = this.append_cell( | |||
|
29 | 'from IPython.html.widgets import Widget\n' + | |||
|
30 | 'widget = Widget.widgets.values()[0]\n' + | |||
|
31 | 'print(widget.model_id)'); | |||
|
32 | this.execute_cell_then(index, function(index) { | |||
|
33 | var output = this.get_output_cell(index).text.trim(); | |||
|
34 | this.test.assertEquals(output, slider.id, "Widget created from the front-end."); | |||
|
35 | }); | |||
|
36 | }); |
@@ -187,29 +187,22 b' define([' | |||||
187 |
|
187 | |||
188 | WidgetManager.prototype._handle_comm_open = function (comm, msg) { |
|
188 | WidgetManager.prototype._handle_comm_open = function (comm, msg) { | |
189 | // Handle when a comm is opened. |
|
189 | // Handle when a comm is opened. | |
190 |
return this. |
|
190 | return this.create_model({model_name: msg.content.data.model_name, comm: comm}); | |
191 | }; |
|
191 | }; | |
192 |
|
192 | |||
193 |
WidgetManager.prototype.create_model = function ( |
|
193 | WidgetManager.prototype.create_model = function (options) { | |
194 | // Create and return a new widget model. |
|
194 | // Create and return a new widget model. | |
195 | // |
|
195 | // | |
196 | // Parameters |
|
196 | // Minimally, one must provide the model_name and target_name | |
197 | // ---------- |
|
197 | // parameters to create a model from Javascript. | |
198 | // model_name: string |
|
198 | // | |
199 | // Target name of the widget model to create. |
|
199 | // Example | |
200 | // target_name: string |
|
200 | // -------- | |
201 | // Target name of the widget in the back-end. |
|
201 | // JS: | |
202 | // init_state_callback: (optional) callback |
|
202 | // window.slider = IPython.notebook.kernel.widget_manager.create_model({ | |
203 | // Called when the first state push from the back-end is |
|
203 | // model_name: 'WidgetModel', | |
204 | // recieved. |
|
204 | // target_name: 'IPython.html.widgets.widget_int.IntSlider', | |
205 | return this._create_model({ |
|
205 | // init_state_callback: function(model) { console.log('Create success!', model); }}); | |
206 | model_name: model_name, |
|
|||
207 | target_name: target_name, |
|
|||
208 | init_state_callback: init_state_callback}); |
|
|||
209 | }; |
|
|||
210 |
|
||||
211 | WidgetManager.prototype._create_model = function (options) { |
|
|||
212 | // Create and return a new widget model. |
|
|||
213 | // |
|
206 | // | |
214 | // Parameters |
|
207 | // Parameters | |
215 | // ---------- |
|
208 | // ---------- | |
@@ -222,7 +215,8 b' define([' | |||||
222 | // comm: (optional) Comm |
|
215 | // comm: (optional) Comm | |
223 | // init_state_callback: (optional) callback |
|
216 | // init_state_callback: (optional) callback | |
224 | // Called when the first state push from the back-end is |
|
217 | // Called when the first state push from the back-end is | |
225 | // recieved. |
|
218 | // recieved. Allows you to modify the model after it's | |
|
219 | // complete state is filled and synced. | |||
226 |
|
220 | |||
227 | // Create a comm if it wasn't provided. |
|
221 | // Create a comm if it wasn't provided. | |
228 | var comm = options.comm; |
|
222 | var comm = options.comm; |
@@ -38,14 +38,6 b' var recursive_compare = function(a, b) {' | |||||
38 | // Test the widget framework. |
|
38 | // Test the widget framework. | |
39 | casper.notebook_test(function () { |
|
39 | casper.notebook_test(function () { | |
40 | var index; |
|
40 | var index; | |
41 |
|
||||
42 | this.then(function () { |
|
|||
43 |
|
||||
44 | // Check if the WidgetManager class is defined. |
|
|||
45 | this.test.assert(this.evaluate(function() { |
|
|||
46 | return IPython.WidgetManager !== undefined; |
|
|||
47 | }), 'WidgetManager class is defined'); |
|
|||
48 | }); |
|
|||
49 |
|
41 | |||
50 | index = this.append_cell( |
|
42 | index = this.append_cell( | |
51 | 'from IPython.html import widgets\n' + |
|
43 | 'from IPython.html import widgets\n' + | |
@@ -54,10 +46,6 b' casper.notebook_test(function () {' | |||||
54 | this.execute_cell_then(index); |
|
46 | this.execute_cell_then(index); | |
55 |
|
47 | |||
56 | this.then(function () { |
|
48 | this.then(function () { | |
57 | // Check if the widget manager has been instantiated. |
|
|||
58 | this.test.assert(this.evaluate(function() { |
|
|||
59 | return IPython.notebook.kernel.widget_manager !== undefined; |
|
|||
60 | }), 'Notebook widget manager instantiated'); |
|
|||
61 |
|
49 | |||
62 | // Functions that can be used to test the packing and unpacking APIs |
|
50 | // Functions that can be used to test the packing and unpacking APIs | |
63 | var that = this; |
|
51 | var that = this; |
General Comments 0
You need to be logged in to leave comments.
Login now