##// END OF EJS Templates
load kernel js, css, logo on spec_changed event...
Min RK -
Show More
@@ -54,37 +54,32 b' define(['
54 54 change_kernel_submenu.append(ks_submenu_entry);
55 55 }
56 56 };
57
58 KernelSelector.prototype.change_kernel = function(kernel_name) {
59 /**
60 * TODO, have a methods to set kernel spec directly ?
61 **/
62 if (kernel_name === this.current_selection) {
63 return;
57
58 KernelSelector.prototype._spec_changed = function (event, ks) {
59 /** event handler for spec_changed */
60
61 // update selection
62 this.current_selection = ks.name;
63
64 // load logo
65 var logo_img = this.element.find("img.current_kernel_logo");
66 $("#kernel_indicator").find('.kernel_indicator_name').text(ks.spec.display_name);
67 if (ks.resources['logo-64x64']) {
68 logo_img.attr("src", ks.resources['logo-64x64']);
69 logo_img.show();
70 } else {
71 logo_img.hide();
64 72 }
65 var ks = this.kernelspecs[kernel_name];
66 73
74 // load kernel css
67 75 var css_url = ks.resources['kernel.css'];
68 76 if (css_url) {
69 77 $('#kernel-css').attr('href', css_url);
70 78 } else {
71 79 $('#kernel-css').attr('href', '');
72 80 }
73
74 try {
75 this.notebook.start_session(kernel_name);
76 } catch (e) {
77 if (e.name === 'SessionAlreadyStarting') {
78 console.log("Cannot change kernel while waiting for pending session start.");
79 } else {
80 // unhandled error
81 throw e;
82 }
83 // only trigger spec_changed if change was successful
84 return;
85 }
86 this.events.trigger('spec_changed.Kernel', ks);
87 81
82 // load kernel js
88 83 if (ks.resources['kernel.js']) {
89 84 require([ks.resources['kernel.js']],
90 85 function (kernel_mod) {
@@ -100,7 +95,31 b' define(['
100 95 }
101 96 );
102 97 }
98 };
103 99
100 KernelSelector.prototype.change_kernel = function (kernel_name) {
101 /**
102 * TODO, have a methods to set kernel spec directly ?
103 **/
104 if (kernel_name === this.current_selection) {
105 return;
106 }
107 var ks = this.kernelspecs[kernel_name];
108
109 try {
110 this.notebook.start_session(kernel_name);
111 } catch (e) {
112 if (e.name === 'SessionAlreadyStarting') {
113 console.log("Cannot change kernel while waiting for pending session start.");
114 } else {
115 // unhandled error
116 throw e;
117 }
118 // only trigger spec_changed if change was successful
119 return;
120 }
121 console.log('spec', kernel_name, ks);
122 this.events.trigger('spec_changed.Kernel', ks);
104 123 };
105 124
106 125 KernelSelector.prototype.lock_switch = function() {
@@ -112,19 +131,9 b' define(['
112 131
113 132 KernelSelector.prototype.bind_events = function() {
114 133 var that = this;
115 var logo_img = this.element.find("img.current_kernel_logo");
116 this.events.on('spec_changed.Kernel', function(event, data) {
117 that.current_selection = data.name;
118 $("#kernel_indicator").find('.kernel_indicator_name').text(data.spec.display_name);
119 if (data.resources['logo-64x64']) {
120 logo_img.attr("src", data.resources['logo-64x64']);
121 logo_img.show();
122 } else {
123 logo_img.hide();
124 }
125 });
134 this.events.on('spec_changed.Kernel', $.proxy(this._spec_changed, this));
126 135
127 this.events.on('kernel_created.Session', function(event, data) {
136 this.events.on('kernel_created.Session', function (event, data) {
128 137 if (data.kernel.name !== that.current_selection) {
129 138 // If we created a 'python' session, we only know if it's Python
130 139 // 3 or 2 on the server's reply, so we fire the event again to
@@ -134,6 +143,7 b' define(['
134 143 }
135 144 });
136 145
146 var logo_img = this.element.find("img.current_kernel_logo");
137 147 logo_img.on("load", function() {
138 148 logo_img.show();
139 149 });
General Comments 0
You need to be logged in to leave comments. Login now