Show More
@@ -0,0 +1,58 b'' | |||
|
1 | // Copyright (c) IPython Development Team. | |
|
2 | // Distributed under the terms of the Modified BSD License. | |
|
3 | ||
|
4 | define([ | |
|
5 | 'base/js/namespace', | |
|
6 | 'jquery', | |
|
7 | 'base/js/utils', | |
|
8 | ], function(IPython, $, utils) { | |
|
9 | "use strict"; | |
|
10 | ||
|
11 | var KernelSelector = function(selector, notebook) { | |
|
12 | this.selector = selector; | |
|
13 | this.notebook = notebook; | |
|
14 | this.kernelspecs = {}; | |
|
15 | this.current = "python"; | |
|
16 | if (this.selector !== undefined) { | |
|
17 | this.element = $(selector); | |
|
18 | this.style(); | |
|
19 | this.request_kernelspecs(); | |
|
20 | } | |
|
21 | }; | |
|
22 | ||
|
23 | KernelSelector.prototype.style = function() { | |
|
24 | }; | |
|
25 | ||
|
26 | KernelSelector.prototype.request_kernelspecs = function() { | |
|
27 | var url = utils.url_join_encode(this.notebook.base_url, 'api/kernelspecs'); | |
|
28 | $.ajax(url, {success: $.proxy(this.got_kernelspecs, this)}); | |
|
29 | }; | |
|
30 | ||
|
31 | KernelSelector.prototype.got_kernelspecs = function(data, status, xhr) { | |
|
32 | this.kernelspecs = {}; | |
|
33 | var menu = this.element.find("#kernel_selector"); | |
|
34 | for (var i = 0; i < data.length; i++) { | |
|
35 | var ks = data[i]; | |
|
36 | this.kernelspecs[ks.name] = ks; | |
|
37 | var ksentry = $("<li>").attr("id", "kernel-" +ks.name).append($('<a>') | |
|
38 | .attr('href', '#') | |
|
39 | .click($.proxy(this.change_kernel, this, ks.name)) | |
|
40 | .text(ks.display_name)); | |
|
41 | menu.append(ksentry); | |
|
42 | } | |
|
43 | }; | |
|
44 | ||
|
45 | KernelSelector.prototype.change_kernel = function(kernel_name) { | |
|
46 | console.log("change_kernel " + kernel_name + " from " + this.current); | |
|
47 | if (kernel_name === this.current) { | |
|
48 | return; | |
|
49 | } | |
|
50 | this.notebook.session.delete(); | |
|
51 | this.notebook.start_session(kernel_name); | |
|
52 | this.current = kernel_name; | |
|
53 | var display_name = this.kernelspecs[kernel_name].display_name; | |
|
54 | this.element.find("#current_kernel_spec").text(display_name); | |
|
55 | }; | |
|
56 | ||
|
57 | return {'KernelSelector': KernelSelector}; | |
|
58 | }); |
@@ -18,6 +18,7 b' require([' | |||
|
18 | 18 | 'notebook/js/savewidget', |
|
19 | 19 | 'notebook/js/keyboardmanager', |
|
20 | 20 | 'notebook/js/config', |
|
21 | 'notebook/js/kernelselector', | |
|
21 | 22 | // only loaded, not used: |
|
22 | 23 | 'custom/custom', |
|
23 | 24 | ], function( |
@@ -36,7 +37,8 b' require([' | |||
|
36 | 37 | notificationarea, |
|
37 | 38 | savewidget, |
|
38 | 39 | keyboardmanager, |
|
39 | config | |
|
40 | config, | |
|
41 | kernelselector | |
|
40 | 42 | ) { |
|
41 | 43 | "use strict"; |
|
42 | 44 | |
@@ -90,6 +92,8 b' require([' | |||
|
90 | 92 | notebook: notebook, |
|
91 | 93 | keyboard_manager: keyboard_manager}); |
|
92 | 94 | notification_area.init_notification_widgets(); |
|
95 | var kernel_selector = new kernelselector.KernelSelector( | |
|
96 | '#kernel_selector_widget', notebook); | |
|
93 | 97 | |
|
94 | 98 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ |
|
95 | 99 | '<span id="test2" style="font-weight: bold;">x</span>'+ |
@@ -1496,7 +1496,11 b' define([' | |||
|
1496 | 1496 | * |
|
1497 | 1497 | * @method start_session |
|
1498 | 1498 | */ |
|
1499 | Notebook.prototype.start_session = function () { | |
|
1499 | Notebook.prototype.start_session = function (kernel_name) { | |
|
1500 | if (kernel_name === undefined) { | |
|
1501 | kernel_name = this.default_kernel_name; | |
|
1502 | } | |
|
1503 | console.log("start_session", kernel_name); | |
|
1500 | 1504 | this.session = new session.Session({ |
|
1501 | 1505 | base_url: this.base_url, |
|
1502 | 1506 | ws_url: this.ws_url, |
@@ -1505,7 +1509,7 b' define([' | |||
|
1505 | 1509 | // For now, create all sessions with the 'python' kernel, which is the |
|
1506 | 1510 | // default. Later, the user will be able to select kernels. This is |
|
1507 | 1511 | // overridden if KernelManager.kernel_cmd is specified for the server. |
|
1508 |
kernel_name: |
|
|
1512 | kernel_name: kernel_name, | |
|
1509 | 1513 | notebook: this}); |
|
1510 | 1514 | |
|
1511 | 1515 | this.session.start($.proxy(this._session_started, this)); |
@@ -40,6 +40,12 b' class="notebook_app"' | |||
|
40 | 40 | <span id="autosave_status"></span> |
|
41 | 41 | </span> |
|
42 | 42 | |
|
43 | <span id="kernel_selector_widget" class="nav pull-right"> | |
|
44 | <a href="#" class="dropdown-toggle" data-toggle="dropdown" id="current_kernel_spec">Python</a> | |
|
45 | <ul id="kernel_selector" class="dropdown-menu"> | |
|
46 | </ul> | |
|
47 | </span> | |
|
48 | ||
|
43 | 49 | {% endblock %} |
|
44 | 50 | |
|
45 | 51 |
General Comments 0
You need to be logged in to leave comments.
Login now