##// END OF EJS Templates
tweak history prefix search (up/^p) in qtconsole...
tweak history prefix search (up/^p) in qtconsole moving the cursor around the line could result in weird inconsistencies in the prefix. This simplifies the logic by always using the cursor position to set the history prefix, and better determine when the history prefix has actually changed.

File last commit:

r8839:b1ae47fc
r9205:ef8c14cd
Show More
kernel.js
460 lines | 15.4 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
//============================================================================
// Kernel
//============================================================================
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* @module IPython
* @namespace IPython
* @submodule Kernel
*/
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var IPython = (function (IPython) {
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var utils = IPython.utils;
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 // Initialization and connection.
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* A Kernel Class to communicate with the Python kernel
* @Class Kernel
*/
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var Kernel = function (base_url) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.kernel_id = null;
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.shell_channel = null;
this.iopub_channel = null;
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 this.base_url = base_url;
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.running = false;
MinRK
fix undefined 'session_id' member in kernel.js
r4694 this.username = "username";
this.session_id = utils.uuid();
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 this._msg_callbacks = {};
Brian E. Granger
Better WebSocket detection added.
r4612 if (typeof(WebSocket) !== 'undefined') {
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 this.WebSocket = WebSocket;
Brian E. Granger
Better WebSocket detection added.
r4612 } else if (typeof(MozWebSocket) !== 'undefined') {
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 this.WebSocket = MozWebSocket;
Brian E. Granger
Adding code to handle MozWebSocket for FF 6.
r4611 } else {
MinRK
alert client on failed and lost web socket connections...
r5253 alert('Your browser does not have WebSocket support, please try Chrome, Safari or Firefox ≥ 6. Firefox 4 and 5 are also supported by you have to enable WebSockets in about:config.');
Brian E. Granger
Adding code to handle MozWebSocket for FF 6.
r4611 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 Kernel.prototype._get_msg = function (msg_type, content) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var msg = {
header : {
msg_id : utils.uuid(),
MinRK
fix undefined 'session_id' member in kernel.js
r4694 username : this.username,
session : this.session_id,
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 msg_type : msg_type
},
MinRK
add metadata to javascript msg spec implementation
r7958 metadata : {},
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 content : content,
parent_header : {}
};
return msg;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* Start the Python kernel
* @method start
*/
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 Kernel.prototype.start = function (notebook_id) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var that = this;
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 if (!this.running) {
var qs = $.param({notebook:notebook_id});
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 var url = this.base_url + '?' + qs;
Brian E. Granger
Updating JS URL scheme to use embedded data....
r5106 $.post(url,
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 $.proxy(that._kernel_started,that),
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 'json'
);
};
};
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* Restart the python kernel.
*
* Emit a 'status_restarting.Kernel' event with
* the current object as parameter
*
* @method restart
*/
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 Kernel.prototype.restart = function () {
Matthias BUSSONNIER
change all trigger parameter to (event,data)
r8677 $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this});
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 var that = this;
if (this.running) {
this.stop_channels();
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var url = this.kernel_url + "/restart";
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 $.post(url,
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 $.proxy(that._kernel_started, that),
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 'json'
);
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 Kernel.prototype._kernel_started = function (json) {
console.log("Kernel started: ", json.kernel_id);
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.running = true;
Brian E. Granger
WebSocket url is now passed to browser when a kernel is started.
r4572 this.kernel_id = json.kernel_id;
this.ws_url = json.ws_url;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.kernel_url = this.base_url + "/" + this.kernel_id;
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.start_channels();
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 this.shell_channel.onmessage = $.proxy(this._handle_shell_reply,this);
this.iopub_channel.onmessage = $.proxy(this._handle_iopub_reply,this);
Matthias BUSSONNIER
add status_started event to Kernel
r8690 $([IPython.events]).trigger('status_started.Kernel', {kernel: this});
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168
MinRK
use jQuery dialog instead of alert()
r5255 Kernel.prototype._websocket_closed = function(ws_url, early){
var msg;
var parent_item = $('body');
if (early) {
Brian Granger
Major refactoring of saving, notification....
r6047 msg = "Websocket connection to " + ws_url + " could not be established." +
" You will NOT be able to run code." +
MinRK
use jQuery dialog instead of alert()
r5255 " Your browser may not be compatible with the websocket version in the server," +
" or if the url does not look right, there could be an error in the" +
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 " server's configuration.";
MinRK
use jQuery dialog instead of alert()
r5255 } else {
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 IPython.notification_area.widget('kernel').set_message('Reconnecting Websockets', 1000);
MinRK
avoid double websocket-close message
r7559 this.start_channels();
return;
}
MinRK
use jQuery dialog instead of alert()
r5255 var dialog = $('<div/>');
dialog.html(msg);
parent_item.append(dialog);
dialog.dialog({
resizable: false,
modal: true,
title: "Websocket closed",
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 closeText: "",
close: function(event, ui) {$(this).dialog('destroy').remove();},
MinRK
use jQuery dialog instead of alert()
r5255 buttons : {
Brian Granger
Proper error handling for nbformat versions in client code....
r6061 "OK": function () {
MinRK
use jQuery dialog instead of alert()
r5255 $(this).dialog('close');
}
}
});
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* Start the `shell`and `iopub` channels.
* Will stop and restart them if they already exist.
*
* @method start_channels
*/
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 Kernel.prototype.start_channels = function () {
MinRK
alert client on failed and lost web socket connections...
r5253 var that = this;
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.stop_channels();
Brian E. Granger
WebSocket url is now passed to browser when a kernel is started.
r4572 var ws_url = this.ws_url + this.kernel_url;
console.log("Starting WS:", ws_url);
Brian E. Granger
Adding code to handle MozWebSocket for FF 6.
r4611 this.shell_channel = new this.WebSocket(ws_url + "/shell");
this.iopub_channel = new this.WebSocket(ws_url + "/iopub");
MinRK
authenticate Websockets with the session cookie...
r4707 send_cookie = function(){
this.send(document.cookie);
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
MinRK
alert client on failed and lost web socket connections...
r5253 var already_called_onclose = false; // only alert once
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var ws_closed_early = function(evt){
MinRK
alert client on failed and lost web socket connections...
r5253 if (already_called_onclose){
return;
}
already_called_onclose = true;
if ( ! evt.wasClean ){
MinRK
use jQuery dialog instead of alert()
r5255 that._websocket_closed(ws_url, true);
MinRK
alert client on failed and lost web socket connections...
r5253 }
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var ws_closed_late = function(evt){
MinRK
alert client on failed and lost web socket connections...
r5253 if (already_called_onclose){
return;
}
already_called_onclose = true;
if ( ! evt.wasClean ){
MinRK
use jQuery dialog instead of alert()
r5255 that._websocket_closed(ws_url, false);
MinRK
alert client on failed and lost web socket connections...
r5253 }
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
MinRK
authenticate Websockets with the session cookie...
r4707 this.shell_channel.onopen = send_cookie;
MinRK
alert client on failed and lost web socket connections...
r5253 this.shell_channel.onclose = ws_closed_early;
MinRK
authenticate Websockets with the session cookie...
r4707 this.iopub_channel.onopen = send_cookie;
MinRK
alert client on failed and lost web socket connections...
r5253 this.iopub_channel.onclose = ws_closed_early;
// switch from early-close to late-close message after 1s
setTimeout(function(){
that.shell_channel.onclose = ws_closed_late;
that.iopub_channel.onclose = ws_closed_late;
}, 1000);
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* Start the `shell`and `iopub` channels.
* @method stop_channels
*/
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 Kernel.prototype.stop_channels = function () {
if (this.shell_channel !== null) {
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 this.shell_channel.onclose = function (evt) {};
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.shell_channel.close();
this.shell_channel = null;
};
if (this.iopub_channel !== null) {
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 this.iopub_channel.onclose = function (evt) {};
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.iopub_channel.close();
this.iopub_channel = null;
};
};
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 // Main public methods.
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* Get info on object asynchronoulsy
*
* @async
* @param objname {string}
* @param callback {dict}
* @method object_info_request
*
* @example
*
* When calling this method pass a callbacks structure of the form:
*
* callbacks = {
* 'object_info_reply': object_info_reply_callback
* }
*
* The `object_info_reply_callback` will be passed the content object of the
*
* `object_into_reply` message documented in
* [IPython dev documentation](http://ipython.org/ipython-doc/dev/development/messaging.html#object-information)
*/
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 Kernel.prototype.object_info_request = function (objname, callbacks) {
Matthias BUSSONNIER
tab pick if only one match left
r5522 if(typeof(objname)!=null && objname!=null)
Matthias BUSSONNIER
handle null objectname on tooltip
r5409 {
var content = {
oname : objname.toString(),
};
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var msg = this._get_msg("object_info_request", content);
Matthias BUSSONNIER
handle null objectname on tooltip
r5409 this.shell_channel.send(JSON.stringify(msg));
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 this.set_callbacks_for_msg(msg.header.msg_id, callbacks);
Matthias BUSSONNIER
handle null objectname on tooltip
r5409 return msg.header.msg_id;
}
return;
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 }
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* Execute given code into kernel, and pass result to callback.
*
* @async
* @method execute
* @param {string} code
* @param callback {Object} With the following keys
* @param callback.'execute_reply' {function}
* @param callback.'output' {function}
* @param callback.'clear_output' {function}
* @param callback.'set_next_input' {function}
* @param {object} [options]
* @param [options.silent=false] {Boolean}
* @param [options.user_expressions=empty_dict] {Dict}
* @param [options.user_variables=empty_list] {List od Strings}
* @param [options.allow_stdin=false] {Boolean} true|false
*
* @example
*
* The options object should contain the options for the execute call. Its default
* values are:
*
* options = {
* silent : true,
* user_variables : [],
* user_expressions : {},
* allow_stdin : false
* }
*
* When calling this method pass a callbacks structure of the form:
*
* callbacks = {
* 'execute_reply': execute_reply_callback,
* 'output': output_callback,
* 'clear_output': clear_output_callback,
* 'set_next_input': set_next_input_callback
* }
*
* 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 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 metadata object.
*
* The `set_next_input_callback` will be passed the text that should become the next
* input cell.
*/
Brian Granger
Adding options to Kernel.execute with a default of silent=true.
r7176 Kernel.prototype.execute = function (code, callbacks, options) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var content = {
code : code,
Brian Granger
Adding options to Kernel.execute with a default of silent=true.
r7176 silent : true,
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 user_variables : [],
MinRK
fix missing trailing comma in kernel.js
r4975 user_expressions : {},
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 allow_stdin : false
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Matthias BUSSONNIER
Add event to kernel execution/shell reply....
r8605 $.extend(true, content, options)
Matthias BUSSONNIER
change all trigger parameter to (event,data)
r8677 $([IPython.events]).trigger('execution_request.Kernel', {kernel: this, content:content});
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var msg = this._get_msg("execute_request", content);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.shell_channel.send(JSON.stringify(msg));
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 this.set_callbacks_for_msg(msg.header.msg_id, callbacks);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return msg.header.msg_id;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* When calling this method pass a callbacks structure of the form:
*
* callbacks = {
* 'complete_reply': complete_reply_callback
* }
*
* The `complete_reply_callback` will be passed the content object of the
* `complete_reply` message documented
* [here](http://ipython.org/ipython-doc/dev/development/messaging.html#complete)
*
* @method complete
* @param line {integer}
* @param cursor_pos {integer}
* @param {dict} callbacks
* @param callbacks.complete_reply {function} `complete_reply_callback`
*
*/
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 Kernel.prototype.complete = function (line, cursor_pos, callbacks) {
Brian Granger
Update directview.ipynb & allowing no-callbacks in kernel.execute.
r7212 callbacks = callbacks || {};
Brian Granger
Added complete method of JS kernel object.
r4388 var content = {
text : '',
line : line,
cursor_pos : cursor_pos
};
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var msg = this._get_msg("complete_request", content);
Brian Granger
Added complete method of JS kernel object.
r4388 this.shell_channel.send(JSON.stringify(msg));
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 this.set_callbacks_for_msg(msg.header.msg_id, callbacks);
Brian Granger
Added complete method of JS kernel object.
r4388 return msg.header.msg_id;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian Granger
Added complete method of JS kernel object.
r4388
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Kernel.prototype.interrupt = function () {
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 if (this.running) {
Matthias BUSSONNIER
change all trigger parameter to (event,data)
r8677 $([IPython.events]).trigger('status_interrupting.Kernel', {kernel: this});
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 $.post(this.kernel_url + "/interrupt");
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 };
Brian E. Granger
Using beforeunload to save at exit and kill the kernel.
r4496 Kernel.prototype.kill = function () {
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 if (this.running) {
this.running = false;
var settings = {
cache : false,
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 type : "DELETE"
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 };
$.ajax(this.kernel_url, settings);
Brian E. Granger
Using beforeunload to save at exit and kill the kernel.
r4496 };
};
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168
// Reply handlers.
Kernel.prototype.get_callbacks_for_msg = function (msg_id) {
var callbacks = this._msg_callbacks[msg_id];
return callbacks;
};
Kernel.prototype.set_callbacks_for_msg = function (msg_id, callbacks) {
Brian Granger
Update directview.ipynb & allowing no-callbacks in kernel.execute.
r7212 this._msg_callbacks[msg_id] = callbacks || {};
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 }
Kernel.prototype._handle_shell_reply = function (e) {
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 var reply = $.parseJSON(e.data);
Matthias BUSSONNIER
change all trigger parameter to (event,data)
r8677 $([IPython.events]).trigger('shell_reply.Kernel', {kernel: this, reply:reply});
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var header = reply.header;
var content = reply.content;
Jason Grout
Add an optional metadata attribute to all messages and add a session-level default metadata attribute.
r7952 var metadata = reply.metadata;
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 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) {
Jason Grout
Add an optional metadata attribute to all messages and add a session-level default metadata attribute.
r7952 cb(content, metadata);
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 }
};
Brian Granger
Removing cell from execute callbacks in kernel.js.
r7223 if (content.payload !== undefined) {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var payload = content.payload || [];
Brian Granger
Removing cell from execute callbacks in kernel.js.
r7223 this._handle_payload(callbacks, payload);
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 }
};
Brian Granger
Removing cell from execute callbacks in kernel.js.
r7223 Kernel.prototype._handle_payload = function (callbacks, payload) {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var l = payload.length;
// Payloads are handled by triggering events because we don't want the Kernel
// to depend on the Notebook or Pager classes.
for (var i=0; i<l; i++) {
if (payload[i].source === 'IPython.zmq.page.page') {
var data = {'text':payload[i].text}
$([IPython.events]).trigger('open_with_text.Pager', data);
Brian Granger
Removing cell from execute callbacks in kernel.js.
r7223 } else if (payload[i].source === 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input') {
if (callbacks.set_next_input !== undefined) {
callbacks.set_next_input(payload[i].text)
}
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 }
};
};
Kernel.prototype._handle_iopub_reply = function (e) {
Jason Grout
Add an optional metadata attribute to all messages and add a session-level default metadata attribute.
r7952 var reply = $.parseJSON(e.data);
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 var content = reply.content;
var msg_type = reply.header.msg_type;
Jason Grout
Make top-level metadata dictionary not optional.
r7955 var metadata = reply.metadata;
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 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
// callbacks to handle it.
return;
}
var output_types = ['stream','display_data','pyout','pyerr'];
if (output_types.indexOf(msg_type) >= 0) {
var cb = callbacks['output'];
if (cb !== undefined) {
Jason Grout
Add an optional metadata attribute to all messages and add a session-level default metadata attribute.
r7952 cb(msg_type, content, metadata);
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 }
} else if (msg_type === 'status') {
if (content.execution_state === 'busy') {
Matthias BUSSONNIER
change all trigger parameter to (event,data)
r8677 $([IPython.events]).trigger('status_busy.Kernel', {kernel: this});
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 } else if (content.execution_state === 'idle') {
Matthias BUSSONNIER
change all trigger parameter to (event,data)
r8677 $([IPython.events]).trigger('status_idle.Kernel', {kernel: this});
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 } else if (content.execution_state === 'dead') {
this.stop_channels();
Matthias BUSSONNIER
change all trigger parameter to (event,data)
r8677 $([IPython.events]).trigger('status_dead.Kernel', {kernel: this});
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 };
} else if (msg_type === 'clear_output') {
var cb = callbacks['clear_output'];
if (cb !== undefined) {
Jason Grout
Add an optional metadata attribute to all messages and add a session-level default metadata attribute.
r7952 cb(content, metadata);
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 }
};
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Kernel = Kernel;
return IPython;
}(IPython));