From 009e5583cfc7bdddb9ad058fcd42a82c9a4a1acb Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Fri, 29 Jun 2012 11:09:22 -0500 Subject: [PATCH 1/5] Pass the header of output and clear_output messages to javascript callbacks --- IPython/frontend/html/notebook/static/js/kernel.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/kernel.js b/IPython/frontend/html/notebook/static/js/kernel.js index b466b66de..761402b07 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -226,15 +226,15 @@ var IPython = (function (IPython) { // http://ipython.org/ipython-doc/dev/development/messaging.html#execute // // The output_callback will be passed msg_type ('stream','display_data','pyout','pyerr') - // of the output and the content object of the PUB/SUB channel that contains the + // of the output and the content and header objects of the PUB/SUB channel that contains the // output: // // http://ipython.org/ipython-doc/dev/development/messaging.html#messages-on-the-pub-sub-socket // // The clear_output_callback will be passed a content object that contains - // stdout, stderr and other fields that are booleans. + // stdout, stderr and other fields that are booleans, as well as the header object. // - // The set_next_input_callback will bepassed the text that should become the next + // The set_next_input_callback will be passed the text that should become the next // input cell. var content = { @@ -350,6 +350,7 @@ var IPython = (function (IPython) { reply = $.parseJSON(e.data); var content = reply.content; var msg_type = reply.header.msg_type; + var header = reply.header; var callbacks = this.get_callbacks_for_msg(reply.parent_header.msg_id); if (msg_type !== 'status' && callbacks === undefined) { // Message not from one of this notebook's cells and there are no @@ -360,7 +361,7 @@ var IPython = (function (IPython) { if (output_types.indexOf(msg_type) >= 0) { var cb = callbacks['output']; if (cb !== undefined) { - cb(msg_type, content); + cb(msg_type, content, header); } } else if (msg_type === 'status') { if (content.execution_state === 'busy') { @@ -374,7 +375,7 @@ var IPython = (function (IPython) { } else if (msg_type === 'clear_output') { var cb = callbacks['clear_output']; if (cb !== undefined) { - cb(content); + cb(content, header); } }; }; From 9436f33035f642c8a3397d940fd8844a077749b8 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Sat, 7 Jul 2012 11:06:48 -0500 Subject: [PATCH 2/5] Add an optional metadata attribute to all messages and add a session-level default metadata attribute. --- .../frontend/html/notebook/static/js/kernel.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/kernel.js b/IPython/frontend/html/notebook/static/js/kernel.js index 761402b07..e446d5cba 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -220,19 +220,19 @@ var IPython = (function (IPython) { // 'set_next_input': set_next_input_callback // } // - // The execute_reply_callback will be passed the content object of the execute_reply + // The execute_reply_callback will be passed the content and metadata objects of the execute_reply // message documented here: // // http://ipython.org/ipython-doc/dev/development/messaging.html#execute // // The output_callback will be passed msg_type ('stream','display_data','pyout','pyerr') - // of the output and the content and header objects of the PUB/SUB channel that contains the + // of the output and the content and metadata objects of the PUB/SUB channel that contains the // output: // // http://ipython.org/ipython-doc/dev/development/messaging.html#messages-on-the-pub-sub-socket // // The clear_output_callback will be passed a content object that contains - // stdout, stderr and other fields that are booleans, as well as the header object. + // stdout, stderr and other fields that are booleans, as well as the metadata object. // // The set_next_input_callback will be passed the text that should become the next // input cell. @@ -313,12 +313,13 @@ var IPython = (function (IPython) { reply = $.parseJSON(e.data); var header = reply.header; var content = reply.content; + var metadata = reply.metadata; var msg_type = header.msg_type; var callbacks = this.get_callbacks_for_msg(reply.parent_header.msg_id); if (callbacks !== undefined) { var cb = callbacks[msg_type]; if (cb !== undefined) { - cb(content); + cb(content, metadata); } }; @@ -347,10 +348,10 @@ var IPython = (function (IPython) { Kernel.prototype._handle_iopub_reply = function (e) { - reply = $.parseJSON(e.data); + var reply = $.parseJSON(e.data); var content = reply.content; var msg_type = reply.header.msg_type; - var header = reply.header; + var metadata = reply.metadata; var callbacks = this.get_callbacks_for_msg(reply.parent_header.msg_id); if (msg_type !== 'status' && callbacks === undefined) { // Message not from one of this notebook's cells and there are no @@ -361,7 +362,7 @@ var IPython = (function (IPython) { if (output_types.indexOf(msg_type) >= 0) { var cb = callbacks['output']; if (cb !== undefined) { - cb(msg_type, content, header); + cb(msg_type, content, metadata); } } else if (msg_type === 'status') { if (content.execution_state === 'busy') { @@ -375,7 +376,7 @@ var IPython = (function (IPython) { } else if (msg_type === 'clear_output') { var cb = callbacks['clear_output']; if (cb !== undefined) { - cb(content, header); + cb(content, metadata); } }; }; From 4ad79b41f6ddcb1b355a47d3d96b5ea2bd422999 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Sat, 7 Jul 2012 11:38:08 -0500 Subject: [PATCH 3/5] Set default metadata for javascript callback --- IPython/frontend/html/notebook/static/js/kernel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/static/js/kernel.js b/IPython/frontend/html/notebook/static/js/kernel.js index e446d5cba..ea80e9ed4 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -351,7 +351,7 @@ var IPython = (function (IPython) { var reply = $.parseJSON(e.data); var content = reply.content; var msg_type = reply.header.msg_type; - var metadata = reply.metadata; + var metadata = reply.metadata || {}; var callbacks = this.get_callbacks_for_msg(reply.parent_header.msg_id); if (msg_type !== 'status' && callbacks === undefined) { // Message not from one of this notebook's cells and there are no From 7095b9eb8789a487e1892e4d3f30c20bc3642721 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Sat, 7 Jul 2012 12:43:41 -0500 Subject: [PATCH 4/5] Make top-level metadata dictionary not optional. --- IPython/frontend/html/notebook/static/js/kernel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/static/js/kernel.js b/IPython/frontend/html/notebook/static/js/kernel.js index ea80e9ed4..e446d5cba 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -351,7 +351,7 @@ var IPython = (function (IPython) { var reply = $.parseJSON(e.data); var content = reply.content; var msg_type = reply.header.msg_type; - var metadata = reply.metadata || {}; + var metadata = reply.metadata; var callbacks = this.get_callbacks_for_msg(reply.parent_header.msg_id); if (msg_type !== 'status' && callbacks === undefined) { // Message not from one of this notebook's cells and there are no From 25aa3003ac71e9971cd784b47266fcc6a5b1a476 Mon Sep 17 00:00:00 2001 From: MinRK Date: Fri, 20 Jul 2012 17:57:35 -0500 Subject: [PATCH 5/5] add metadata to javascript msg spec implementation --- IPython/frontend/html/notebook/static/js/kernel.js | 1 + 1 file changed, 1 insertion(+) diff --git a/IPython/frontend/html/notebook/static/js/kernel.js b/IPython/frontend/html/notebook/static/js/kernel.js index e446d5cba..77292ba47 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -43,6 +43,7 @@ var IPython = (function (IPython) { session : this.session_id, msg_type : msg_type }, + metadata : {}, content : content, parent_header : {} };