##// END OF EJS Templates
Hook the output the right way.
Jonathan Frederic -
Show More
@@ -46,30 +46,14 define([
46 46 /**
47 47 * Handles re-routed iopub messages.
48 48 */
49 _handle_route_msg: function(content) {
50 if (content) {
51 var msg_type = content.type;
52 var json = {
53 output_type: msg_type
54 };
55
56 var data = content.args[0];
49 _handle_route_msg: function(msg) {
50 if (msg) {
51 var msg_type = msg.msg_type;
57 52 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;
53 this.output_area.handle_clear_output(msg);
67 54 } else {
68 console.log("unhandled output message", msg);
69 return;
55 this.output_area.handle_output(msg);
70 56 }
71
72 this.output_area.append_output(json);
73 57 }
74 58 },
75 59 });
@@ -46,12 +46,24 class Output(DOMWidget):
46 46 self._original_send = send
47 47 self._session = session
48 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)
49 def send_hook(stream, msg_or_type, content=None, parent=None, ident=None,
50 buffers=None, track=False, header=None, metadata=None):
51
52 # Handle both prebuild messages and unbuilt messages.
53 if isinstance(msg_or_type, dict):
54 msg_type = msg_or_type['msg_type']
55 msg = msg_or_type
53 56 else:
54 send(stream, msg_or_type, *args, **kwargs)
57 msg_type = msg_or_type
58 msg = session.msg(msg_type, content=content, parent=parent,
59 header=header, metadata=metadata)
60
61 # If this is a message type that we want to forward, forward it.
62 if stream is kernel.iopub_socket and msg_type in ['clear_output', 'stream', 'display_data']:
63 self.send(msg)
64 else:
65 send(stream, msg_or_type, content=content, parent=parent, ident=ident,
66 buffers=buffers, track=track, header=header, metadata=metadata)
55 67
56 68 session.send = send_hook
57 69
General Comments 0
You need to be logged in to leave comments. Login now