##// END OF EJS Templates
fix js/Python WidgetManager symmetry...
MinRK -
Show More
@@ -6,10 +6,10 b''
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // Cell
9 // Widget and WidgetManager bases
10 //============================================================================
10 //============================================================================
11 /**
11 /**
12 * An extendable module that provide base functionnality to create cell for notebook.
12 * Base Widget classes
13 * @module IPython
13 * @module IPython
14 * @namespace IPython
14 * @namespace IPython
15 * @submodule widget
15 * @submodule widget
@@ -35,7 +35,7 b' var IPython = (function (IPython) {'
35 var msg_types = ['widget_create', 'widget_destroy', 'widget_update'];
35 var msg_types = ['widget_create', 'widget_destroy', 'widget_update'];
36 for (var i = 0; i < msg_types.length; i++) {
36 for (var i = 0; i < msg_types.length; i++) {
37 var msg_type = msg_types[i];
37 var msg_type = msg_types[i];
38 kernel.register_iopub_handler(msg_type, $.proxy(this['handle_' + msg_type], this));
38 kernel.register_iopub_handler(msg_type, $.proxy(this[msg_type], this));
39 }
39 }
40 };
40 };
41
41
@@ -44,10 +44,8 b' var IPython = (function (IPython) {'
44 this.widget_types[widget_type] = constructor;
44 this.widget_types[widget_type] = constructor;
45 };
45 };
46
46
47 WidgetManager.prototype.handle_widget_create = function (msg) {
47 WidgetManager.prototype.widget_create = function (msg) {
48 var content = msg.content;
48 var content = msg.content;
49 console.log("handle create", content);
50 console.log(this.widget_types);
51 var constructor = this.widget_types[content.widget_type];
49 var constructor = this.widget_types[content.widget_type];
52 if (constructor === undefined) {
50 if (constructor === undefined) {
53 console.log("No such widget type registered: ", content.widget_type);
51 console.log("No such widget type registered: ", content.widget_type);
@@ -58,9 +56,8 b' var IPython = (function (IPython) {'
58 this.widgets[content.widget_id] = widget;
56 this.widgets[content.widget_id] = widget;
59 };
57 };
60
58
61 WidgetManager.prototype.handle_widget_destroy = function (msg) {
59 WidgetManager.prototype.widget_destroy = function (msg) {
62 var content = msg.content;
60 var content = msg.content;
63 console.log("handle destroy", content);
64 var widget = this.widgets[content.widget_id];
61 var widget = this.widgets[content.widget_id];
65 if (widget === undefined) {
62 if (widget === undefined) {
66 return;
63 return;
@@ -69,9 +66,8 b' var IPython = (function (IPython) {'
69 widget.handle_destroy(content.data);
66 widget.handle_destroy(content.data);
70 };
67 };
71
68
72 WidgetManager.prototype.handle_widget_update = function (msg) {
69 WidgetManager.prototype.widget_update = function (msg) {
73 var content = msg.content;
70 var content = msg.content;
74 console.log("handle update", content);
75 var widget = this.widgets[content.widget_id];
71 var widget = this.widgets[content.widget_id];
76 if (widget === undefined) {
72 if (widget === undefined) {
77 return;
73 return;
@@ -84,27 +80,22 b' var IPython = (function (IPython) {'
84 //-----------------------------------------------------------------------
80 //-----------------------------------------------------------------------
85
81
86 var Widget = function (kernel, content) {
82 var Widget = function (kernel, content) {
87 console.log('widget!', this, kernel, content);
88 this.kernel = kernel;
83 this.kernel = kernel;
84 if (!content) return;
89 this.widget_id = content.widget_id;
85 this.widget_id = content.widget_id;
90 this.handle_create(content.data);
86 this.handle_create(content.data);
91 };
87 };
92
88
93 Widget.prototype.handle_create = function (data) {
89 Widget.prototype.handle_create = function (data) {
94 // base class init does nothing
95 console.log("handle_create", this, data);
96 };
90 };
97
91
98 Widget.prototype.handle_update = function (data) {
92 Widget.prototype.handle_update = function (data) {
99 console.log("handle_update", this, data);
100 };
93 };
101
94
102 Widget.prototype.handle_destroy = function (data) {
95 Widget.prototype.handle_destroy = function (data) {
103 console.log("handle_destroy", this, data);
104 };
96 };
105
97
106 Widget.prototype.update = function (data) {
98 Widget.prototype.update = function (data) {
107 console.log("update", this, data);
108 var content = {
99 var content = {
109 widget_id : this.widget_id,
100 widget_id : this.widget_id,
110 data : data,
101 data : data,
@@ -114,7 +105,6 b' var IPython = (function (IPython) {'
114
105
115
106
116 Widget.prototype.destroy = function (data) {
107 Widget.prototype.destroy = function (data) {
117 console.log("destroy", this, data);
118 var content = {
108 var content = {
119 widget_id : this.widget_id,
109 widget_id : this.widget_id,
120 data : data,
110 data : data,
General Comments 0
You need to be logged in to leave comments. Login now