manual rebase static/services (add session.js)

pull/37/head
Zachary Sailer 13 years ago committed by MinRK
parent 0f52ffa756
commit 385ad6f509

@ -24,15 +24,16 @@ var IPython = (function (IPython) {
* A Kernel Class to communicate with the Python kernel
* @Class Kernel
*/
var Kernel = function (base_url) {
var Kernel = function (base_url, session_id) {
this.kernel_id = null;
this.session_id = session_id
this.shell_channel = null;
this.iopub_channel = null;
this.stdin_channel = null;
this.base_url = base_url;
this.running = false;
this.username = "username";
this.session_id = utils.uuid();
this.base_session_id = utils.uuid();
this._msg_callbacks = {};
if (typeof(WebSocket) !== 'undefined') {
@ -51,7 +52,7 @@ var IPython = (function (IPython) {
header : {
msg_id : utils.uuid(),
username : this.username,
session : this.session_id,
session : this.base_session_id,
msg_type : msg_type
},
metadata : {},
@ -72,17 +73,19 @@ var IPython = (function (IPython) {
* Start the Python kernel
* @method start
*/
Kernel.prototype.start = function (params) {
var that = this;
if (!this.running) {
var qs = $.param(params);
var url = this.base_url + '?' + qs;
$.post(url,
$.proxy(that._kernel_started,that),
'json'
);
};
};
Kernel.prototype.start = function (params) {
var that = this;
params = params || {};
params.session = this.session_id;
if (!this.running) {
var qs = $.param(params);
var url = this.base_url + '?' + qs;
$.post(url,
$.proxy(that._kernel_started,that),
'json'
);
};
};
/**
* Restart the python kernel.

@ -0,0 +1,88 @@
//----------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------
//============================================================================
// Notebook
//============================================================================
var IPython = (function (IPython) {
var Session = function(notebook_path, Notebook){
this.kernel = null;
this.kernel_id = null;
this.session_id = null;
this.notebook_path = notebook_path;
this.notebook = Notebook;
};
Session.prototype.start = function(){
var that = this
var qs = $.param({notebook_path:this.notebook_path});
var url = '/api/sessions' + '?' + qs;
$.post(url,
$.proxy(this.start_kernel, that),
'json'
);
};
// Kernel related things
/**
* Start a new kernel and set it on each code cell.
*
* @method start_kernel
*/
Session.prototype.start_kernel = function (json) {
this.session_id = json.session_id;
this.kernel_content = json.kernel;
var base_url = $('body').data('baseKernelUrl') + "api/kernels";
this.kernel = new IPython.Kernel(base_url, this.session_id);
// Now that the kernel has been created, tell the CodeCells about it.
this.kernel._kernel_started(this.kernel_content)
var ncells = this.notebook.ncells();
for (var i=0; i<ncells; i++) {
var cell = this.notebook.get_cell(i);
if (cell instanceof IPython.CodeCell) {
cell.set_kernel(this.kernel)
};
};
};
/**
* Prompt the user to restart the IPython kernel.
*
* @method restart_kernel
*/
Session.prototype.restart_kernel = function () {
var that = this;
var dialog = $('<div/>');
dialog.html('Do you want to restart the current kernel? You will lose all variables defined in it.');
$(document).append(dialog);
dialog.dialog({
resizable: false,
modal: true,
title: "Restart kernel or continue running?",
closeText: '',
buttons : {
"Restart": function () {
that.kernel.restart();
$(this).dialog('close');
},
"Continue running": function () {
$(this).dialog('close');
}
}
});
};
IPython.Session = Session;
return IPython;
}(IPython));
Loading…
Cancel
Save