Skip to content

Commit d0f2925

Browse files
author
minjk-bl
committed
Add protector for lab and lite on launcher state
1 parent e7f7572 commit d0f2925

File tree

4 files changed

+117
-10
lines changed

4 files changed

+117
-10
lines changed

visualpython/css/mainFrame.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,43 @@ div#vp_wrapper.colab * {
5959
#vp_wrapper.lab *, #vp_wrapper.lite * {
6060
box-sizing: border-box !important;
6161
}
62+
/* LITE: show protector */
63+
#vp_wrapper.lab .vp-protector,
64+
#vp_wrapper.lite .vp-protector {
65+
background-color: rgb(33 33 33 / 77%);
66+
position: absolute;
67+
width: 100%;
68+
height: 100%;
69+
z-index: 100;
70+
}
71+
#vp_wrapper.lab .vp-protector-info,
72+
#vp_wrapper.lite .vp-protector-info {
73+
background-color: var(--vp-background-color);
74+
width: 250px;
75+
height: 170px;
76+
padding: 10px;
77+
margin: auto;
78+
top: calc(50% - 80px);
79+
position: relative;
80+
display: grid;
81+
grid-template-rows: 20px 100px 30px;
82+
}
83+
#vp_wrapper.lab .vp-protector-title,
84+
#vp_wrapper.lite .vp-protector-title {
85+
font-weight: bold;
86+
color: var(--vp-font-highlight);
87+
}
88+
#vp_wrapper.lab .vp-protector-content,
89+
#vp_wrapper.lite .vp-protector-content {
90+
border: 0.25px solid var(--vp-border-gray-color);
91+
border-radius: 10px;
92+
padding: 10px;
93+
margin: 5px 0;
94+
}
95+
#vp_wrapper.lab .vp-protector-footer,
96+
#vp_wrapper.lite .vp-protector-footer {
97+
text-align: right;
98+
}
6299

63100
/* resizing handle */
64101
#vp_wrapper > .ui-resizable-handle {

