UNPKG

7.4 kBTypeScriptView Raw
1import { ISessionContext, VDomModel, VDomRenderer } from '@jupyterlab/apputils';
2import { ITranslator } from '@jupyterlab/translation';
3import React from 'react';
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): React.ReactElement<ExecutionIndicatorComponent.IProps>;
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?: Private.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 * A VDomModel for the execution status indicator.
54 */
55 class Model extends VDomModel {
56 constructor();
57 /**
58 * Attach a notebook with session context to model in order to keep
59 * track of multiple notebooks. If a session context is already
60 * attached, only set current activated notebook to input.
61 *
62 * @param data - The notebook and session context to be attached to model
63 */
64 attachNotebook(data: {
65 content?: Notebook;
66 context?: ISessionContext;
67 } | null): void;
68 /**
69 * The current activated notebook in model.
70 */
71 get currentNotebook(): Notebook | null;
72 /**
73 * The display options for progress bar and elapsed time.
74 */
75 get displayOption(): Private.DisplayOption;
76 /**
77 * Set the display options for progress bar and elapsed time.
78 *
79 * @param options - Options to be used
80 */
81 set displayOption(options: Private.DisplayOption);
82 /**
83 * Get the execution state associated with a notebook.
84 *
85 * @param nb - The notebook used to identify execution
86 * state.
87 *
88 * @return - The associated execution state.
89 */
90 executionState(nb: Notebook): Private.IExecutionState | undefined;
91 /**
92 * The function is called on kernel's idle status message.
93 * It is used to keep track number of executed
94 * cell or Comm custom messages and the status of kernel.
95 *
96 * @param nb - The notebook which contains the executed code
97 * cell.
98 * @param msg_id - The id of message.
99 *
100 * ### Note
101 *
102 * To keep track of cells executed under 1 second,
103 * the execution state is marked as `needReset` 1 second after executing
104 * these cells. This `Timeout` will be cleared if there is any cell
105 * scheduled after that.
106 */
107 private _cellExecutedCallback;
108 /**
109 * This function is called on kernel's `execute_input` message to start
110 * the elapsed time counter.
111 *
112 * @param nb - The notebook which contains the scheduled execution request.
113 */
114 private _startTimer;
115 /**
116 * The function is called on kernel's `execute_request` message or Comm message, it is
117 * used to keep track number of scheduled cell or Comm execution message
118 * and the status of kernel.
119 *
120 * @param nb - The notebook which contains the scheduled code.
121 * cell
122 * @param msg_id - The id of message.
123 */
124 private _cellScheduledCallback;
125 /**
126 * Increment the executed time of input execution state
127 * and emit `stateChanged` signal to re-render the indicator.
128 *
129 * @param data - the state to be updated.
130 */
131 private _tick;
132 /**
133 * Reset the input execution state.
134 *
135 * @param data - the state to be rested.
136 */
137 private _resetTime;
138 get renderFlag(): boolean;
139 updateRenderOption(options: {
140 showOnToolBar: boolean;
141 showProgress: boolean;
142 }): void;
143 /**
144 * The option to show the indicator on status bar or toolbar.
145 */
146 private _displayOption;
147 /**
148 * Current activated notebook.
149 */
150 private _currentNotebook;
151 /**
152 * A weak map to hold execution status of multiple notebooks.
153 */
154 private _notebookExecutionProgress;
155 /**
156 * A flag to show or hide the indicator.
157 */
158 private _renderFlag;
159 }
160 function createExecutionIndicatorItem(panel: NotebookPanel, translator: ITranslator, loadSettings: Promise<ISettingRegistry.ISettings> | undefined): Widget;
161 function getSettingValue(settings: ISettingRegistry.ISettings): {
162 showOnToolBar: boolean;
163 showProgress: boolean;
164 };
165}
166/**
167 * A namespace for module-private data.
168 */
169declare namespace Private {
170 interface IExecutionState {
171 /**
172 * Execution status of kernel, this status is deducted from the
173 * number of scheduled code cells.
174 */
175 executionStatus: string;
176 /**
177 * Current status of kernel.
178 */
179 kernelStatus: ISessionContext.KernelDisplayStatus;
180 /**
181 * Total execution time.
182 */
183 totalTime: number;
184 /**
185 * Id of `setInterval`, it is used to start / stop the elapsed time
186 * counter.
187 */
188 interval: number;
189 /**
190 * Id of `setTimeout`, it is used to create / clear the state
191 * resetting request.
192 */
193 timeout: number;
194 /**
195 * Set of messages scheduled for executing, `executionStatus` is set
196 * to `idle if the length of this set is 0 and to `busy` otherwise.
197 */
198 scheduledCell: Set<string>;
199 /**
200 * Total number of cells requested for executing, it is used to compute
201 * the execution progress in progress bar.
202 */
203 scheduledCellNumber: number;
204 /**
205 * Flag to reset the execution state when a code cell is scheduled for
206 * executing.
207 */
208 needReset: boolean;
209 }
210 type DisplayOption = {
211 /**
212 * The option to show the indicator on status bar or toolbar.
213 */
214 showOnToolBar: boolean;
215 /**
216 * The option to show the execution progress inside kernel
217 * status circle.
218 */
219 showProgress: boolean;
220 };
221}
222export {};