UNPKG

7.85 kBTypeScriptView Raw
1import { ISessionContext } from '@jupyterlab/apputils';
2import { ITranslator } from '@jupyterlab/translation';
3import { VDomModel, VDomRenderer } from '@jupyterlab/ui-components';
4import { Notebook } from './widget';
5import { NotebookPanel } from './panel';
6import { ISettingRegistry } from '@jupyterlab/settingregistry';
7import { Widget } from '@lumino/widgets';
8/**
9 * A react functional component for rendering execution indicator.
10 */
11export declare function ExecutionIndicatorComponent(props: ExecutionIndicatorComponent.IProps): JSX.Element;
12/**
13 * A namespace for ExecutionIndicatorComponent statics.
14 */
15declare namespace ExecutionIndicatorComponent {
16 /**
17 * Props for the execution status component.
18 */
19 interface IProps {
20 /**
21 * Display option for progress bar and elapsed time.
22 */
23 displayOption: Private.DisplayOption;
24 /**
25 * Execution state of selected notebook.
26 */
27 state?: ExecutionIndicator.IExecutionState;
28 /**
29 * The application language translator.
30 */
31 translator?: ITranslator;
32 }
33}
34/**
35 * A VDomRenderer widget for displaying the execution status.
36 */
37export declare class ExecutionIndicator extends VDomRenderer<ExecutionIndicator.Model> {
38 /**
39 * Construct the kernel status widget.
40 */
41 constructor(translator?: ITranslator, showProgress?: boolean);
42 /**
43 * Render the execution status item.
44 */
45 render(): JSX.Element | null;
46 private translator;
47}
48/**
49 * A namespace for ExecutionIndicator statics.
50 */
51export declare namespace ExecutionIndicator {
52 /**
53 * Execution state of a notebook.
54 */
55 interface IExecutionState {
56 /**
57 * Execution status of kernel, this status is deducted from the
58 * number of scheduled code cells.
59 */
60 executionStatus: string;
61 /**
62 * Current status of kernel.
63 */
64 kernelStatus: ISessionContext.KernelDisplayStatus;
65 /**
66 * Total execution time.
67 */
68 totalTime: number;
69 /**
70 * Id of `setInterval`, it is used to start / stop the elapsed time
71 * counter.
72 */
73 interval: number;
74 /**
75 * Id of `setTimeout`, it is used to create / clear the state
76 * resetting request.
77 */
78 timeout: number;
79 /**
80 * Set of messages scheduled for executing, `executionStatus` is set
81 * to `idle if the length of this set is 0 and to `busy` otherwise.
82 */
83 scheduledCell: Set<string>;
84 /**
85 * Total number of cells requested for executing, it is used to compute
86 * the execution progress in progress bar.
87 */
88 scheduledCellNumber: number;
89 /**
90 * Flag to reset the execution state when a code cell is scheduled for
91 * executing.
92 */
93 needReset: boolean;
94 }
95 /**
96 * A VDomModel for the execution status indicator.
97 */
98 class Model extends VDomModel {
99 constructor();
100 /**
101 * Attach a notebook with session context to model in order to keep
102 * track of multiple notebooks. If a session context is already
103 * attached, only set current activated notebook to input.
104 *
105 * @param data - The notebook and session context to be attached to model
106 */
107 attachNotebook(data: {
108 content?: Notebook;
109 context?: ISessionContext;
110 } | null): void;
111 /**
112 * The current activated notebook in model.
113 */
114 get currentNotebook(): Notebook | null;
115 /**
116 * The display options for progress bar and elapsed time.
117 */
118 get displayOption(): Private.DisplayOption;
119 /**
120 * Set the display options for progress bar and elapsed time.
121 *
122 * @param options - Options to be used
123 */
124 set displayOption(options: Private.DisplayOption);
125 /**
126 * Get the execution state associated with a notebook.
127 *
128 * @param nb - The notebook used to identify execution
129 * state.
130 *
131 * @returns - The associated execution state.
132 */
133 executionState(nb: Notebook): IExecutionState | undefined;
134 /**
135 * Schedule switch to idle status and clearing of the timer.
136 *
137 * ### Note
138 *
139 * To keep track of cells executed under 1 second,
140 * the execution state is marked as `needReset` 1 second after executing
141 * these cells. This `Timeout` will be cleared if there is any cell
142 * scheduled after that.
143 */
144 private _scheduleSwitchToIdle;
145 /**
146 * The function is called on kernel's idle status message.
147 * It is used to keep track of number of executed
148 * cells or Comm custom messages and the status of kernel.
149 *
150 * @param nb - The notebook which contains the executed code cell.
151 * @param msg_id - The id of message.
152 */
153 private _cellExecutedCallback;
154 /**
155 * The function is called on kernel's restarting status message.
156 * It is used to clear the state tracking the number of executed
157 * cells.
158 *
159 * @param nb - The notebook which contains the executed code cell.
160 */
161 private _restartHandler;
162 /**
163 * This function is called on kernel's `execute_input` message to start
164 * the elapsed time counter.
165 *
166 * @param nb - The notebook which contains the scheduled execution request.
167 */
168 private _startTimer;
169 /**
170 * The function is called on kernel's `execute_request` message or Comm message, it is
171 * used to keep track number of scheduled cell or Comm execution message
172 * and the status of kernel.
173 *
174 * @param nb - The notebook which contains the scheduled code.
175 * cell
176 * @param msg_id - The id of message.
177 */
178 private _cellScheduledCallback;
179 /**
180 * Increment the executed time of input execution state
181 * and emit `stateChanged` signal to re-render the indicator.
182 *
183 * @param data - the state to be updated.
184 */
185 private _tick;
186 /**
187 * Reset the input execution state.
188 *
189 * @param data - the state to be rested.
190 */
191 private _resetTime;
192 get renderFlag(): boolean;
193 updateRenderOption(options: {
194 showOnToolBar: boolean;
195 showProgress: boolean;
196 }): void;
197 /**
198 * The option to show the indicator on status bar or toolbar.
199 */
200 private _displayOption;
201 /**
202 * Current activated notebook.
203 */
204 private _currentNotebook;
205 /**
206 * A weak map to hold execution status of multiple notebooks.
207 */
208 private _notebookExecutionProgress;
209 /**
210 * A flag to show or hide the indicator.
211 */
212 private _renderFlag;
213 }
214 function createExecutionIndicatorItem(panel: NotebookPanel, translator?: ITranslator, loadSettings?: Promise<ISettingRegistry.ISettings>): Widget;
215 function getSettingValue(settings: ISettingRegistry.ISettings): {
216 showOnToolBar: boolean;
217 showProgress: boolean;
218 };
219}
220/**
221 * A namespace for module-private data.
222 */
223declare namespace Private {
224 type DisplayOption = {
225 /**
226 * The option to show the indicator on status bar or toolbar.
227 */
228 showOnToolBar: boolean;
229 /**
230 * The option to show the execution progress inside kernel
231 * status circle.
232 */
233 showProgress: boolean;
234 };
235}
236export {};