##// END OF EJS Templates
Merge pull request #7523 from jdfreder/outputwidgetfix...
Min RK -
r20096:5616d61c merge
parent child Browse files
Show More
@@ -97,22 +97,6 b' define(['
97 97 this.input_prompt_number = null;
98 98 this.celltoolbar = null;
99 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 101 this.last_msg_id = null;
118 102 this.completer = null;
@@ -126,6 +110,7 b' define(['
126 110
127 111 // Attributes we want to override in this subclass.
128 112 this.cell_type = "code";
113 var that = this;
129 114 this.element.focusout(
130 115 function() { that.auto_highlight(); }
131 116 );
@@ -162,23 +147,6 b' define(['
162 147
163 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 150 /** @method create_element */
183 151 CodeCell.prototype.create_element = function () {
184 152 Cell.prototype.create_element.apply(this, arguments);
@@ -409,7 +377,7 b' define(['
409 377 return;
410 378 }
411 379
412 this.active_output_area.clear_output(false, true);
380 this.output_area.clear_output(false, true);
413 381
414 382 if (stop_on_error === undefined) {
415 383 stop_on_error = true;
@@ -464,10 +432,10 b' define(['
464 432 },
465 433 iopub : {
466 434 output : function() {
467 that.active_output_area.handle_output.apply(that.active_output_area, arguments);
435 that.output_area.handle_output.apply(that.output_area, arguments);
468 436 },
469 437 clear_output : function() {
470 that.active_output_area.handle_clear_output.apply(that.active_output_area, arguments);
438 that.output_area.handle_clear_output.apply(that.output_area, arguments);
471 439 },
472 440 },
473 441 input : $.proxy(this._handle_input_request, this)
@@ -502,7 +470,7 b' define(['
502 470 * @private
503 471 */
504 472 CodeCell.prototype._handle_input_request = function (msg) {
505 this.active_output_area.append_raw_input(msg);
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 575 CodeCell.prototype.clear_output = function (wait) {
608 this.active_output_area.clear_output(wait);
576 this.output_area.clear_output(wait);
609 577 this.set_input_prompt();
610 578 };
611 579
@@ -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 /**
13 * Public constructor
14 */
12 15 initialize: function (parameters) {
13 /**
14 * Public constructor
15 */
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 /**
21 * Called when view is rendered.
22 */
20 23 render: function(){
21 /**
22 * Called when view is rendered.
23 */
24 24 this.output_area = new outputarea.OutputArea({
25 25 selector: this.$el,
26 26 prompt_area: false,
@@ -43,13 +43,16 b' define(['
43 43 this.output_area.element.html(this.model.get('contents'));
44 44 },
45 45
46 _handle_route_msg: function(content) {
47 var cell = this.options.cell;
48 if (content && cell) {
49 if (content.method == 'push') {
50 cell.push_output_area(this.output_area);
51 } else if (content.method == 'pop') {
52 cell.pop_output_area(this.output_area);
46 /**
47 * Handles re-routed iopub messages.
48 */
49 _handle_route_msg: function(msg) {
50 if (msg) {
51 var msg_type = msg.msg_type;
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 11 from IPython.utils.traitlets import Unicode, List
12 12 from IPython.display import clear_output
13 13 from IPython.testing.skipdoctest import skip_doctest
14 from IPython.kernel.zmq.session import Message
14 15
15 16 @skip_doctest
16 17 class Output(DOMWidget):
@@ -38,13 +39,40 b' class Output(DOMWidget):'
38 39 clear_output(*pargs, **kwargs)
39 40
40 41 def __enter__(self):
42 """Called upon entering output widget context manager."""
41 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 70 def __exit__(self, exception_type, exception_value, traceback):
71 """Called upon exiting output widget context manager."""
45 72 self._flush()
46 self.send({'method': 'pop'})
73 self._session.send = self._original_send
47 74
48 75 def _flush(self):
76 """Flush stdout and stderr buffers."""
49 77 sys.stdout.flush()
50 78 sys.stderr.flush()
General Comments 0
You need to be logged in to leave comments. Login now