Show More
@@ -0,0 +1,36 | |||
|
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 define([ | |||
|
187 | 187 | |
|
188 | 188 | WidgetManager.prototype._handle_comm_open = function (comm, msg) { |
|
189 | 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 | 194 | // Create and return a new widget model. |
|
195 | 195 | // |
|
196 | // Parameters | |
|
197 | // ---------- | |
|
198 | // model_name: string | |
|
199 | // Target name of the widget model to create. | |
|
200 | // target_name: string | |
|
201 | // Target name of the widget in the back-end. | |
|
202 | // init_state_callback: (optional) callback | |
|
203 | // Called when the first state push from the back-end is | |
|
204 | // recieved. | |
|
205 | return this._create_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. | |
|
196 | // Minimally, one must provide the model_name and target_name | |
|
197 | // parameters to create a model from Javascript. | |
|
198 | // | |
|
199 | // Example | |
|
200 | // -------- | |
|
201 | // JS: | |
|
202 | // window.slider = IPython.notebook.kernel.widget_manager.create_model({ | |
|
203 | // model_name: 'WidgetModel', | |
|
204 | // target_name: 'IPython.html.widgets.widget_int.IntSlider', | |
|
205 | // init_state_callback: function(model) { console.log('Create success!', model); }}); | |
|
213 | 206 | // |
|
214 | 207 | // Parameters |
|
215 | 208 | // ---------- |
@@ -222,7 +215,8 define([ | |||
|
222 | 215 | // comm: (optional) Comm |
|
223 | 216 | // init_state_callback: (optional) callback |
|
224 | 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 | 221 | // Create a comm if it wasn't provided. |
|
228 | 222 | var comm = options.comm; |
@@ -38,14 +38,6 var recursive_compare = function(a, b) { | |||
|
38 | 38 | // Test the widget framework. |
|
39 | 39 | casper.notebook_test(function () { |
|
40 | 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 | 42 | index = this.append_cell( |
|
51 | 43 | 'from IPython.html import widgets\n' + |
@@ -54,10 +46,6 casper.notebook_test(function () { | |||
|
54 | 46 | this.execute_cell_then(index); |
|
55 | 47 | |
|
56 | 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 | 50 | // Functions that can be used to test the packing and unpacking APIs |
|
63 | 51 | var that = this; |
General Comments 0
You need to be logged in to leave comments.
Login now