##// END OF EJS Templates
Finished changing output widget logic.
Jonathan Frederic -
Show More
@@ -110,6 +110,7 b' define(['
110
110
111 // Attributes we want to override in this subclass.
111 // Attributes we want to override in this subclass.
112 this.cell_type = "code";
112 this.cell_type = "code";
113 var that = this;
113 this.element.focusout(
114 this.element.focusout(
114 function() { that.auto_highlight(); }
115 function() { that.auto_highlight(); }
115 );
116 );
@@ -212,11 +212,9 b' define(['
212 json.name = content.name;
212 json.name = content.name;
213 } else if (msg_type === "display_data") {
213 } else if (msg_type === "display_data") {
214 json.data = content.data;
214 json.data = content.data;
215 json.output_type = msg_type;
216 json.metadata = content.metadata;
215 json.metadata = content.metadata;
217 } else if (msg_type === "execute_result") {
216 } else if (msg_type === "execute_result") {
218 json.data = content.data;
217 json.data = content.data;
219 json.output_type = msg_type;
220 json.metadata = content.metadata;
218 json.metadata = content.metadata;
221 json.execution_count = content.execution_count;
219 json.execution_count = content.execution_count;
222 } else if (msg_type === "error") {
220 } else if (msg_type === "error") {
@@ -9,18 +9,18 b' define(['
9 'use strict';
9 'use strict';
10
10
11 var OutputView = widget.DOMWidgetView.extend({
11 var OutputView = widget.DOMWidgetView.extend({
12 initialize: function (parameters) {
13 /**
12 /**
14 * Public constructor
13 * Public constructor
15 */
14 */
15 initialize: function (parameters) {
16 OutputView.__super__.initialize.apply(this, [parameters]);
16 OutputView.__super__.initialize.apply(this, [parameters]);
17 this.model.on('msg:custom', this._handle_route_msg, this);
17 this.model.on('msg:custom', this._handle_route_msg, this);
18 },
18 },
19
19
20 render: function(){
21 /**
20 /**
22 * Called when view is rendered.
21 * Called when view is rendered.
23 */
22 */
23 render: function(){
24 this.output_area = new outputarea.OutputArea({
24 this.output_area = new outputarea.OutputArea({
25 selector: this.$el,
25 selector: this.$el,
26 prompt_area: false,
26 prompt_area: false,
@@ -43,32 +43,33 b' define(['
43 this.output_area.element.html(this.model.get('contents'));
43 this.output_area.element.html(this.model.get('contents'));
44 },
44 },
45
45
46 /**
47 * Handles re-routed iopub messages.
48 */
46 _handle_route_msg: function(content) {
49 _handle_route_msg: function(content) {
47 if (content) {
50 if (content) {
48 // return {
51 var msg_type = content.type;
49 // shell : {
52 var json = {
50 // reply : $.proxy(this._handle_execute_reply, this),
53 output_type: msg_type
51 // payload : {
54 };
52 // set_next_input : $.proxy(this._handle_set_next_input, this),
55
53 // page : $.proxy(this._open_with_pager, this)
56 var data = content.args[0];
54 // }
57 if (msg_type=='clear_output') {
55 // },
58 this.output_area.clear_output(data.wait || false);
56 // iopub : {
59 return;
57 // output : function() {
60 } else if (msg_type === "stream") {
58 // that.output_area.handle_output.apply(that.output_area, arguments);
61 data = content.kwargs.content;
59 // },
62 json.text = data.text;
60 // clear_output : function() {
63 json.name = data.name;
61 // that.output_area.handle_clear_output.apply(that.output_area, arguments);
64 } else if (msg_type === "display_data") {
62 // },
65 json.data = data.data;
63 // },
66 json.metadata = data.metadata;
64 // input : $.proxy(this._handle_input_request, this)
67 } else {
65 // };
68 console.log("unhandled output message", msg);
66 // };
69 return;
67 if (content.method == 'push') {
68 cell.push_output_area(this.output_area);
69 } else if (content.method == 'pop') {
70 cell.pop_output_area(this.output_area);
71 }
70 }
71
72 this.output_area.append_output(json);
72 }
73 }
73 },
74 },
74 });
75 });
@@ -38,13 +38,30 b' class Output(DOMWidget):'
38 clear_output(*pargs, **kwargs)
38 clear_output(*pargs, **kwargs)
39
39
40 def __enter__(self):
40 def __enter__(self):
41 """Called upon entering output widget context manager."""
41 self._flush()
42 self._flush()
42 self.send({'method': 'push'})
43 kernel = get_ipython().kernel
44 session = kernel.session
45 send = session.send
46 self._original_send = send
47 self._session = session
48
49 def send_hook(stream, msg_or_type, *args, **kwargs):
50 if stream is kernel.iopub_socket and msg_or_type in ['clear_output', 'stream', 'display_data']:
51 msg = {'type': msg_or_type, 'args': args, 'kwargs': kwargs}
52 self.send(msg)
53 else:
54 send(stream, msg_or_type, *args, **kwargs)
55 return
56
57 session.send = send_hook
43
58
44 def __exit__(self, exception_type, exception_value, traceback):
59 def __exit__(self, exception_type, exception_value, traceback):
60 """Called upon exiting output widget context manager."""
45 self._flush()
61 self._flush()
46 self.send({'method': 'pop'})
62 self._session.send = self._original_send
47
63
48 def _flush(self):
64 def _flush(self):
65 """Flush stdout and stderr buffers."""
49 sys.stdout.flush()
66 sys.stdout.flush()
50 sys.stderr.flush()
67 sys.stderr.flush()
General Comments 0
You need to be logged in to leave comments. Login now