##// END OF EJS Templates
Merge pull request #7088 from Carreau/kernel.js...
Min RK -
r19561:da81b943 merge
parent child Browse files
Show More
@@ -11,6 +11,7 b' define(['
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.notebook.set_kernelselector(this);
14 this.events = notebook.events;
15 this.events = notebook.events;
15 this.current_selection = null;
16 this.current_selection = null;
16 this.kernelspecs = {};
17 this.kernelspecs = {};
@@ -21,6 +22,7 b' define(['
21 this.bind_events();
22 this.bind_events();
22 // Make the object globally available for user convenience & inspection
23 // Make the object globally available for user convenience & inspection
23 IPython.kernelselector = this;
24 IPython.kernelselector = this;
25 Object.seal(this);
24 };
26 };
25
27
26 KernelSelector.prototype.request_kernelspecs = function() {
28 KernelSelector.prototype.request_kernelspecs = function() {
@@ -61,10 +63,29 b' define(['
61 };
63 };
62
64
63 KernelSelector.prototype.change_kernel = function(kernel_name) {
65 KernelSelector.prototype.change_kernel = function(kernel_name) {
66 /**
67 * TODO, have a methods to set kernel spec directly ?
68 **/
69 var that = this;
64 if (kernel_name === this.current_selection) {
70 if (kernel_name === this.current_selection) {
65 return;
71 return;
66 }
72 }
67 var ks = this.kernelspecs[kernel_name];
73 var ks = this.kernelspecs[kernel_name];
74 var new_mode_url = 'kernelspecs/'+ks.name+'/kernel';
75
76 var css_url = this.notebook.base_url+new_mode_url+'.css';
77 $.ajax({
78 type: 'HEAD',
79 url: css_url,
80 success: function(){
81 $('#kernel-css')
82 .attr('href',css_url);
83 },
84 error:function(){
85 console.info("No custom kernel.css at URL:", 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,33 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 defined a kernel.js file but does not contain "+
113 "any asynchronous module definition. This is undefined behavior "+
114 "which is not recommended");
115 }
116 },
117 function(err){
118 // if new mode does not have custom.js
119 console.info("No custom kernel.css at URL:", new_mode_url)
120 }
121 );
122 };
123
124 KernelSelector.prototype.lock_switch = function() {
125 // should set a flag and display warning+reload if user want to
126 // re-change kernel. As UI discussion never finish
127 // making that a separate PR.
128 console.warn('switching kernel is not guaranteed to work !');
81 };
129 };
82
130
83 KernelSelector.prototype.bind_events = function() {
131 KernelSelector.prototype.bind_events = function() {
@@ -1745,7 +1745,14 b' define(['
1745 // Trigger an event changing the kernel spec - this will set the default
1745 // Trigger an event changing the kernel spec - this will set the default
1746 // codemirror mode
1746 // codemirror mode
1747 if (this.metadata.kernelspec !== undefined) {
1747 if (this.metadata.kernelspec !== undefined) {
1748 this.events.trigger('spec_changed.Kernel', this.metadata.kernelspec);
1748 // TODO shoudl probably not trigger here,
1749 // should call the kernel selector, or custom.{js|css} not loaded.
1750 if(this.kernel_selector){
1751 // technically not perfect, we should check that the kernelspec matches
1752 this.kernel_selector.change_kernel(this.metadata.kernelspec.name);
1753 } else {
1754 console.log('do not have handle on kernel_selector');
1755 }
1749 }
1756 }
1750
1757
1751 // Set the codemirror mode from language_info metadata
1758 // Set the codemirror mode from language_info metadata
@@ -2188,6 +2195,10 b' define(['
2188 this.events.trigger('notebook_loaded.Notebook');
2195 this.events.trigger('notebook_loaded.Notebook');
2189 };
2196 };
2190
2197
2198 Notebook.prototype.set_kernelselector = function(k_selector){
2199 this.kernel_selector = k_selector;
2200 };
2201
2191 /**
2202 /**
2192 * Failure callback for loading a notebook from the server.
2203 * Failure callback for loading a notebook from the server.
2193 *
2204 *
@@ -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