Show More
@@ -193,7 +193,7 define([ | |||||
193 | WidgetManager.prototype.create_model = function (options) { |
|
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 |
// Minimally, one must provide the model_name and |
|
196 | // Minimally, one must provide the model_name and widget_class | |
197 | // parameters to create a model from Javascript. |
|
197 | // parameters to create a model from Javascript. | |
198 | // |
|
198 | // | |
199 | // Example |
|
199 | // Example | |
@@ -201,7 +201,7 define([ | |||||
201 | // JS: |
|
201 | // JS: | |
202 | // window.slider = IPython.notebook.kernel.widget_manager.create_model({ |
|
202 | // window.slider = IPython.notebook.kernel.widget_manager.create_model({ | |
203 | // model_name: 'WidgetModel', |
|
203 | // model_name: 'WidgetModel', | |
204 |
// |
|
204 | // widget_class: 'IPython.html.widgets.widget_int.IntSlider', | |
205 | // init_state_callback: function(model) { console.log('Create success!', model); }}); |
|
205 | // init_state_callback: function(model) { console.log('Create success!', model); }}); | |
206 | // |
|
206 | // | |
207 | // Parameters |
|
207 | // Parameters | |
@@ -210,7 +210,7 define([ | |||||
210 | // Dictionary of options with the following contents: |
|
210 | // Dictionary of options with the following contents: | |
211 | // model_name: string |
|
211 | // model_name: string | |
212 | // Target name of the widget model to create. |
|
212 | // Target name of the widget model to create. | |
213 |
// |
|
213 | // widget_class: (optional) string | |
214 | // Target name of the widget in the back-end. |
|
214 | // Target name of the widget in the back-end. | |
215 | // comm: (optional) Comm |
|
215 | // comm: (optional) Comm | |
216 | // init_state_callback: (optional) callback |
|
216 | // init_state_callback: (optional) callback | |
@@ -221,7 +221,7 define([ | |||||
221 | // Create a comm if it wasn't provided. |
|
221 | // Create a comm if it wasn't provided. | |
222 | var comm = options.comm; |
|
222 | var comm = options.comm; | |
223 | if (!comm) { |
|
223 | if (!comm) { | |
224 |
comm = this.comm_manager.new_comm('ipython.widget', {' |
|
224 | comm = this.comm_manager.new_comm('ipython.widget', {'widget_class': options.widget_class}); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | // Create and return a new model that is connected to the comm. |
|
227 | // Create and return a new model that is connected to the comm. |
@@ -99,8 +99,7 class Widget(LoggingConfigurable): | |||||
99 | @staticmethod |
|
99 | @staticmethod | |
100 | def handle_comm_opened(comm, msg): |
|
100 | def handle_comm_opened(comm, msg): | |
101 | """Static method, called when a widget is constructed.""" |
|
101 | """Static method, called when a widget is constructed.""" | |
102 |
|
|
102 | widget_class = import_item(msg['content']['data']['widget_class']) | |
103 | widget_class = import_item(target_name) |
|
|||
104 | widget = widget_class(comm=comm) |
|
103 | widget = widget_class(comm=comm) | |
105 |
|
104 | |||
106 |
|
105 |
General Comments 0
You need to be logged in to leave comments.
Login now