1 |
|
2 |
|
3 | import { nullTranslator } from '@jupyterlab/translation';
|
4 | import { circleEmptyIcon, circleIcon, LabIcon, offlineBoltIcon, ReactWidget, refreshIcon, stopIcon, ToolbarButton, ToolbarButtonComponent, UseSignal } from '@jupyterlab/ui-components';
|
5 | import { Widget } from '@lumino/widgets';
|
6 | import * as React from 'react';
|
7 | import { SessionContextDialogs } from '../sessioncontext';
|
8 | import { translateKernelStatuses } from '../kernelstatuses';
|
9 |
|
10 |
|
11 |
|
12 | const TOOLBAR_KERNEL_NAME_CLASS = 'jp-Toolbar-kernelName';
|
13 |
|
14 |
|
15 |
|
16 | const TOOLBAR_KERNEL_STATUS_CLASS = 'jp-Toolbar-kernelStatus';
|
17 |
|
18 |
|
19 |
|
20 | export var Toolbar;
|
21 | (function (Toolbar) {
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | function createInterruptButton(sessionContext, translator) {
|
29 | translator = translator || nullTranslator;
|
30 | const trans = translator.load('jupyterlab');
|
31 | return new ToolbarButton({
|
32 | icon: stopIcon,
|
33 | onClick: () => {
|
34 | var _a, _b;
|
35 | void ((_b = (_a = sessionContext.session) === null || _a === void 0 ? void 0 : _a.kernel) === null || _b === void 0 ? void 0 : _b.interrupt());
|
36 | },
|
37 | tooltip: trans.__('Interrupt the kernel')
|
38 | });
|
39 | }
|
40 | Toolbar.createInterruptButton = createInterruptButton;
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | function createRestartButton(sessionContext, dialogs, translator) {
|
48 | translator = translator !== null && translator !== void 0 ? translator : nullTranslator;
|
49 | const trans = translator.load('jupyterlab');
|
50 | return new ToolbarButton({
|
51 | icon: refreshIcon,
|
52 | onClick: () => {
|
53 | void (dialogs !== null && dialogs !== void 0 ? dialogs : new SessionContextDialogs({ translator })).restart(sessionContext);
|
54 | },
|
55 | tooltip: trans.__('Restart the kernel')
|
56 | });
|
57 | }
|
58 | Toolbar.createRestartButton = createRestartButton;
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | function createKernelNameItem(sessionContext, dialogs, translator) {
|
67 | const el = ReactWidget.create(React.createElement(Private.KernelNameComponent, { sessionContext: sessionContext, dialogs: dialogs !== null && dialogs !== void 0 ? dialogs : new SessionContextDialogs({ translator }), translator: translator }));
|
68 | el.addClass('jp-KernelName');
|
69 | return el;
|
70 | }
|
71 | Toolbar.createKernelNameItem = createKernelNameItem;
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | function createKernelStatusItem(sessionContext, translator) {
|
84 | return new Private.KernelStatus(sessionContext, translator);
|
85 | }
|
86 | Toolbar.createKernelStatusItem = createKernelStatusItem;
|
87 | })(Toolbar || (Toolbar = {}));
|
88 |
|
89 |
|
90 |
|
91 | var Private;
|
92 | (function (Private) {
|
93 | |
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | function KernelNameComponent(props) {
|
100 | const translator = props.translator || nullTranslator;
|
101 | const trans = translator.load('jupyterlab');
|
102 | const callback = () => {
|
103 | void props.dialogs.selectKernel(props.sessionContext);
|
104 | };
|
105 | return (React.createElement(UseSignal, { signal: props.sessionContext.kernelChanged, initialSender: props.sessionContext }, sessionContext => (React.createElement(ToolbarButtonComponent, { className: TOOLBAR_KERNEL_NAME_CLASS, onClick: callback, tooltip: trans.__('Switch kernel'), label: sessionContext === null || sessionContext === void 0 ? void 0 : sessionContext.kernelDisplayName }))));
|
106 | }
|
107 | Private.KernelNameComponent = KernelNameComponent;
|
108 | |
109 |
|
110 |
|
111 | class KernelStatus extends Widget {
|
112 | |
113 |
|
114 |
|
115 | constructor(sessionContext, translator) {
|
116 | super();
|
117 | this.translator = translator || nullTranslator;
|
118 | this._trans = this.translator.load('jupyterlab');
|
119 | this.addClass(TOOLBAR_KERNEL_STATUS_CLASS);
|
120 | this._statusNames = translateKernelStatuses(this.translator);
|
121 | this._onStatusChanged(sessionContext);
|
122 | sessionContext.statusChanged.connect(this._onStatusChanged, this);
|
123 | sessionContext.connectionStatusChanged.connect(this._onStatusChanged, this);
|
124 | }
|
125 | |
126 |
|
127 |
|
128 | _onStatusChanged(sessionContext) {
|
129 | if (this.isDisposed) {
|
130 | return;
|
131 | }
|
132 | const status = sessionContext.kernelDisplayStatus;
|
133 | const circleIconProps = {
|
134 | container: this.node,
|
135 | title: this._trans.__('Kernel %1', this._statusNames[status] || status),
|
136 | stylesheet: 'toolbarButton',
|
137 | alignSelf: 'normal',
|
138 | height: '24px'
|
139 | };
|
140 |
|
141 | LabIcon.remove(this.node);
|
142 | if (status === 'busy' ||
|
143 | status === 'starting' ||
|
144 | status === 'terminating' ||
|
145 | status === 'restarting' ||
|
146 | status === 'initializing') {
|
147 | circleIcon.element(circleIconProps);
|
148 | }
|
149 | else if (status === 'connecting' ||
|
150 | status === 'disconnected' ||
|
151 | status === 'unknown') {
|
152 | offlineBoltIcon.element(circleIconProps);
|
153 | }
|
154 | else {
|
155 | circleEmptyIcon.element(circleIconProps);
|
156 | }
|
157 | }
|
158 | }
|
159 | Private.KernelStatus = KernelStatus;
|
160 | })(Private || (Private = {}));
|
161 |
|
\ | No newline at end of file |