##// END OF EJS Templates
Merge pull request #1490 from minrk/raw...
Merge pull request #1490 from minrk/raw rename plaintext cell -> raw cell Raw cells should be *untransformed* when writing various output formats, as the point of them is to let users pass through IPython to their rendered document format (rst, latex, etc.). This is different from what is the logical meaning of 'plaintext', which would suggest that the contents should be preserved as unformatted plaintext (e.g. in a `<pre>` tag, or literal block). In the UI, these cells will be displayed as 'Raw Text'. WARNING: any existing v3 notebooks which use plaintext cells, when read in by versions after this merge, will silently rename those cells to 'raw'. But if such a notebook is uploaded into a pre-merge IPython, cells labeled as 'raw' will simply *not be displayed*.

File last commit:

r6061:cddb82ef
r6480:a0e0f391 merge
Show More
kernel.js
237 lines | 7.5 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;
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.shell_channel = null;
this.iopub_channel = null;
Brian E. Granger
Updating JS URL scheme to use embedded data....
r5106 this.base_url = $('body').data('baseKernelUrl') + "kernels";
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 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 };
Kernel.prototype.get_msg = function (msg_type, content) {
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
},
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
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});
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 E. Granger
Major refactor of kernel connection management in the notebook....
r4545 function (kernel_id) {
that._handle_start_kernel(kernel_id, callback);
},
'json'
);
};
};
Kernel.prototype.restart = function (callback) {
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.events]).trigger('status_restarting.Kernel');
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 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
Implemented module and namespace pattern in js notebook.
r4352 };
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 {
Brian Granger
Major refactoring of saving, notification....
r6047 msg = "Websocket connection closed unexpectedly." +
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 " The kernel will no longer be responsive.";
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');
}
}
});
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
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
ws_closed_early = function(evt){
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 };
MinRK
alert client on failed and lost web socket connections...
r5253 ws_closed_late = function(evt){
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
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;
};
};
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 Kernel.prototype.object_info_request = function (objname) {
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(),
};
var msg = this.get_msg("object_info_request", content);
this.shell_channel.send(JSON.stringify(msg));
return msg.header.msg_id;
}
return;
Matthias BUSSONNIER
Add Tootip to notebook....
r5397 }
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 : [],
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 };
var msg = this.get_msg("execute_request", content);
this.shell_channel.send(JSON.stringify(msg));
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
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;
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) {
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.events]).trigger('status_interrupting.Kernel');
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 E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Kernel = Kernel;
return IPython;
}(IPython));