Show More
@@ -21,6 +21,7 b' define([' | |||||
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 | Object.seal(this); | |||
24 | }; |
|
25 | }; | |
25 |
|
26 | |||
26 | KernelSelector.prototype.request_kernelspecs = function() { |
|
27 | KernelSelector.prototype.request_kernelspecs = function() { | |
@@ -61,10 +62,30 b' define([' | |||||
61 | }; |
|
62 | }; | |
62 |
|
63 | |||
63 | KernelSelector.prototype.change_kernel = function(kernel_name) { |
|
64 | KernelSelector.prototype.change_kernel = function(kernel_name) { | |
|
65 | /** | |||
|
66 | * TODO, have a methods to set kernel spec directly ? | |||
|
67 | **/ | |||
|
68 | var that = this; | |||
64 | if (kernel_name === this.current_selection) { |
|
69 | if (kernel_name === this.current_selection) { | |
65 | return; |
|
70 | return; | |
66 | } |
|
71 | } | |
67 | var ks = this.kernelspecs[kernel_name]; |
|
72 | var ks = this.kernelspecs[kernel_name]; | |
|
73 | var new_mode_url = 'kernelspecs/'+ks.name+'/kernel'; | |||
|
74 | ||||
|
75 | var css_url = this.notebook.base_url+new_mode_url+'.css'; | |||
|
76 | $.ajax({ | |||
|
77 | type: 'HEAD', | |||
|
78 | url: css_url, | |||
|
79 | success: function(){ | |||
|
80 | $('#kernel-css') | |||
|
81 | .attr('href',css_url); | |||
|
82 | }, | |||
|
83 | error:function(){ | |||
|
84 | console.warn(new_mode_url+' does not provide custom URL, you might see a 404 error that shoudl not prevent '+ | |||
|
85 | ' the Jupyter notebook from working :' ,css_url ); | |||
|
86 | } | |||
|
87 | }); | |||
|
88 | ||||
68 | try { |
|
89 | try { | |
69 | this.notebook.start_session(kernel_name); |
|
90 | this.notebook.start_session(kernel_name); | |
70 | } catch (e) { |
|
91 | } catch (e) { | |
@@ -78,6 +99,30 b' define([' | |||||
78 | return; |
|
99 | return; | |
79 | } |
|
100 | } | |
80 | this.events.trigger('spec_changed.Kernel', ks); |
|
101 | this.events.trigger('spec_changed.Kernel', ks); | |
|
102 | ||||
|
103 | ||||
|
104 | // load new mode kernel.js if exist | |||
|
105 | require([new_mode_url], | |||
|
106 | // if new mode has custom.js | |||
|
107 | function(new_mode){ | |||
|
108 | that.lock_switch(); | |||
|
109 | if(new_mode && new_mode.onload){ | |||
|
110 | new_mode.onload(); | |||
|
111 | } else { | |||
|
112 | console.warn("The current kernel seem to define a kernel.js file; though this file does"+ | |||
|
113 | "not contain any asynchronous module definition. This is undefined behavior"+ | |||
|
114 | "which is not recommeneded"); | |||
|
115 | } | |||
|
116 | }, | |||
|
117 | function(err){ | |||
|
118 | // if new mode does not have custom.js | |||
|
119 | console.warn('Any above 404 on '+new_mode_url+'.js is normal'); | |||
|
120 | } | |||
|
121 | ); | |||
|
122 | }; | |||
|
123 | ||||
|
124 | KernelSelector.prototype.lock_switch = function() { | |||
|
125 | console.warn('switching kernel is not guarantied to work !'); | |||
81 | }; |
|
126 | }; | |
82 |
|
127 | |||
83 | KernelSelector.prototype.bind_events = function() { |
|
128 | KernelSelector.prototype.bind_events = function() { |
@@ -113,6 +113,7 b' require([' | |||||
113 | notification_area.init_notification_widgets(); |
|
113 | notification_area.init_notification_widgets(); | |
114 | var kernel_selector = new kernelselector.KernelSelector( |
|
114 | var kernel_selector = new kernelselector.KernelSelector( | |
115 | '#kernel_selector_widget', notebook); |
|
115 | '#kernel_selector_widget', notebook); | |
|
116 | notebook.set_kernelselector(kernel_selector); | |||
116 |
|
117 | |||
117 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ |
|
118 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ | |
118 | '<span id="test2" style="font-weight: bold;">x</span>'+ |
|
119 | '<span id="test2" style="font-weight: bold;">x</span>'+ |
@@ -1864,7 +1864,14 b' define([' | |||||
1864 | // Trigger an event changing the kernel spec - this will set the default |
|
1864 | // Trigger an event changing the kernel spec - this will set the default | |
1865 | // codemirror mode |
|
1865 | // codemirror mode | |
1866 | if (this.metadata.kernelspec !== undefined) { |
|
1866 | if (this.metadata.kernelspec !== undefined) { | |
1867 | this.events.trigger('spec_changed.Kernel', this.metadata.kernelspec); |
|
1867 | // TODO shoudl probably not trigger here, | |
|
1868 | // should call the kernel selector, or custom.{js|css} not loaded. | |||
|
1869 | if(this.kernel_selector){ | |||
|
1870 | // technically not perfect, we should check that the kernelspec matches | |||
|
1871 | this.kernel_selector.change_kernel(this.metadata.kernelspec.name); | |||
|
1872 | } else { | |||
|
1873 | console.log('do not have handle on kernnel_selector'); | |||
|
1874 | } | |||
1868 | } |
|
1875 | } | |
1869 |
|
1876 | |||
1870 | // Set the codemirror mode from language_info metadata |
|
1877 | // Set the codemirror mode from language_info metadata | |
@@ -2308,6 +2315,10 b' define([' | |||||
2308 | this.events.trigger('notebook_loaded.Notebook'); |
|
2315 | this.events.trigger('notebook_loaded.Notebook'); | |
2309 | }; |
|
2316 | }; | |
2310 |
|
2317 | |||
|
2318 | Notebook.prototype.set_kernelselector = function(k_selector){ | |||
|
2319 | this.kernel_selector = k_selector; | |||
|
2320 | }; | |||
|
2321 | ||||
2311 | /** |
|
2322 | /** | |
2312 | * Failure callback for loading a notebook from the server. |
|
2323 | * Failure callback for loading a notebook from the server. | |
2313 | * |
|
2324 | * |
@@ -17,6 +17,7 b' window.mathjax_url = "{{mathjax_url}}";' | |||||
17 | {{super()}} |
|
17 | {{super()}} | |
18 |
|
18 | |||
19 | <link rel="stylesheet" href="{{ static_url("notebook/css/override.css") }}" type="text/css" /> |
|
19 | <link rel="stylesheet" href="{{ static_url("notebook/css/override.css") }}" type="text/css" /> | |
|
20 | <link rel="stylesheet" href="" id='kernel-css' type="text/css" /> | |||
20 |
|
21 | |||
21 | {% endblock %} |
|
22 | {% endblock %} | |
22 |
|
23 |
@@ -24,6 +24,7 b'' | |||||
24 | baseUrl: '{{static_url("", include_version=False)}}', |
|
24 | baseUrl: '{{static_url("", include_version=False)}}', | |
25 | paths: { |
|
25 | paths: { | |
26 | nbextensions : '{{ base_url }}nbextensions', |
|
26 | nbextensions : '{{ base_url }}nbextensions', | |
|
27 | kernelspecs : '{{ base_url }}kernelspecs', | |||
27 | underscore : 'components/underscore/underscore-min', |
|
28 | underscore : 'components/underscore/underscore-min', | |
28 | backbone : 'components/backbone/backbone-min', |
|
29 | backbone : 'components/backbone/backbone-min', | |
29 | jquery: 'components/jquery/jquery.min', |
|
30 | jquery: 'components/jquery/jquery.min', |
General Comments 0
You need to be logged in to leave comments.
Login now