##// END OF EJS Templates
Adding keyboard shortcut help dialog.
Adding keyboard shortcut help dialog.

File last commit:

r4613:486e84fb
r4646:7e2eee18
Show More
kernel.js
156 lines | 4.6 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
//============================================================================
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;
var Kernel = function () {
this.kernel_id = null;
this.base_url = "/kernels";
this.kernel_url = null;
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.shell_channel = null;
this.iopub_channel = null;
this.running = false;
Brian E. Granger
Better WebSocket detection added.
r4612 if (typeof(WebSocket) !== 'undefined') {
this.WebSocket = WebSocket
} else if (typeof(MozWebSocket) !== 'undefined') {
Brian E. Granger
Adding code to handle MozWebSocket for FF 6.
r4611 this.WebSocket = MozWebSocket
} else {
Brian E. Granger
Better alert message if no WebSockets are detected.
r4613 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 };
Kernel.prototype.get_msg = function (msg_type, content) {
var msg = {
header : {
msg_id : utils.uuid(),
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 username : "username",
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 session: this.session_id,
msg_type : msg_type
},
content : content,
parent_header : {}
};
return msg;
}
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 Kernel.prototype.start = function (notebook_id, callback) {
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});
$.post(this.base_url + '?' + qs,
function (kernel_id) {
that._handle_start_kernel(kernel_id, callback);
},
'json'
);
};
};
Kernel.prototype.restart = function (callback) {
IPython.kernel_status_widget.status_restarting();
var url = this.kernel_url + "/restart";
var that = this;
if (this.running) {
this.stop_channels();
$.post(url,
function (kernel_id) {
that._handle_start_kernel(kernel_id, callback);
},
'json'
);
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
WebSocket url is now passed to browser when a kernel is started.
r4572 Kernel.prototype._handle_start_kernel = function (json, callback) {
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 E. Granger
Using $.proxy to clean up callbacks.
r4353 callback();
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 IPython.kernel_status_widget.status_idle();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 Kernel.prototype.start_channels = function () {
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");
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
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 Kernel.prototype.stop_channels = function () {
if (this.shell_channel !== null) {
this.shell_channel.close();
this.shell_channel = null;
};
if (this.iopub_channel !== null) {
this.iopub_channel.close();
this.iopub_channel = null;
};
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Kernel.prototype.execute = function (code) {
var content = {
code : code,
silent : false,
user_variables : [],
user_expressions : {}
};
var msg = this.get_msg("execute_request", content);
this.shell_channel.send(JSON.stringify(msg));
return msg.header.msg_id;
}
Brian Granger
Added complete method of JS kernel object.
r4388 Kernel.prototype.complete = function (line, cursor_pos) {
var content = {
text : '',
line : line,
cursor_pos : cursor_pos
};
var msg = this.get_msg("complete_request", content);
this.shell_channel.send(JSON.stringify(msg));
return msg.header.msg_id;
}
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) {
$.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,
type : "DELETE",
};
$.ajax(this.kernel_url, settings);
Brian E. Granger
Using beforeunload to save at exit and kill the kernel.
r4496 };
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Kernel = Kernel;
return IPython;
}(IPython));