##// END OF EJS Templates
Don't refer to global kernelselector object in Session
Thomas Kluyver -
Show More
@@ -12,6 +12,7 b' define(['
12 this.selector = selector;
12 this.selector = selector;
13 this.notebook = notebook;
13 this.notebook = notebook;
14 this.events = notebook.events;
14 this.events = notebook.events;
15 this.current_selection = notebook.default_kernel_name;
15 this.kernelspecs = {};
16 this.kernelspecs = {};
16 if (this.selector !== undefined) {
17 if (this.selector !== undefined) {
17 this.element = $(selector);
18 this.element = $(selector);
@@ -42,7 +43,7 b' define(['
42 };
43 };
43
44
44 KernelSelector.prototype.change_kernel = function(kernel_name) {
45 KernelSelector.prototype.change_kernel = function(kernel_name) {
45 if (kernel_name === this.notebook.kernel.name) {
46 if (kernel_name === this.current_selection) {
46 return;
47 return;
47 }
48 }
48 var ks = this.kernelspecs[kernel_name];
49 var ks = this.kernelspecs[kernel_name];
@@ -54,8 +55,19 b' define(['
54 KernelSelector.prototype.bind_events = function() {
55 KernelSelector.prototype.bind_events = function() {
55 var that = this;
56 var that = this;
56 this.events.on('spec_changed.Kernel', function(event, data) {
57 this.events.on('spec_changed.Kernel', function(event, data) {
58 that.current_selection = data.name;
57 that.element.find("#current_kernel_spec").find('.kernel_name').text(data.display_name);
59 that.element.find("#current_kernel_spec").find('.kernel_name').text(data.display_name);
58 });
60 });
61
62 this.events.on('started.Session', function(events, session) {
63 if (session.kernel_name !== that.current_selection) {
64 // If we created a 'python' session, we only know if it's Python
65 // 3 or 2 on the server's reply, so we fire the event again to
66 // set things up.
67 var ks = that.kernelspecs[session.kernel_name];
68 that.events.trigger('spec_changed.Kernel', ks);
69 }
70 });
59 };
71 };
60
72
61 return {'KernelSelector': KernelSelector};
73 return {'KernelSelector': KernelSelector};
@@ -13,6 +13,7 b' define(['
13 this.kernel = null;
13 this.kernel = null;
14 this.id = null;
14 this.id = null;
15 this.notebook = options.notebook;
15 this.notebook = options.notebook;
16 this.events = options.notebook.events;
16 this.name = options.notebook_name;
17 this.name = options.notebook_name;
17 this.path = options.notebook_path;
18 this.path = options.notebook_path;
18 this.kernel_name = options.kernel_name;
19 this.kernel_name = options.kernel_name;
@@ -92,13 +93,8 b' define(['
92 Session.prototype._handle_start_success = function (data, status, xhr) {
93 Session.prototype._handle_start_success = function (data, status, xhr) {
93 this.id = data.id;
94 this.id = data.id;
94 // If we asked for 'python', the response will have 'python3' or 'python2'.
95 // If we asked for 'python', the response will have 'python3' or 'python2'.
95 // In this case, fire the spec changed event again to update the name
96 this.kernel_name = data.kernel.name;
96 // and highlighting.
97 this.events.trigger('started.Session', this);
97 if (data.kernel.name !== this.kernel_name) {
98 this.kernel_name = data.kernel.name;
99 var ks = IPython.kernelselector.kernelspecs[this.kernel_name];
100 this.notebook.events.trigger('spec_changed.Kernel', ks);
101 }
102 var kernel_service_url = utils.url_path_join(this.base_url, "api/kernels");
98 var kernel_service_url = utils.url_path_join(this.base_url, "api/kernels");
103 this.kernel = new kernel.Kernel(kernel_service_url, this.ws_url, this.notebook, this.kernel_name);
99 this.kernel = new kernel.Kernel(kernel_service_url, this.ws_url, this.notebook, this.kernel_name);
104 this.kernel._kernel_started(data.kernel);
100 this.kernel._kernel_started(data.kernel);
General Comments 0
You need to be logged in to leave comments. Login now