Show More
@@ -97,22 +97,6 b' define([' | |||||
97 | this.input_prompt_number = null; |
|
97 | this.input_prompt_number = null; | |
98 | this.celltoolbar = null; |
|
98 | this.celltoolbar = null; | |
99 | this.output_area = null; |
|
99 | this.output_area = null; | |
100 | // Keep a stack of the 'active' output areas (where active means the |
|
|||
101 | // output area that recieves output). When a user activates an output |
|
|||
102 | // area, it gets pushed to the stack. Then, when the output area is |
|
|||
103 | // deactivated, it's popped from the stack. When the stack is empty, |
|
|||
104 | // the cell's output area is used. |
|
|||
105 | this.active_output_areas = []; |
|
|||
106 | var that = this; |
|
|||
107 | Object.defineProperty(this, 'active_output_area', { |
|
|||
108 | get: function() { |
|
|||
109 | if (that.active_output_areas && that.active_output_areas.length > 0) { |
|
|||
110 | return that.active_output_areas[that.active_output_areas.length-1]; |
|
|||
111 | } else { |
|
|||
112 | return that.output_area; |
|
|||
113 | } |
|
|||
114 | }, |
|
|||
115 | }); |
|
|||
116 |
|
100 | |||
117 | this.last_msg_id = null; |
|
101 | this.last_msg_id = null; | |
118 | this.completer = null; |
|
102 | this.completer = null; | |
@@ -126,6 +110,7 b' define([' | |||||
126 |
|
110 | |||
127 | // Attributes we want to override in this subclass. |
|
111 | // Attributes we want to override in this subclass. | |
128 | this.cell_type = "code"; |
|
112 | this.cell_type = "code"; | |
|
113 | var that = this; | |||
129 | this.element.focusout( |
|
114 | this.element.focusout( | |
130 | function() { that.auto_highlight(); } |
|
115 | function() { that.auto_highlight(); } | |
131 | ); |
|
116 | ); | |
@@ -162,23 +147,6 b' define([' | |||||
162 |
|
147 | |||
163 | CodeCell.prototype = Object.create(Cell.prototype); |
|
148 | CodeCell.prototype = Object.create(Cell.prototype); | |
164 |
|
149 | |||
165 | /** |
|
|||
166 | * @method push_output_area |
|
|||
167 | */ |
|
|||
168 | CodeCell.prototype.push_output_area = function (output_area) { |
|
|||
169 | this.active_output_areas.push(output_area); |
|
|||
170 | }; |
|
|||
171 |
|
||||
172 | /** |
|
|||
173 | * @method pop_output_area |
|
|||
174 | */ |
|
|||
175 | CodeCell.prototype.pop_output_area = function (output_area) { |
|
|||
176 | var index = this.active_output_areas.lastIndexOf(output_area); |
|
|||
177 | if (index > -1) { |
|
|||
178 | this.active_output_areas.splice(index, 1); |
|
|||
179 | } |
|
|||
180 | }; |
|
|||
181 |
|
||||
182 | /** @method create_element */ |
|
150 | /** @method create_element */ | |
183 | CodeCell.prototype.create_element = function () { |
|
151 | CodeCell.prototype.create_element = function () { | |
184 | Cell.prototype.create_element.apply(this, arguments); |
|
152 | Cell.prototype.create_element.apply(this, arguments); | |
@@ -409,7 +377,7 b' define([' | |||||
409 | return; |
|
377 | return; | |
410 | } |
|
378 | } | |
411 |
|
379 | |||
412 |
this. |
|
380 | this.output_area.clear_output(false, true); | |
413 |
|
381 | |||
414 | if (stop_on_error === undefined) { |
|
382 | if (stop_on_error === undefined) { | |
415 | stop_on_error = true; |
|
383 | stop_on_error = true; | |
@@ -464,10 +432,10 b' define([' | |||||
464 | }, |
|
432 | }, | |
465 | iopub : { |
|
433 | iopub : { | |
466 | output : function() { |
|
434 | output : function() { | |
467 |
that. |
|
435 | that.output_area.handle_output.apply(that.output_area, arguments); | |
468 | }, |
|
436 | }, | |
469 | clear_output : function() { |
|
437 | clear_output : function() { | |
470 |
that. |
|
438 | that.output_area.handle_clear_output.apply(that.output_area, arguments); | |
471 | }, |
|
439 | }, | |
472 | }, |
|
440 | }, | |
473 | input : $.proxy(this._handle_input_request, this) |
|
441 | input : $.proxy(this._handle_input_request, this) | |
@@ -502,7 +470,7 b' define([' | |||||
502 | * @private |
|
470 | * @private | |
503 | */ |
|
471 | */ | |
504 | CodeCell.prototype._handle_input_request = function (msg) { |
|
472 | CodeCell.prototype._handle_input_request = function (msg) { | |
505 |
this. |
|
473 | this.output_area.append_raw_input(msg); | |
506 | }; |
|
474 | }; | |
507 |
|
475 | |||
508 |
|
476 | |||
@@ -605,7 +573,7 b' define([' | |||||
605 |
|
573 | |||
606 |
|
574 | |||
607 | CodeCell.prototype.clear_output = function (wait) { |
|
575 | CodeCell.prototype.clear_output = function (wait) { | |
608 |
this. |
|
576 | this.output_area.clear_output(wait); | |
609 | this.set_input_prompt(); |
|
577 | this.set_input_prompt(); | |
610 | }; |
|
578 | }; | |
611 |
|
579 |
@@ -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 | /** | |||
|
13 | * Public constructor | |||
|
14 | */ | |||
12 | initialize: function (parameters) { |
|
15 | initialize: function (parameters) { | |
13 | /** |
|
|||
14 | * Public constructor |
|
|||
15 | */ |
|
|||
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 | /** | |||
|
21 | * Called when view is rendered. | |||
|
22 | */ | |||
20 | render: function(){ |
|
23 | render: function(){ | |
21 | /** |
|
|||
22 | * Called when view is rendered. |
|
|||
23 | */ |
|
|||
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,13 +43,16 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 | _handle_route_msg: function(content) { |
|
46 | /** | |
47 | var cell = this.options.cell; |
|
47 | * Handles re-routed iopub messages. | |
48 | if (content && cell) { |
|
48 | */ | |
49 | if (content.method == 'push') { |
|
49 | _handle_route_msg: function(msg) { | |
50 | cell.push_output_area(this.output_area); |
|
50 | if (msg) { | |
51 | } else if (content.method == 'pop') { |
|
51 | var msg_type = msg.msg_type; | |
52 | cell.pop_output_area(this.output_area); |
|
52 | if (msg_type=='clear_output') { | |
|
53 | this.output_area.handle_clear_output(msg); | |||
|
54 | } else { | |||
|
55 | this.output_area.handle_output(msg); | |||
53 | } |
|
56 | } | |
54 | } |
|
57 | } | |
55 | }, |
|
58 | }, |
@@ -11,6 +11,7 b' import sys' | |||||
11 | from IPython.utils.traitlets import Unicode, List |
|
11 | from IPython.utils.traitlets import Unicode, List | |
12 | from IPython.display import clear_output |
|
12 | from IPython.display import clear_output | |
13 | from IPython.testing.skipdoctest import skip_doctest |
|
13 | from IPython.testing.skipdoctest import skip_doctest | |
|
14 | from IPython.kernel.zmq.session import Message | |||
14 |
|
15 | |||
15 | @skip_doctest |
|
16 | @skip_doctest | |
16 | class Output(DOMWidget): |
|
17 | class Output(DOMWidget): | |
@@ -38,13 +39,40 b' class Output(DOMWidget):' | |||||
38 | clear_output(*pargs, **kwargs) |
|
39 | clear_output(*pargs, **kwargs) | |
39 |
|
40 | |||
40 | def __enter__(self): |
|
41 | def __enter__(self): | |
|
42 | """Called upon entering output widget context manager.""" | |||
41 | self._flush() |
|
43 | self._flush() | |
42 | self.send({'method': 'push'}) |
|
44 | kernel = get_ipython().kernel | |
|
45 | session = kernel.session | |||
|
46 | send = session.send | |||
|
47 | self._original_send = send | |||
|
48 | self._session = session | |||
|
49 | ||||
|
50 | def send_hook(stream, msg_or_type, content=None, parent=None, ident=None, | |||
|
51 | buffers=None, track=False, header=None, metadata=None): | |||
|
52 | ||||
|
53 | # Handle both prebuild messages and unbuilt messages. | |||
|
54 | if isinstance(msg_or_type, (Message, dict)): | |||
|
55 | msg_type = msg_or_type['msg_type'] | |||
|
56 | msg = dict(msg_or_type) | |||
|
57 | else: | |||
|
58 | msg_type = msg_or_type | |||
|
59 | msg = session.msg(msg_type, content=content, parent=parent, | |||
|
60 | header=header, metadata=metadata) | |||
|
61 | ||||
|
62 | # If this is a message type that we want to forward, forward it. | |||
|
63 | if stream is kernel.iopub_socket and msg_type in ['clear_output', 'stream', 'display_data']: | |||
|
64 | self.send(msg) | |||
|
65 | else: | |||
|
66 | send(stream, msg, ident=ident, buffers=buffers, track=track) | |||
|
67 | ||||
|
68 | session.send = send_hook | |||
43 |
|
69 | |||
44 | def __exit__(self, exception_type, exception_value, traceback): |
|
70 | def __exit__(self, exception_type, exception_value, traceback): | |
|
71 | """Called upon exiting output widget context manager.""" | |||
45 | self._flush() |
|
72 | self._flush() | |
46 | self.send({'method': 'pop'}) |
|
73 | self._session.send = self._original_send | |
47 |
|
74 | |||
48 | def _flush(self): |
|
75 | def _flush(self): | |
|
76 | """Flush stdout and stderr buffers.""" | |||
49 | sys.stdout.flush() |
|
77 | sys.stdout.flush() | |
50 | sys.stderr.flush() |
|
78 | sys.stderr.flush() |
General Comments 0
You need to be logged in to leave comments.
Login now