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