##// END OF EJS Templates
Add submenu under kernel for changing kernel
Thomas Kluyver -
Show More
@@ -1,72 +1,80 b''
1 1 // Copyright (c) IPython Development Team.
2 2 // Distributed under the terms of the Modified BSD License.
3 3
4 4 define([
5 5 'base/js/namespace',
6 6 'jquery',
7 7 'base/js/utils',
8 8 ], function(IPython, $, utils) {
9 9 "use strict";
10 10
11 11 var KernelSelector = function(selector, notebook) {
12 12 this.selector = selector;
13 13 this.notebook = notebook;
14 14 this.events = notebook.events;
15 15 this.current_selection = notebook.default_kernel_name;
16 16 this.kernelspecs = {};
17 17 if (this.selector !== undefined) {
18 18 this.element = $(selector);
19 19 this.request_kernelspecs();
20 20 }
21 21 this.bind_events();
22 22 };
23 23
24 24 KernelSelector.prototype.request_kernelspecs = function() {
25 25 var url = utils.url_join_encode(this.notebook.base_url, 'api/kernelspecs');
26 26 $.ajax(url, {success: $.proxy(this.got_kernelspecs, this)});
27 27 };
28 28
29 29 KernelSelector.prototype.got_kernelspecs = function(data, status, xhr) {
30 30 this.kernelspecs = {};
31 31 var menu = this.element.find("#kernel_selector");
32 var change_kernel_submenu = $("#menu-change-kernel-submenu");
33 console.log(change_kernel_submenu);
32 34 for (var i = 0; i < data.length; i++) {
33 35 var ks = data[i];
34 36 this.kernelspecs[ks.name] = ks;
35 37 var ksentry = $("<li>").attr("id", "kernel-" +ks.name).append($('<a>')
36 38 .attr('href', '#')
37 39 .click($.proxy(this.change_kernel, this, ks.name))
38 40 .text(ks.display_name));
39 41 menu.append(ksentry);
42
43 var ks_submenu_entry = $("<li>").attr("id", "kernel-submenu-"+ks.name).append($('<a>')
44 .attr('href', '#')
45 .click($.proxy(this.change_kernel, this, ks.name))
46 .text(ks.display_name));
47 change_kernel_submenu.append(ks_submenu_entry);
40 48 }
41 49 };
42 50
43 51 KernelSelector.prototype.change_kernel = function(kernel_name) {
44 52 if (kernel_name === this.current_selection) {
45 53 return;
46 54 }
47 55 var ks = this.kernelspecs[kernel_name];
48 56 this.events.trigger('spec_changed.Kernel', ks);
49 57 this.notebook.session.delete();
50 58 this.notebook.start_session(kernel_name);
51 59 };
52 60
53 61 KernelSelector.prototype.bind_events = function() {
54 62 var that = this;
55 63 this.events.on('spec_changed.Kernel', function(event, data) {
56 64 that.current_selection = data.name;
57 65 that.element.find("#current_kernel_spec").find('.kernel_name').text(data.display_name);
58 66 });
59 67
60 68 this.events.on('started.Session', function(events, session) {
61 69 if (session.kernel_name !== that.current_selection) {
62 70 // If we created a 'python' session, we only know if it's Python
63 71 // 3 or 2 on the server's reply, so we fire the event again to
64 72 // set things up.
65 73 var ks = that.kernelspecs[session.kernel_name];
66 74 that.events.trigger('spec_changed.Kernel', ks);
67 75 }
68 76 });
69 77 };
70 78
71 79 return {'KernelSelector': KernelSelector};
72 80 });
@@ -1,331 +1,336 b''
1 1 {% extends "page.html" %}
2 2
3 3 {% block stylesheet %}
4 4
5 5 {% if mathjax_url %}
6 6 <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML-full&delayStartupUntil=configured" charset="utf-8"></script>
7 7 {% endif %}
8 8 <script type="text/javascript">
9 9 // MathJax disabled, set as null to distingish from *missing* MathJax,
10 10 // where it will be undefined, and should prompt a dialog later.
11 11 window.mathjax_url = "{{mathjax_url}}";
12 12 </script>
13 13
14 14 <link rel="stylesheet" href="{{ static_url("components/bootstrap-tour/build/css/bootstrap-tour.min.css") }}" type="text/css" />
15 15 <link rel="stylesheet" href="{{ static_url("components/codemirror/lib/codemirror.css") }}">
16 16
17 17 {{super()}}
18 18
19 19 <link rel="stylesheet" href="{{ static_url("notebook/css/override.css") }}" type="text/css" />
20 20
21 21 {% endblock %}
22 22
23 23 {% block params %}
24 24
25 25 data-project="{{project}}"
26 26 data-base-url="{{base_url}}"
27 27 data-ws-url="{{ws_url}}"
28 28 data-notebook-name="{{notebook_name}}"
29 29 data-notebook-path="{{notebook_path}}"
30 30 class="notebook_app"
31 31
32 32 {% endblock %}
33 33
34 34
35 35 {% block header %}
36 36
37 37
38 38 <span id="save_widget" class="nav pull-left">
39 39 <span id="notebook_name"></span>
40 40 <span id="checkpoint_status"></span>
41 41 <span id="autosave_status"></span>
42 42 </span>
43 43
44 44 <span id="kernel_selector_widget" class="pull-right dropdown">
45 45 <button href="#" class="dropdown-toggle" data-toggle="dropdown" type='button' id="current_kernel_spec">
46 46 <span class='kernel_name'>Python</span>
47 47 <span class="caret"></span>
48 48 </button>
49 49 <ul id="kernel_selector" class="dropdown-menu">
50 50 </ul>
51 51 </span>
52 52
53 53 {% endblock %}
54 54
55 55
56 56 {% block site %}
57 57
58 58 <div id="menubar-container" class="container">
59 59 <div id="menubar">
60 60 <div id="menus" class="navbar navbar-default" role="navigation">
61 61 <div class="container-fluid">
62 62 <ul class="nav navbar-nav">
63 63 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">File</a>
64 64 <ul id="file_menu" class="dropdown-menu">
65 65 <li id="new_notebook"
66 66 title="Make a new notebook (Opens a new window)">
67 67 <a href="#">New</a></li>
68 68 <li id="open_notebook"
69 69 title="Opens a new window with the Dashboard view">
70 70 <a href="#">Open...</a></li>
71 71 <!-- <hr/> -->
72 72 <li class="divider"></li>
73 73 <li id="copy_notebook"
74 74 title="Open a copy of this notebook's contents and start a new kernel">
75 75 <a href="#">Make a Copy...</a></li>
76 76 <li id="rename_notebook"><a href="#">Rename...</a></li>
77 77 <li id="save_checkpoint"><a href="#">Save and Checkpoint</a></li>
78 78 <!-- <hr/> -->
79 79 <li class="divider"></li>
80 80 <li id="restore_checkpoint" class="dropdown-submenu"><a href="#">Revert to Checkpoint</a>
81 81 <ul class="dropdown-menu">
82 82 <li><a href="#"></a></li>
83 83 <li><a href="#"></a></li>
84 84 <li><a href="#"></a></li>
85 85 <li><a href="#"></a></li>
86 86 <li><a href="#"></a></li>
87 87 </ul>
88 88 </li>
89 89 <li class="divider"></li>
90 90 <li id="print_preview"><a href="#">Print Preview</a></li>
91 91 <li class="dropdown-submenu"><a href="#">Download as</a>
92 92 <ul class="dropdown-menu">
93 93 <li id="download_ipynb"><a href="#">IPython Notebook (.ipynb)</a></li>
94 94 <li id="download_py"><a href="#">Python (.py)</a></li>
95 95 <li id="download_html"><a href="#">HTML (.html)</a></li>
96 96 <li id="download_rst"><a href="#">reST (.rst)</a></li>
97 97 <li id="download_pdf"><a href="#">PDF (.pdf)</a></li>
98 98 </ul>
99 99 </li>
100 100 <li class="divider"></li>
101 101 <li id="trust_notebook"
102 102 title="Trust the output of this notebook">
103 103 <a href="#" >Trust Notebook</a></li>
104 104 <li class="divider"></li>
105 105 <li id="kill_and_exit"
106 106 title="Shutdown this notebook's kernel, and close this window">
107 107 <a href="#" >Close and halt</a></li>
108 108 </ul>
109 109 </li>
110 110 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Edit</a>
111 111 <ul id="edit_menu" class="dropdown-menu">
112 112 <li id="cut_cell"><a href="#">Cut Cell</a></li>
113 113 <li id="copy_cell"><a href="#">Copy Cell</a></li>
114 114 <li id="paste_cell_above" class="disabled"><a href="#">Paste Cell Above</a></li>
115 115 <li id="paste_cell_below" class="disabled"><a href="#">Paste Cell Below</a></li>
116 116 <li id="paste_cell_replace" class="disabled"><a href="#">Paste Cell &amp; Replace</a></li>
117 117 <li id="delete_cell"><a href="#">Delete Cell</a></li>
118 118 <li id="undelete_cell" class="disabled"><a href="#">Undo Delete Cell</a></li>
119 119 <li class="divider"></li>
120 120 <li id="split_cell"><a href="#">Split Cell</a></li>
121 121 <li id="merge_cell_above"><a href="#">Merge Cell Above</a></li>
122 122 <li id="merge_cell_below"><a href="#">Merge Cell Below</a></li>
123 123 <li class="divider"></li>
124 124 <li id="move_cell_up"><a href="#">Move Cell Up</a></li>
125 125 <li id="move_cell_down"><a href="#">Move Cell Down</a></li>
126 126 <li class="divider"></li>
127 127 <li id="edit_nb_metadata"><a href="#">Edit Notebook Metadata</a></li>
128 128 </ul>
129 129 </li>
130 130 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">View</a>
131 131 <ul id="view_menu" class="dropdown-menu">
132 132 <li id="toggle_header"
133 133 title="Show/Hide the IPython Notebook logo and notebook title (above menu bar)">
134 134 <a href="#">Toggle Header</a></li>
135 135 <li id="toggle_toolbar"
136 136 title="Show/Hide the action icons (below menu bar)">
137 137 <a href="#">Toggle Toolbar</a></li>
138 138 </ul>
139 139 </li>
140 140 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Insert</a>
141 141 <ul id="insert_menu" class="dropdown-menu">
142 142 <li id="insert_cell_above"
143 143 title="Insert an empty Code cell above the currently active cell">
144 144 <a href="#">Insert Cell Above</a></li>
145 145 <li id="insert_cell_below"
146 146 title="Insert an empty Code cell below the currently active cell">
147 147 <a href="#">Insert Cell Below</a></li>
148 148 </ul>
149 149 </li>
150 150 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Cell</a>
151 151 <ul id="cell_menu" class="dropdown-menu">
152 152 <li id="run_cell" title="Run this cell, and move cursor to the next one">
153 153 <a href="#">Run</a></li>
154 154 <li id="run_cell_select_below" title="Run this cell, select below">
155 155 <a href="#">Run and Select Below</a></li>
156 156 <li id="run_cell_insert_below" title="Run this cell, insert below">
157 157 <a href="#">Run and Insert Below</a></li>
158 158 <li id="run_all_cells" title="Run all cells in the notebook">
159 159 <a href="#">Run All</a></li>
160 160 <li id="run_all_cells_above" title="Run all cells above (but not including) this cell">
161 161 <a href="#">Run All Above</a></li>
162 162 <li id="run_all_cells_below" title="Run this cell and all cells below it">
163 163 <a href="#">Run All Below</a></li>
164 164 <li class="divider"></li>
165 165 <li id="change_cell_type" class="dropdown-submenu"
166 166 title="All cells in the notebook have a cell type. By default, new cells are created as 'Code' cells">
167 167 <a href="#">Cell Type</a>
168 168 <ul class="dropdown-menu">
169 169 <li id="to_code"
170 170 title="Contents will be sent to the kernel for execution, and output will display in the footer of cell">
171 171 <a href="#">Code</a></li>
172 172 <li id="to_markdown"
173 173 title="Contents will be rendered as HTML and serve as explanatory text">
174 174 <a href="#">Markdown</a></li>
175 175 <li id="to_raw"
176 176 title="Contents will pass through nbconvert unmodified">
177 177 <a href="#">Raw NBConvert</a></li>
178 178 <li id="to_heading1"><a href="#">Heading 1</a></li>
179 179 <li id="to_heading2"><a href="#">Heading 2</a></li>
180 180 <li id="to_heading3"><a href="#">Heading 3</a></li>
181 181 <li id="to_heading4"><a href="#">Heading 4</a></li>
182 182 <li id="to_heading5"><a href="#">Heading 5</a></li>
183 183 <li id="to_heading6"><a href="#">Heading 6</a></li>
184 184 </ul>
185 185 </li>
186 186 <li class="divider"></li>
187 187 <li id="current_outputs" class="dropdown-submenu"><a href="#">Current Output</a>
188 188 <ul class="dropdown-menu">
189 189 <li id="toggle_current_output"
190 190 title="Hide/Show the output of the current cell">
191 191 <a href="#">Toggle</a>
192 192 </li>
193 193 <li id="toggle_current_output_scroll"
194 194 title="Scroll the output of the current cell">
195 195 <a href="#">Toggle Scrolling</a>
196 196 </li>
197 197 <li id="clear_current_output"
198 198 title="Clear the output of the current cell">
199 199 <a href="#">Clear</a>
200 200 </li>
201 201 </ul>
202 202 </li>
203 203 <li id="all_outputs" class="dropdown-submenu"><a href="#">All Output</a>
204 204 <ul class="dropdown-menu">
205 205 <li id="toggle_all_output"
206 206 title="Hide/Show the output of all cells">
207 207 <a href="#">Toggle</a>
208 208 </li>
209 209 <li id="toggle_all_output_scroll"
210 210 title="Scroll the output of all cells">
211 211 <a href="#">Toggle Scrolling</a>
212 212 </li>
213 213 <li id="clear_all_output"
214 214 title="Clear the output of all cells">
215 215 <a href="#">Clear</a>
216 216 </li>
217 217 </ul>
218 218 </li>
219 219 </ul>
220 220 </li>
221 221 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Kernel</a>
222 222 <ul id="kernel_menu" class="dropdown-menu">
223 223 <li id="int_kernel"
224 224 title="Send KeyboardInterrupt (CTRL-C) to the Kernel">
225 225 <a href="#">Interrupt</a></li>
226 226 <li id="restart_kernel"
227 227 title="Restart the Kernel">
228 228 <a href="#">Restart</a></li>
229 <li class="divider"></li>
230 <li id="menu-change-kernel" class="dropdown-submenu">
231 <a href="#">Change kernel</a>
232 <ul class="dropdown-menu" id="menu-change-kernel-submenu"></ul>
233 </li>
229 234 </ul>
230 235 </li>
231 236 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Help</a>
232 237 <ul id="help_menu" class="dropdown-menu">
233 238 <li id="notebook_tour" title="A quick tour of the notebook user interface"><a href="#">User Interface Tour</a></li>
234 239 <li id="keyboard_shortcuts" title="Opens a tooltip with all keyboard shortcuts"><a href="#">Keyboard Shortcuts</a></li>
235 240 <li class="divider"></li>
236 241 {% set
237 242 sections = (
238 243 (
239 244 ("http://ipython.org/documentation.html","IPython Help",True),
240 245 ("http://nbviewer.ipython.org/github/ipython/ipython/tree/2.x/examples/Index.ipynb", "Notebook Help", True),
241 246 ),(
242 247 ("http://docs.python.org","Python",True),
243 248 ("http://help.github.com/articles/github-flavored-markdown","Markdown",True),
244 249 ("http://docs.scipy.org/doc/numpy/reference/","NumPy",True),
245 250 ("http://docs.scipy.org/doc/scipy/reference/","SciPy",True),
246 251 ("http://matplotlib.org/contents.html","Matplotlib",True),
247 252 ("http://docs.sympy.org/latest/index.html","SymPy",True),
248 253 ("http://pandas.pydata.org/pandas-docs/stable/","pandas", True)
249 254 )
250 255 )
251 256 %}
252 257
253 258 {% for helplinks in sections %}
254 259 {% for link in helplinks %}
255 260 <li><a href="{{link[0]}}" {{'target="_blank" title="Opens in a new window"' if link[2]}}>
256 261 {{'<i class="icon-external-link menu-icon pull-right"></i>' if link[2]}}
257 262 {{link[1]}}
258 263 </a></li>
259 264 {% endfor %}
260 265 {% if not loop.last %}
261 266 <li class="divider"></li>
262 267 {% endif %}
263 268 {% endfor %}
264 269 </li>
265 270 </ul>
266 271 </li>
267 272 </ul>
268 273 <ul class="nav navbar-nav navbar-right">
269 274 <div id="kernel_indicator">
270 275 <i id="kernel_indicator_icon"></i>
271 276 </div>
272 277 <div id="modal_indicator">
273 278 <i id="modal_indicator_icon"></i>
274 279 </div>
275 280 <div id="notification_area"></div>
276 281 </ul>
277 282 </div>
278 283 </div>
279 284 </div>
280 285 <div id="maintoolbar" class="navbar">
281 286 <div class="toolbar-inner navbar-inner navbar-nobg">
282 287 <div id="maintoolbar-container" class="container"></div>
283 288 </div>
284 289 </div>
285 290 </div>
286 291
287 292 <div id="ipython-main-app">
288 293
289 294 <div id="notebook_panel">
290 295 <div id="notebook"></div>
291 296 <div id="pager_splitter"></div>
292 297 <div id="pager">
293 298 <div id='pager_button_area'>
294 299 </div>
295 300 <div id="pager-container" class="container"></div>
296 301 </div>
297 302 </div>
298 303
299 304 </div>
300 305 <div id='tooltip' class='ipython_tooltip' style='display:none'></div>
301 306
302 307
303 308 {% endblock %}
304 309
305 310
306 311 {% block script %}
307 312 {{super()}}
308 313
309 314 <script src="{{ static_url("components/codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
310 315 <script type="text/javascript">
311 316 CodeMirror.modeURL = "{{ static_url("components/codemirror/mode/%N/%N.js", include_version=False) }}";
312 317 </script>
313 318 <script src="{{ static_url("components/codemirror/addon/mode/loadmode.js") }}" charset="utf-8"></script>
314 319 <script src="{{ static_url("components/codemirror/addon/mode/multiplex.js") }}" charset="utf-8"></script>
315 320 <script src="{{ static_url("components/codemirror/addon/mode/overlay.js") }}" charset="utf-8"></script>
316 321 <script src="{{ static_url("components/codemirror/addon/edit/matchbrackets.js") }}" charset="utf-8"></script>
317 322 <script src="{{ static_url("components/codemirror/addon/edit/closebrackets.js") }}" charset="utf-8"></script>
318 323 <script src="{{ static_url("components/codemirror/addon/comment/comment.js") }}" charset="utf-8"></script>
319 324 <script src="{{ static_url("components/codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script>
320 325 <script src="{{ static_url("components/codemirror/mode/xml/xml.js") }}" charset="utf-8"></script>
321 326 <script src="{{ static_url("components/codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script>
322 327 <script src="{{ static_url("components/codemirror/mode/css/css.js") }}" charset="utf-8"></script>
323 328 <script src="{{ static_url("components/codemirror/mode/rst/rst.js") }}" charset="utf-8"></script>
324 329 <script src="{{ static_url("components/codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
325 330 <script src="{{ static_url("components/codemirror/mode/python/python.js") }}" charset="utf-8"></script>
326 331 <script src="{{ static_url("notebook/js/codemirror-ipython.js") }}" charset="utf-8"></script>
327 332 <script src="{{ static_url("notebook/js/codemirror-ipythongfm.js") }}" charset="utf-8"></script>
328 333
329 334 <script src="{{ static_url("notebook/js/main.js") }}" charset="utf-8"></script>
330 335
331 336 {% endblock %}
General Comments 0
You need to be logged in to leave comments. Login now