Don't refer to global kernelselector object in Session

Thomas Kluyver 12 years ago
parent 2785e87b4b
commit 76477386ae

@ -12,6 +12,7 @@ define([
this.selector = selector;
this.notebook = notebook;
this.events = notebook.events;
this.current_selection = notebook.default_kernel_name;
this.kernelspecs = {};
if (this.selector !== undefined) {
this.element = $(selector);
@ -42,7 +43,7 @@ define([
};
KernelSelector.prototype.change_kernel = function(kernel_name) {
if (kernel_name === this.notebook.kernel.name) {
if (kernel_name === this.current_selection) {
return;
}
var ks = this.kernelspecs[kernel_name];
@ -54,8 +55,19 @@ define([
KernelSelector.prototype.bind_events = function() {
var that = this;
this.events.on('spec_changed.Kernel', function(event, data) {
that.current_selection = data.name;
that.element.find("#current_kernel_spec").find('.kernel_name').text(data.display_name);
});
this.events.on('started.Session', function(events, session) {
if (session.kernel_name !== that.current_selection) {
// If we created a 'python' session, we only know if it's Python
// 3 or 2 on the server's reply, so we fire the event again to
// set things up.
var ks = that.kernelspecs[session.kernel_name];
that.events.trigger('spec_changed.Kernel', ks);
}
});
};
return {'KernelSelector': KernelSelector};

@ -13,6 +13,7 @@ define([
this.kernel = null;
this.id = null;
this.notebook = options.notebook;
this.events = options.notebook.events;
this.name = options.notebook_name;
this.path = options.notebook_path;
this.kernel_name = options.kernel_name;
@ -92,13 +93,8 @@ define([
Session.prototype._handle_start_success = function (data, status, xhr) {
this.id = data.id;
// If we asked for 'python', the response will have 'python3' or 'python2'.
// In this case, fire the spec changed event again to update the name
// and highlighting.
if (data.kernel.name !== this.kernel_name) {
this.kernel_name = data.kernel.name;
var ks = IPython.kernelselector.kernelspecs[this.kernel_name];
this.notebook.events.trigger('spec_changed.Kernel', ks);
}
this.kernel_name = data.kernel.name;
this.events.trigger('started.Session', this);
var kernel_service_url = utils.url_path_join(this.base_url, "api/kernels");
this.kernel = new kernel.Kernel(kernel_service_url, this.ws_url, this.notebook, this.kernel_name);
this.kernel._kernel_started(data.kernel);

Loading…
Cancel
Save