Show More
@@ -66,37 +66,37 b'' | |||||
66 | WidgetManager.prototype.register_widget_view = function (widget_view_name, widget_view_type) { |
|
66 | WidgetManager.prototype.register_widget_view = function (widget_view_name, widget_view_type) { | |
67 | this.widget_view_types[widget_view_name] = widget_view_type; |
|
67 | this.widget_view_types[widget_view_name] = widget_view_type; | |
68 | }; |
|
68 | }; | |
69 |
|
|
69 | WidgetManager.prototype.handle_msg = function(msg, model) { | |
70 |
|
|
70 | var method = msg.content.data.method; | |
71 |
|
|
71 | switch (method) { | |
72 |
|
|
72 | case 'display': | |
73 |
|
|
73 | var cell = this.get_msg_cell(msg.parent_header.msg_id); | |
74 |
|
|
74 | if (cell === null) { | |
75 |
|
|
75 | console.log("Could not determine where the display" + | |
76 |
|
|
76 | " message was from. Widget will not be displayed"); | |
77 |
|
|
77 | } else { | |
78 |
|
|
78 | var view = this.create_view(model, | |
79 |
|
|
79 | msg.content.data.view_name, cell); | |
80 |
|
|
80 | if (view !== undefined | |
81 |
|
|
81 | && cell.widget_subarea !== undefined | |
82 |
|
|
82 | && cell.widget_subarea !== null) { | |
83 | cell.widget_area.show(); |
|
83 | cell.widget_area.show(); | |
84 | cell.widget_subarea.append(view.$el); |
|
84 | cell.widget_subarea.append(view.$el); | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 |
|
|
87 | break; | |
88 |
|
|
88 | } | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 |
|
|
91 | WidgetManager.prototype.create_view = function(model, view_name, cell) { | |
92 |
|
|
92 | view_name = view_name || model.get('default_view_name'); | |
93 | var ViewType = this.widget_view_types[view_name]; |
|
93 | var ViewType = this.widget_view_types[view_name]; | |
94 | if (ViewType !== undefined && ViewType !== null) { |
|
94 | if (ViewType !== undefined && ViewType !== null) { | |
95 | var view = new ViewType({model: model, widget_manager: this, cell: cell}); |
|
95 | var view = new ViewType({model: model, widget_manager: this, cell: cell}); | |
96 | view.render(); |
|
96 | view.render(); | |
97 |
|
|
97 | model.views.push(view); | |
98 |
|
|
98 | model.on('destroy', view.remove, view); | |
99 | /* |
|
99 | /* | |
100 | // TODO: handle view deletion. Don't forget to delete child views |
|
100 | // TODO: handle view deletion. Don't forget to delete child views | |
101 | var that = this; |
|
101 | var that = this; | |
102 | view.$el.on("remove", function () { |
|
102 | view.$el.on("remove", function () { | |
@@ -108,10 +108,10 b'' | |||||
108 |
|
108 | |||
109 | // Close the comm if there are no views left. |
|
109 | // Close the comm if there are no views left. | |
110 | if (that.views.length() === 0) { |
|
110 | if (that.views.length() === 0) { | |
111 |
|
|
111 | //trigger comm close event? | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 |
|
|
114 | ||
115 | if (that.comm !== undefined) { |
|
115 | if (that.comm !== undefined) { | |
116 | that.comm.close(); |
|
116 | that.comm.close(); | |
117 | delete that.comm.model; // Delete ref so GC will collect widget model. |
|
117 | delete that.comm.model; // Delete ref so GC will collect widget model. | |
@@ -119,20 +119,20 b'' | |||||
119 | } |
|
119 | } | |
120 | delete that.widget_id; // Delete id from model so widget manager cleans up. |
|
120 | delete that.widget_id; // Delete id from model so widget manager cleans up. | |
121 | }); |
|
121 | }); | |
122 | */ |
|
122 | */ | |
123 | return view; |
|
123 | return view; | |
124 | } |
|
124 | } | |
125 | }, |
|
125 | }, | |
126 |
|
126 | |||
127 | WidgetManager.prototype.get_msg_cell = function (msg_id) { |
|
127 | WidgetManager.prototype.get_msg_cell = function (msg_id) { | |
128 |
|
|
128 | var cell = null; | |
129 | // First, check to see if the msg was triggered by cell execution. |
|
129 | // First, check to see if the msg was triggered by cell execution. | |
130 | if (IPython.notebook !== undefined && IPython.notebook !== null) { |
|
130 | if (IPython.notebook !== undefined && IPython.notebook !== null) { | |
131 | cell = IPython.notebook.get_msg_cell(msg_id); |
|
131 | cell = IPython.notebook.get_msg_cell(msg_id); | |
132 | } |
|
132 | } | |
133 |
|
|
133 | if (cell !== null) { | |
134 |
|
|
134 | return cell | |
135 |
|
|
135 | } | |
136 | // Second, check to see if a get_cell callback was defined |
|
136 | // Second, check to see if a get_cell callback was defined | |
137 | // for the message. get_cell callbacks are registered for |
|
137 | // for the message. get_cell callbacks are registered for | |
138 | // widget messages, so this block is actually checking to see if the |
|
138 | // widget messages, so this block is actually checking to see if the |
@@ -292,7 +292,7 b' function(widget_manager, underscore, backbone){' | |||||
292 | elements.removeClass(class_list); |
|
292 | elements.removeClass(class_list); | |
293 | } |
|
293 | } | |
294 | }, |
|
294 | }, | |
295 |
|
295 | |||
296 | update: function () { |
|
296 | update: function () { | |
297 | // the very first update seems to happen before the element is finished rendering |
|
297 | // the very first update seems to happen before the element is finished rendering | |
298 | // so we use setTimeout to give the element time to render |
|
298 | // so we use setTimeout to give the element time to render |
@@ -119,10 +119,10 b' define(["notebook/js/widgets/base"], function(widget_manager){' | |||||
119 |
|
119 | |||
120 | var TabView = IPython.WidgetView.extend({ |
|
120 | var TabView = IPython.WidgetView.extend({ | |
121 |
|
121 | |||
122 |
|
|
122 | initialize: function() { | |
123 |
|
|
123 | this.containers = []; | |
124 |
|
|
124 | IPython.WidgetView.prototype.initialize.apply(this, arguments); | |
125 | }, |
|
125 | }, | |
126 |
|
126 | |||
127 | render: function(){ |
|
127 | render: function(){ | |
128 | var uuid = 'tabs'+IPython.utils.uuid(); |
|
128 | var uuid = 'tabs'+IPython.utils.uuid(); | |
@@ -134,11 +134,11 b' define(["notebook/js/widgets/base"], function(widget_manager){' | |||||
134 | this.$tab_contents = $('<div />', {id: uuid + 'Content'}) |
|
134 | this.$tab_contents = $('<div />', {id: uuid + 'Content'}) | |
135 | .addClass('tab-content') |
|
135 | .addClass('tab-content') | |
136 | .appendTo(this.$el); |
|
136 | .appendTo(this.$el); | |
137 |
|
|
137 | var children = this.model.get('children'); | |
138 |
|
|
138 | for (var i in children) { | |
139 |
|
|
139 | this.add_child_view(this.child_view(children[i])) | |
140 |
|
|
140 | } | |
141 |
|
|
141 | this.update(); | |
142 | }, |
|
142 | }, | |
143 |
|
143 | |||
144 | update: function() { |
|
144 | update: function() { |
General Comments 0
You need to be logged in to leave comments.
Login now