Show More
@@ -55,15 +55,23 b' define([' | |||||
55 | } |
|
55 | } | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 |
KernelSelector.prototype.change |
|
58 | KernelSelector.prototype._spec_changed = function (event, ks) { | |
59 | /** |
|
59 | /** event handler for spec_changed */ | |
60 | * TODO, have a methods to set kernel spec directly ? |
|
60 | ||
61 | **/ |
|
61 | // update selection | |
62 |
|
|
62 | this.current_selection = ks.name; | |
63 | return; |
|
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 | var css_url = ks.resources['kernel.css']; |
|
75 | var css_url = ks.resources['kernel.css']; | |
68 | if (css_url) { |
|
76 | if (css_url) { | |
69 | $('#kernel-css').attr('href', css_url); |
|
77 | $('#kernel-css').attr('href', css_url); | |
@@ -71,20 +79,7 b' define([' | |||||
71 | $('#kernel-css').attr('href', ''); |
|
79 | $('#kernel-css').attr('href', ''); | |
72 | } |
|
80 | } | |
73 |
|
81 | |||
74 | try { |
|
82 | // load kernel js | |
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 |
|
||||
88 | if (ks.resources['kernel.js']) { |
|
83 | if (ks.resources['kernel.js']) { | |
89 | require([ks.resources['kernel.js']], |
|
84 | require([ks.resources['kernel.js']], | |
90 | function (kernel_mod) { |
|
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 | KernelSelector.prototype.lock_switch = function() { |
|
125 | KernelSelector.prototype.lock_switch = function() { | |
@@ -112,17 +131,7 b' define([' | |||||
112 |
|
131 | |||
113 | KernelSelector.prototype.bind_events = function() { |
|
132 | KernelSelector.prototype.bind_events = function() { | |
114 | var that = this; |
|
133 | var that = this; | |
115 | var logo_img = this.element.find("img.current_kernel_logo"); |
|
134 | this.events.on('spec_changed.Kernel', $.proxy(this._spec_changed, this)); | |
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 | }); |
|
|||
126 |
|
135 | |||
127 | this.events.on('kernel_created.Session', function(event, data) { |
|
136 | this.events.on('kernel_created.Session', function (event, data) { | |
128 | if (data.kernel.name !== that.current_selection) { |
|
137 | if (data.kernel.name !== that.current_selection) { | |
@@ -134,6 +143,7 b' define([' | |||||
134 | } |
|
143 | } | |
135 | }); |
|
144 | }); | |
136 |
|
145 | |||
|
146 | var logo_img = this.element.find("img.current_kernel_logo"); | |||
137 | logo_img.on("load", function() { |
|
147 | logo_img.on("load", function() { | |
138 | logo_img.show(); |
|
148 | logo_img.show(); | |
139 | }); |
|
149 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now