From eeea62316103899c002f60dbd8691c29dade1297 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Fri, 26 Oct 2012 22:03:57 +0200 Subject: [PATCH 1/4] Add event to kernel execution/shell reply. This should allow to hook more easily phantomjs for testing. --- IPython/frontend/html/notebook/static/js/kernel.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/static/js/kernel.js b/IPython/frontend/html/notebook/static/js/kernel.js index dea771177..1334884d5 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -245,7 +245,8 @@ var IPython = (function (IPython) { user_expressions : {}, allow_stdin : false }; - $.extend(true, content, options) + $.extend(true, content, options) + $([IPython.events]).trigger({type: 'Kernel.execution_request', kernel: this, content:content}); var msg = this._get_msg("execute_request", content); this.shell_channel.send(JSON.stringify(msg)); this.set_callbacks_for_msg(msg.header.msg_id, callbacks); @@ -312,6 +313,7 @@ var IPython = (function (IPython) { Kernel.prototype._handle_shell_reply = function (e) { reply = $.parseJSON(e.data); + $([IPython.events]).trigger({type: 'Kernel.shell_reply', kernel: this, reply:reply}); var header = reply.header; var content = reply.content; var metadata = reply.metadata; From afa18913b91f61705f3d7d2d68aa186a2928fd51 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Fri, 2 Nov 2012 13:58:08 +0100 Subject: [PATCH 2/4] invert event name --- IPython/frontend/html/notebook/static/js/kernel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/kernel.js b/IPython/frontend/html/notebook/static/js/kernel.js index 1334884d5..53aeabf2a 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -246,7 +246,7 @@ var IPython = (function (IPython) { allow_stdin : false }; $.extend(true, content, options) - $([IPython.events]).trigger({type: 'Kernel.execution_request', kernel: this, content:content}); + $([IPython.events]).trigger({type: 'execution_request.Kernel', kernel: this, content:content}); var msg = this._get_msg("execute_request", content); this.shell_channel.send(JSON.stringify(msg)); this.set_callbacks_for_msg(msg.header.msg_id, callbacks); @@ -313,7 +313,7 @@ var IPython = (function (IPython) { Kernel.prototype._handle_shell_reply = function (e) { reply = $.parseJSON(e.data); - $([IPython.events]).trigger({type: 'Kernel.shell_reply', kernel: this, reply:reply}); + $([IPython.events]).trigger({type: 'shell_reply.Kernel', kernel: this, reply:reply}); var header = reply.header; var content = reply.content; var metadata = reply.metadata; From 68fd917bfbfc5da1d47f58fc5bb61cbb069592b3 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Fri, 2 Nov 2012 21:23:34 +0100 Subject: [PATCH 3/4] change all trigger parameter to (event,data) --- IPython/frontend/html/notebook/static/js/kernel.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/kernel.js b/IPython/frontend/html/notebook/static/js/kernel.js index 53aeabf2a..5958c496c 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -64,7 +64,7 @@ var IPython = (function (IPython) { Kernel.prototype.restart = function () { - $([IPython.events]).trigger({type: 'status_restarting.Kernel', kernel: this}); + $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this}); var that = this; if (this.running) { this.stop_channels(); @@ -246,7 +246,7 @@ var IPython = (function (IPython) { allow_stdin : false }; $.extend(true, content, options) - $([IPython.events]).trigger({type: 'execution_request.Kernel', kernel: this, content:content}); + $([IPython.events]).trigger('execution_request.Kernel', {kernel: this, content:content}); var msg = this._get_msg("execute_request", content); this.shell_channel.send(JSON.stringify(msg)); this.set_callbacks_for_msg(msg.header.msg_id, callbacks); @@ -280,7 +280,7 @@ var IPython = (function (IPython) { Kernel.prototype.interrupt = function () { if (this.running) { - $([IPython.events]).trigger({type: 'status_interrupting.Kernel', kernel: this}); + $([IPython.events]).trigger('status_interrupting.Kernel', {kernel: this}); $.post(this.kernel_url + "/interrupt"); }; }; @@ -313,7 +313,7 @@ var IPython = (function (IPython) { Kernel.prototype._handle_shell_reply = function (e) { reply = $.parseJSON(e.data); - $([IPython.events]).trigger({type: 'shell_reply.Kernel', kernel: this, reply:reply}); + $([IPython.events]).trigger('shell_reply.Kernel', {kernel: this, reply:reply}); var header = reply.header; var content = reply.content; var metadata = reply.metadata; @@ -369,12 +369,12 @@ var IPython = (function (IPython) { } } else if (msg_type === 'status') { if (content.execution_state === 'busy') { - $([IPython.events]).trigger({type: 'status_busy.Kernel', kernel: this}); + $([IPython.events]).trigger('status_busy.Kernel', {kernel: this}); } else if (content.execution_state === 'idle') { - $([IPython.events]).trigger({type: 'status_idle.Kernel', kernel: this}); + $([IPython.events]).trigger('status_idle.Kernel', {kernel: this}); } else if (content.execution_state === 'dead') { this.stop_channels(); - $([IPython.events]).trigger({type: 'status_dead.Kernel', kernel: this}); + $([IPython.events]).trigger('status_dead.Kernel', {kernel: this}); }; } else if (msg_type === 'clear_output') { var cb = callbacks['clear_output']; From 4aea2b495a6d15f067575b7af656de25e9f88dc4 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Mon, 5 Nov 2012 19:51:31 +0100 Subject: [PATCH 4/4] add status_started event to Kernel --- 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 5958c496c..14f382f91 100644 --- a/IPython/frontend/html/notebook/static/js/kernel.js +++ b/IPython/frontend/html/notebook/static/js/kernel.js @@ -86,6 +86,7 @@ var IPython = (function (IPython) { this.start_channels(); this.shell_channel.onmessage = $.proxy(this._handle_shell_reply,this); this.iopub_channel.onmessage = $.proxy(this._handle_iopub_reply,this); + $([IPython.events]).trigger('status_started.Kernel', {kernel: this}); };