mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
Finished changing output widget logic.
This commit is contained in:
parent
705bd90653
commit
39b99340ed
@ -110,6 +110,7 @@ define([
|
||||
|
||||
// Attributes we want to override in this subclass.
|
||||
this.cell_type = "code";
|
||||
var that = this;
|
||||
this.element.focusout(
|
||||
function() { that.auto_highlight(); }
|
||||
);
|
||||
|
@ -212,11 +212,9 @@ define([
|
||||
json.name = content.name;
|
||||
} else if (msg_type === "display_data") {
|
||||
json.data = content.data;
|
||||
json.output_type = msg_type;
|
||||
json.metadata = content.metadata;
|
||||
} else if (msg_type === "execute_result") {
|
||||
json.data = content.data;
|
||||
json.output_type = msg_type;
|
||||
json.metadata = content.metadata;
|
||||
json.execution_count = content.execution_count;
|
||||
} else if (msg_type === "error") {
|
||||
|
@ -9,18 +9,18 @@ define([
|
||||
'use strict';
|
||||
|
||||
var OutputView = widget.DOMWidgetView.extend({
|
||||
/**
|
||||
* Public constructor
|
||||
*/
|
||||
initialize: function (parameters) {
|
||||
/**
|
||||
* Public constructor
|
||||
*/
|
||||
OutputView.__super__.initialize.apply(this, [parameters]);
|
||||
this.model.on('msg:custom', this._handle_route_msg, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when view is rendered.
|
||||
*/
|
||||
render: function(){
|
||||
/**
|
||||
* Called when view is rendered.
|
||||
*/
|
||||
this.output_area = new outputarea.OutputArea({
|
||||
selector: this.$el,
|
||||
prompt_area: false,
|
||||
@ -43,32 +43,33 @@ define([
|
||||
this.output_area.element.html(this.model.get('contents'));
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles re-routed iopub messages.
|
||||
*/
|
||||
_handle_route_msg: function(content) {
|
||||
if (content) {
|
||||
// return {
|
||||
// shell : {
|
||||
// reply : $.proxy(this._handle_execute_reply, this),
|
||||
// payload : {
|
||||
// set_next_input : $.proxy(this._handle_set_next_input, this),
|
||||
// page : $.proxy(this._open_with_pager, this)
|
||||
// }
|
||||
// },
|
||||
// iopub : {
|
||||
// output : function() {
|
||||
// that.output_area.handle_output.apply(that.output_area, arguments);
|
||||
// },
|
||||
// clear_output : function() {
|
||||
// that.output_area.handle_clear_output.apply(that.output_area, arguments);
|
||||
// },
|
||||
// },
|
||||
// input : $.proxy(this._handle_input_request, this)
|
||||
// };
|
||||
// };
|
||||
if (content.method == 'push') {
|
||||
cell.push_output_area(this.output_area);
|
||||
} else if (content.method == 'pop') {
|
||||
cell.pop_output_area(this.output_area);
|
||||
var msg_type = content.type;
|
||||
var json = {
|
||||
output_type: msg_type
|
||||
};
|
||||
|
||||
var data = content.args[0];
|
||||
if (msg_type=='clear_output') {
|
||||
this.output_area.clear_output(data.wait || false);
|
||||
return;
|
||||
} else if (msg_type === "stream") {
|
||||
data = content.kwargs.content;
|
||||
json.text = data.text;
|
||||
json.name = data.name;
|
||||
} else if (msg_type === "display_data") {
|
||||
json.data = data.data;
|
||||
json.metadata = data.metadata;
|
||||
} else {
|
||||
console.log("unhandled output message", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
this.output_area.append_output(json);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -38,13 +38,30 @@ class Output(DOMWidget):
|
||||
clear_output(*pargs, **kwargs)
|
||||
|
||||
def __enter__(self):
|
||||
"""Called upon entering output widget context manager."""
|
||||
self._flush()
|
||||
self.send({'method': 'push'})
|
||||
kernel = get_ipython().kernel
|
||||
session = kernel.session
|
||||
send = session.send
|
||||
self._original_send = send
|
||||
self._session = session
|
||||
|
||||
def send_hook(stream, msg_or_type, *args, **kwargs):
|
||||
if stream is kernel.iopub_socket and msg_or_type in ['clear_output', 'stream', 'display_data']:
|
||||
msg = {'type': msg_or_type, 'args': args, 'kwargs': kwargs}
|
||||
self.send(msg)
|
||||
else:
|
||||
send(stream, msg_or_type, *args, **kwargs)
|
||||
return
|
||||
|
||||
session.send = send_hook
|
||||
|
||||
def __exit__(self, exception_type, exception_value, traceback):
|
||||
"""Called upon exiting output widget context manager."""
|
||||
self._flush()
|
||||
self.send({'method': 'pop'})
|
||||
self._session.send = self._original_send
|
||||
|
||||
def _flush(self):
|
||||
"""Flush stdout and stderr buffers."""
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
|
Loading…
Reference in New Issue
Block a user