##// END OF EJS Templates
logo-64 -> logo-64x64
Thomas Kluyver -
Show More
@@ -1,111 +1,111 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 define([
4 define([
5 'base/js/namespace',
5 'base/js/namespace',
6 'jquery',
6 'jquery',
7 'base/js/utils',
7 'base/js/utils',
8 ], function(IPython, $, utils) {
8 ], function(IPython, $, utils) {
9 "use strict";
9 "use strict";
10
10
11 var KernelSelector = function(selector, notebook) {
11 var KernelSelector = function(selector, notebook) {
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 = null;
15 this.current_selection = null;
16 this.kernelspecs = {};
16 this.kernelspecs = {};
17 if (this.selector !== undefined) {
17 if (this.selector !== undefined) {
18 this.element = $(selector);
18 this.element = $(selector);
19 this.request_kernelspecs();
19 this.request_kernelspecs();
20 }
20 }
21 this.bind_events();
21 this.bind_events();
22 // Make the object globally available for user convenience & inspection
22 // Make the object globally available for user convenience & inspection
23 IPython.kernelselector = this;
23 IPython.kernelselector = this;
24 };
24 };
25
25
26 KernelSelector.prototype.request_kernelspecs = function() {
26 KernelSelector.prototype.request_kernelspecs = function() {
27 var url = utils.url_join_encode(this.notebook.base_url, 'api/kernelspecs');
27 var url = utils.url_join_encode(this.notebook.base_url, 'api/kernelspecs');
28 utils.promising_ajax(url).then($.proxy(this._got_kernelspecs, this));
28 utils.promising_ajax(url).then($.proxy(this._got_kernelspecs, this));
29 };
29 };
30
30
31 KernelSelector.prototype._got_kernelspecs = function(data) {
31 KernelSelector.prototype._got_kernelspecs = function(data) {
32 this.kernelspecs = data.kernelspecs;
32 this.kernelspecs = data.kernelspecs;
33 var menu = this.element.find("#kernel_selector");
33 var menu = this.element.find("#kernel_selector");
34 var change_kernel_submenu = $("#menu-change-kernel-submenu");
34 var change_kernel_submenu = $("#menu-change-kernel-submenu");
35 var keys = Object.keys(data.kernelspecs).sort(function (a, b) {
35 var keys = Object.keys(data.kernelspecs).sort(function (a, b) {
36 // sort by display_name
36 // sort by display_name
37 var da = data.kernelspecs[a].display_name;
37 var da = data.kernelspecs[a].display_name;
38 var db = data.kernelspecs[b].display_name;
38 var db = data.kernelspecs[b].display_name;
39 if (da === db) {
39 if (da === db) {
40 return 0;
40 return 0;
41 } else if (da > db) {
41 } else if (da > db) {
42 return 1;
42 return 1;
43 } else {
43 } else {
44 return -1;
44 return -1;
45 }
45 }
46 });
46 });
47 for (var i = 0; i < keys.length; i++) {
47 for (var i = 0; i < keys.length; i++) {
48 var ks = this.kernelspecs[keys[i]];
48 var ks = this.kernelspecs[keys[i]];
49 var ksentry = $("<li>").attr("id", "kernel-" +ks.name).append($('<a>')
49 var ksentry = $("<li>").attr("id", "kernel-" +ks.name).append($('<a>')
50 .attr('href', '#')
50 .attr('href', '#')
51 .click($.proxy(this.change_kernel, this, ks.name))
51 .click($.proxy(this.change_kernel, this, ks.name))
52 .text(ks.display_name));
52 .text(ks.display_name));
53 menu.append(ksentry);
53 menu.append(ksentry);
54
54
55 var ks_submenu_entry = $("<li>").attr("id", "kernel-submenu-"+ks.name).append($('<a>')
55 var ks_submenu_entry = $("<li>").attr("id", "kernel-submenu-"+ks.name).append($('<a>')
56 .attr('href', '#')
56 .attr('href', '#')
57 .click($.proxy(this.change_kernel, this, ks.name))
57 .click($.proxy(this.change_kernel, this, ks.name))
58 .text(ks.display_name));
58 .text(ks.display_name));
59 change_kernel_submenu.append(ks_submenu_entry);
59 change_kernel_submenu.append(ks_submenu_entry);
60 }
60 }
61 };
61 };
62
62
63 KernelSelector.prototype.change_kernel = function(kernel_name) {
63 KernelSelector.prototype.change_kernel = function(kernel_name) {
64 if (kernel_name === this.current_selection) {
64 if (kernel_name === this.current_selection) {
65 return;
65 return;
66 }
66 }
67 var ks = this.kernelspecs[kernel_name];
67 var ks = this.kernelspecs[kernel_name];
68 try {
68 try {
69 this.notebook.start_session(kernel_name);
69 this.notebook.start_session(kernel_name);
70 } catch (e) {
70 } catch (e) {
71 if (e.name === 'SessionAlreadyStarting') {
71 if (e.name === 'SessionAlreadyStarting') {
72 console.log("Cannot change kernel while waiting for pending session start.");
72 console.log("Cannot change kernel while waiting for pending session start.");
73 } else {
73 } else {
74 // unhandled error
74 // unhandled error
75 throw e;
75 throw e;
76 }
76 }
77 // only trigger spec_changed if change was successful
77 // only trigger spec_changed if change was successful
78 return;
78 return;
79 }
79 }
80 this.events.trigger('spec_changed.Kernel', ks);
80 this.events.trigger('spec_changed.Kernel', ks);
81 };
81 };
82
82
83 KernelSelector.prototype.bind_events = function() {
83 KernelSelector.prototype.bind_events = function() {
84 var that = this;
84 var that = this;
85 this.events.on('spec_changed.Kernel', function(event, data) {
85 this.events.on('spec_changed.Kernel', function(event, data) {
86 that.current_selection = data.name;
86 that.current_selection = data.name;
87 that.element.find("#current_kernel_spec").find('.kernel_name').text(data.display_name);
87 that.element.find("#current_kernel_spec").find('.kernel_name').text(data.display_name);
88 that.element.find("#current_kernel_logo").attr("src", "/kernelspecs/"+data.name+"/logo-64.png");
88 that.element.find("#current_kernel_logo").attr("src", "/kernelspecs/"+data.name+"/logo-64x64.png");
89 });
89 });
90
90
91 this.events.on('kernel_created.Session', function(event, data) {
91 this.events.on('kernel_created.Session', function(event, data) {
92 if (data.kernel.name !== that.current_selection) {
92 if (data.kernel.name !== that.current_selection) {
93 // If we created a 'python' session, we only know if it's Python
93 // If we created a 'python' session, we only know if it's Python
94 // 3 or 2 on the server's reply, so we fire the event again to
94 // 3 or 2 on the server's reply, so we fire the event again to
95 // set things up.
95 // set things up.
96 var ks = that.kernelspecs[data.kernel.name];
96 var ks = that.kernelspecs[data.kernel.name];
97 that.events.trigger('spec_changed.Kernel', ks);
97 that.events.trigger('spec_changed.Kernel', ks);
98 }
98 }
99 });
99 });
100
100
101 var logo_img = this.element.find("#current_kernel_logo")
101 var logo_img = this.element.find("#current_kernel_logo")
102 logo_img.on("load", function() {
102 logo_img.on("load", function() {
103 logo_img.show();
103 logo_img.show();
104 });
104 });
105 logo_img.on("error", function() {
105 logo_img.on("error", function() {
106 logo_img.hide();
106 logo_img.hide();
107 });
107 });
108 };
108 };
109
109
110 return {'KernelSelector': KernelSelector};
110 return {'KernelSelector': KernelSelector};
111 });
111 });
1 NO CONTENT: file renamed from IPython/kernel/resources/logo-32.png to IPython/kernel/resources/logo-32x32.png
NO CONTENT: file renamed from IPython/kernel/resources/logo-32.png to IPython/kernel/resources/logo-32x32.png
1 NO CONTENT: file renamed from IPython/kernel/resources/logo-64.png to IPython/kernel/resources/logo-64x64.png
NO CONTENT: file renamed from IPython/kernel/resources/logo-64.png to IPython/kernel/resources/logo-64x64.png
General Comments 0
You need to be logged in to leave comments. Login now