visualpython/js/com/com_Config.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ define([
5252
*/
5353
constructor(extensionType='notebook', initialData={}) {
5454
// initial mode
55-
this.isReady = false;
55+
this._isReady = { 'default': false };
5656
this.extensionType = extensionType;
5757
this.parentSelector = 'body';
5858
if (extensionType === 'notebook') {
@@ -216,6 +216,41 @@ define([
216216

217217
}
218218

219+
get isReady() {
220+
let sessionId = 'default';
221+
if (this.extensionType === 'lab' || this.extensionType === 'lite') {
222+
let panelId = vpKernel.getLabPanelId();
223+
if (panelId) {
224+
sessionId = panelId;
225+
}
226+
}
227+
if (sessionId in this._isReady) {
228+
return this._isReady[sessionId];
229+
}
230+
return false;
231+
}
232+
233+
set isReady(ready) {
234+
let sessionId = 'default';
235+
if (this.extensionType === 'lab' || this.extensionType === 'lite') {
236+
let panelId = vpKernel.getLabPanelId();
237+
if (panelId) {
238+
sessionId = panelId;
239+
}
240+
}
241+
this._isReady[sessionId] = ready;
242+
}
243+
244+
showProtector(title='No kernel', content='You have to open the notebook or console to use Visual Python.') {
245+
$('#vp_protector .vp-protector-title').text(title);
246+
$('#vp_protector .vp-protector-content').text(content);
247+
$('#vp_protector').show();
248+
}
249+
250+
hideProtector() {
251+
$('#vp_protector').hide();
252+
}
253+
219254
/**
220255
* Read dejault config
221256
*/
@@ -299,6 +334,9 @@ define([
299334
let that = this;
300335
// CHROME: change method to load py files ($.get -> require)
301336
return new Promise(function(resolve, reject) {
337+
// if (that.extensionType === 'lite') {
338+
// that.showProtector('Kernel loading', 'Required inner function is loading now...');
339+
// }
302340
var libraryList = [
303341
printCommand, fileNaviCommand, pandasCommand, variableCommand, visualizationCommand
304342
];
@@ -344,6 +382,9 @@ define([
344382
console.log('visualpython - failed to load library', resultObj);
345383
// TODO: show to restart kernel
346384
}).finally(function() {
385+
// if (that.extensionType === 'lite') {
386+
// that.hideProtector();
387+
// }
347388
if (!failed) {
348389
console.log('visualpython - loaded libraries', libraryList);
349390
resolve(true);
@@ -1005,8 +1046,8 @@ define([
10051046
/**
10061047
* FIXME: before release, change it to _MODE_TYPE.RELEASE
10071048
*/
1008-
// Config.serverMode = _MODE_TYPE.DEVELOP;
1009-
Config.serverMode = _MODE_TYPE.RELEASE;
1049+
Config.serverMode = _MODE_TYPE.DEVELOP;
1050+
// Config.serverMode = _MODE_TYPE.RELEASE;
10101051

10111052
/**
10121053
* Version

visualpython/js/com/com_Kernel.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ define([
381381
}
382382
var future;
383383
if (vpConfig.isReady === false) {
384+
vpConfig.isReady = true;
385+
vpConfig.hideProtector();
384386
vpConfig.readKernelFunction().then(function() {
385387
future = kernelConnection.requestExecute(codeObj);
386388
future.onIOPub = onIOPub;

visualpython/js/loadVisualpython.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,31 +288,58 @@ define([
288288
// LAB: if widget is ready or changed, ready for lab kernel connected, and restart vp
289289
vpLab.shell._currentChanged.connect(function(s1, value) {
290290
var { newValue } = value;
291+
vpLog.display(VP_LOG_TYPE.DEVELOP, 'jupyterlab shell currently changed', s1, value);
291292
// kernel restart for notebook and console
292293
if (newValue && newValue.sessionContext) {
294+
vpConfig.hideProtector();
293295
if (newValue.sessionContext.isReady) {
294-
vpLog.display(VP_LOG_TYPE.LOG, 'vp operations for kernel ready...');
295-
vpConfig.isReady = true;
296-
vpConfig.readKernelFunction();
297-
vpConfig.checkVersionTimestamp();
298-
}
299-
newValue.sessionContext._connectionStatusChanged.connect(function(s2, status) {
300-
if (status === 'connected') {
296+
if (vpConfig.isReady === false) {
301297
vpLog.display(VP_LOG_TYPE.LOG, 'vp operations for kernel ready...');
302298
vpConfig.isReady = true;
303299
vpConfig.readKernelFunction();
304300
vpConfig.checkVersionTimestamp();
305301
}
302+
}
303+
newValue.sessionContext._connectionStatusChanged.connect(function(s2, status) {
304+
if (status === 'connected') {
305+
if (vpConfig.isReady === false) {
306+
vpLog.display(VP_LOG_TYPE.LOG, 'vp operations for kernel ready...');
307+
vpConfig.isReady = true;
308+
vpConfig.readKernelFunction();
309+
vpConfig.checkVersionTimestamp();
310+
}
311+
}
306312
});
307313
} else {
308314
vpLog.display(VP_LOG_TYPE.LOG, 'No widget detected...');
315+
vpConfig.isReady = false;
316+
vpConfig.showProtector();
317+
if (vpConfig.extensionType === 'lite') {
318+
vpLab.serviceManager.sessions.runningChanged.connect(handleRunningChanged);
319+
}
309320
}
310321
});
311322
}
312323

313324
return vpFrame;
314325
}
315326

327+
var handleRunningChanged = function(a, b) {
328+
vpLog.display(VP_LOG_TYPE.DEVELOP, 'Current widget:', vpLab.shell.currentWidget);
329+
if (vpLab.shell.currentWidget) {
330+
vpLab.shell.currentWidget.sessionContext.statusChanged.connect(function(currentWidget, status) {
331+
if (status === 'idle' && vpConfig.isReady === false) {
332+
vpLog.display(VP_LOG_TYPE.LOG, 'vp operations for kernel ready...');
333+
vpConfig.isReady = true;
334+
vpConfig.hideProtector();
335+
vpConfig.readKernelFunction();
336+
vpConfig.checkVersionTimestamp();
337+
}
338+
});
339+
vpLab.serviceManager.sessions.runningChanged.disconnect(handleRunningChanged);
340+
}
341+
}
342+
316343
return { initVisualpython: initVisualpython, readConfig: readConfig };
317344

318345
}); /* function, define */

0 commit comments

Comments
 (0)