Show More
@@ -26,7 +26,7 b' define([' | |||||
26 | IPython.kernelselector = this; |
|
26 | IPython.kernelselector = this; | |
27 | this._finish_load = null; |
|
27 | this._finish_load = null; | |
28 | this._loaded = false; |
|
28 | this._loaded = false; | |
29 |
this.loaded = new Promise(function(resolve |
|
29 | this.loaded = new Promise(function(resolve) { | |
30 | that._finish_load = resolve; |
|
30 | that._finish_load = resolve; | |
31 | }); |
|
31 | }); | |
32 |
|
32 | |||
@@ -38,16 +38,12 b' define([' | |||||
38 | utils.promising_ajax(url).then($.proxy(this._got_kernelspecs, this)); |
|
38 | utils.promising_ajax(url).then($.proxy(this._got_kernelspecs, this)); | |
39 | }; |
|
39 | }; | |
40 |
|
40 | |||
41 | KernelSelector.prototype._got_kernelspecs = function(data) { |
|
41 | var _sorted_names = function(kernelspecs) { | |
42 | var that = this; |
|
42 | // sort kernel names | |
43 | this.kernelspecs = data.kernelspecs; |
|
43 | return Object.keys(kernelspecs).sort(function (a, b) { | |
44 | var change_kernel_submenu = $("#menu-change-kernel-submenu"); |
|
|||
45 | var new_notebook_submenu = $("#menu-new-notebook-submenu"); |
|
|||
46 |
|
||||
47 | var keys = Object.keys(data.kernelspecs).sort(function (a, b) { |
|
|||
48 | // sort by display_name |
|
44 | // sort by display_name | |
49 |
var da = |
|
45 | var da = kernelspecs[a].spec.display_name; | |
50 |
var db = |
|
46 | var db = kernelspecs[b].spec.display_name; | |
51 | if (da === db) { |
|
47 | if (da === db) { | |
52 | return 0; |
|
48 | return 0; | |
53 | } else if (da > db) { |
|
49 | } else if (da > db) { | |
@@ -56,6 +52,14 b' define([' | |||||
56 | return -1; |
|
52 | return -1; | |
57 | } |
|
53 | } | |
58 | }); |
|
54 | }); | |
|
55 | }; | |||
|
56 | ||||
|
57 | KernelSelector.prototype._got_kernelspecs = function(data) { | |||
|
58 | var that = this; | |||
|
59 | this.kernelspecs = data.kernelspecs; | |||
|
60 | var change_kernel_submenu = $("#menu-change-kernel-submenu"); | |||
|
61 | var new_notebook_submenu = $("#menu-new-notebook-submenu"); | |||
|
62 | var keys = _sorted_names(data.kernelspecs); | |||
59 |
|
63 | |||
60 | keys.map(function (key) { |
|
64 | keys.map(function (key) { | |
61 | // Create the Kernel > Change kernel submenu |
|
65 | // Create the Kernel > Change kernel submenu | |
@@ -160,7 +164,7 b' define([' | |||||
160 | /** set the kernel by name, ensuring kernelspecs have been loaded, first |
|
164 | /** set the kernel by name, ensuring kernelspecs have been loaded, first | |
161 |
|
165 | |||
162 | kernel can be just a kernel name, or a notebook kernelspec metadata |
|
166 | kernel can be just a kernel name, or a notebook kernelspec metadata | |
163 |
(name, |
|
167 | (name, language_name, display_name). | |
164 | */ |
|
168 | */ | |
165 | var that = this; |
|
169 | var that = this; | |
166 | if (typeof selected === 'string') { |
|
170 | if (typeof selected === 'string') { | |
@@ -183,18 +187,28 b' define([' | |||||
183 | // only trigger event if value changed |
|
187 | // only trigger event if value changed | |
184 | return; |
|
188 | return; | |
185 | } |
|
189 | } | |
186 |
var ks = this.kernelspecs |
|
190 | var kernelspecs = this.kernelspecs; | |
|
191 | var ks = kernelspecs[selected.name]; | |||
187 | if (ks === undefined) { |
|
192 | if (ks === undefined) { | |
188 | if (selected.project_name && selected.project_name.length > 0) { |
|
193 | var available = _sorted_names(kernelspecs); | |
189 | $.map(this.kernelspecs, function (k) { |
|
194 | var matches = []; | |
190 |
|
|
195 | if (selected.language_name && selected.language_name.length > 0) { | |
191 | ks = k; |
|
196 | $.map(available, function (name) { | |
|
197 | if (kernelspecs[name].spec.language_name.toLowerCase() === selected.language_name.toLowerCase()) { | |||
|
198 | matches.push(name); | |||
192 | } |
|
199 | } | |
193 | }); |
|
200 | }); | |
194 | } |
|
201 | } | |
|
202 | if (matches.length === 1) { | |||
|
203 | ks = kernelspecs[matches[0]]; | |||
|
204 | } | |||
195 | // if still undefined, trigger failure event |
|
205 | // if still undefined, trigger failure event | |
196 | if (ks === undefined) { |
|
206 | if (ks === undefined) { | |
197 |
this.events.trigger("spec_not_found.Kernel", |
|
207 | this.events.trigger("spec_not_found.Kernel", { | |
|
208 | selected: selected, | |||
|
209 | matches: matches, | |||
|
210 | available: available, | |||
|
211 | }); | |||
198 | return; |
|
212 | return; | |
199 | } |
|
213 | } | |
200 | } |
|
214 | } | |
@@ -210,15 +224,22 b' define([' | |||||
210 | var that = this; |
|
224 | var that = this; | |
211 | var select = $("<select>").addClass('form-control'); |
|
225 | var select = $("<select>").addClass('form-control'); | |
212 | console.warn("Kernelspec not found:", data); |
|
226 | console.warn("Kernelspec not found:", data); | |
213 | $.map(this.kernelspecs, function (ks) { |
|
227 | var names; | |
|
228 | if (data.matches.length > 1) { | |||
|
229 | names = data.matches; | |||
|
230 | } else { | |||
|
231 | names = data.available; | |||
|
232 | } | |||
|
233 | $.map(names, function (name) { | |||
|
234 | var ks = that.kernelspecs[name]; | |||
214 | select.append( |
|
235 | select.append( | |
215 | $('<option/>').attr('value', ks.name).text(ks.spec.display_name) |
|
236 | $('<option/>').attr('value', ks.name).text(ks.spec.display_name || ks.name) | |
216 | ); |
|
237 | ); | |
217 | }); |
|
238 | }); | |
218 |
|
239 | |||
219 | var body = $("<form>").addClass("form-inline").append( |
|
240 | var body = $("<form>").addClass("form-inline").append( | |
220 | $("<span>").text( |
|
241 | $("<span>").text( | |
221 | "I couldn't find a kernel matching " + (data.display_name || data.name) + "." + |
|
242 | "I couldn't find a kernel matching " + (data.selected.display_name || data.name) + "." + | |
222 | " Please select a kernel:" |
|
243 | " Please select a kernel:" | |
223 | ) |
|
244 | ) | |
224 | ).append(select); |
|
245 | ).append(select); |
@@ -249,7 +249,7 b' define([' | |||||
249 | that.metadata.kernelspec = { |
|
249 | that.metadata.kernelspec = { | |
250 | name: data.name, |
|
250 | name: data.name, | |
251 | display_name: data.spec.display_name, |
|
251 | display_name: data.spec.display_name, | |
252 |
|
|
252 | language_name: data.spec.language_name, | |
253 | }; |
|
253 | }; | |
254 | // start session if the current session isn't already correct |
|
254 | // start session if the current session isn't already correct | |
255 | if (!(this.session && this.session.kernel && this.session.kernel.name === data.name)) { |
|
255 | if (!(this.session && this.session.kernel && this.session.kernel.name === data.name)) { |
@@ -36,7 +36,7 b' def _pythonfirst(s):' | |||||
36 | class KernelSpec(HasTraits): |
|
36 | class KernelSpec(HasTraits): | |
37 | argv = List() |
|
37 | argv = List() | |
38 | display_name = Unicode() |
|
38 | display_name = Unicode() | |
39 |
|
|
39 | language_name = Unicode() | |
40 | env = Dict() |
|
40 | env = Dict() | |
41 | resource_dir = Unicode() |
|
41 | resource_dir = Unicode() | |
42 |
|
42 | |||
@@ -55,7 +55,7 b' class KernelSpec(HasTraits):' | |||||
55 | d = dict(argv=self.argv, |
|
55 | d = dict(argv=self.argv, | |
56 | env=self.env, |
|
56 | env=self.env, | |
57 | display_name=self.display_name, |
|
57 | display_name=self.display_name, | |
58 |
|
|
58 | language_name=self.language_name, | |
59 | ) |
|
59 | ) | |
60 |
|
60 | |||
61 | return d |
|
61 | return d | |
@@ -114,7 +114,7 b' class KernelSpecManager(HasTraits):' | |||||
114 | return { |
|
114 | return { | |
115 | 'argv': make_ipkernel_cmd(), |
|
115 | 'argv': make_ipkernel_cmd(), | |
116 | 'display_name': 'Python %i' % (3 if PY3 else 2), |
|
116 | 'display_name': 'Python %i' % (3 if PY3 else 2), | |
117 |
' |
|
117 | 'language_name': 'python', | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | @property |
|
120 | @property |
General Comments 0
You need to be logged in to leave comments.
Login now