Skip to content

Commit 9dc4842

Browse files
author
minjk-bl
committed
Add restart vp menu
1 parent 812bc2c commit 9dc4842

File tree

4 files changed

+59
-28
lines changed

4 files changed

+59
-28
lines changed

html/menuFrame.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
<div id="vp_headerExtraMenuBtn" class="vp-menu-header-button vp-close-on-blur-btn">
2020
<div id="vp_headerExtraMenu" class="vp-no-selection vp-close-on-blur">
2121
<ul class="vp-header-extra-menu-list">
22-
<li id="vp_extraMenuAbout">
22+
<li id="vp_restart" data-menu="restart">
23+
Restart visualpython
24+
</li>
25+
<hr class="vp-extra-menu-line"/>
26+
<li id="vp_extraMenuAbout" data-menu="about">
2327
About Visual Python
2428
<a href="https://visualpython.ai/about" target="_blank">
2529
<img src="/nbextensions/visualpython/img/snippets/export.svg">
2630
</a>
2731
</li>
28-
<li id="vp_extraMenuVPNote">
32+
<li id="vp_extraMenuVPNote" data-menu="vpnote">
2933
VP Note
3034
<a href="https://visualpython.ai/vpnotes" target="_blank">
3135
<img src="/nbextensions/visualpython/img/snippets/export.svg">

js/com/com_Config.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//============================================================================
1212
// [CLASS] Configuration
1313
//============================================================================
14-
define([], function() {
14+
define(['./com_Const'], function(com_Const) {
1515
'use strict';
1616
//========================================================================
1717
// Define Inner Variable
@@ -146,6 +146,43 @@ define([], function() {
146146
$.extend(true, this.defaultConfig, this.metadataSettings);
147147
}
148148

149+
/**
150+
* Read kernel functions for using visualpython
151+
* - manually click restart menu (MenuFrame.js)
152+
* - automatically restart on jupyter kernel restart (loadVisualpython.js)
153+
*/
154+
readKernelFunction() {
155+
var libraryList = [
156+
'printCommand.py',
157+
'fileNaviCommand.py',
158+
'pandasCommand.py',
159+
'variableCommand.py'
160+
];
161+
let promiseList = [];
162+
libraryList.forEach(libName => {
163+
var libPath = com_Const.PYTHON_PATH + libName
164+
$.get(libPath).done(function(data) {
165+
var code_init = data;
166+
promiseList.push(vpKernel.execute(code_init));
167+
}).fail(function() {
168+
console.log('visualpython - failed to read library file', libName);
169+
});
170+
});
171+
// run all promises
172+
let failed = false;
173+
Promise.all(promiseList).then(function(resultObj) {
174+
}).catch(function(resultObj) {
175+
failed = true;
176+
console.log('visualpython - failed to load library', resultObj);
177+
}).finally(function() {
178+
if (!failed) {
179+
console.log('visualpython - loaded libraries', libraryList);
180+
} else {
181+
console.log('visualpython - failed to load libraries');
182+
}
183+
});
184+
}
185+
149186
getMode() {
150187
return Config.serverMode;
151188
}

js/loadVisualpython.js

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,6 @@
139139
});
140140
};
141141

142-
/**
143-
* Declare background vp functions
144-
*/
145-
var _readKernelFunction = function() {
146-
var libraryList = [
147-
'printCommand.py',
148-
'fileNaviCommand.py',
149-
'pandasCommand.py',
150-
'variableCommand.py'
151-
];
152-
libraryList.forEach(libName => {
153-
var libPath = com_Const.PYTHON_PATH + libName
154-
$.get(libPath).done(function(data) {
155-
var code_init = data;
156-
Jupyter.notebook.kernel.execute(code_init, { iopub: { output: function(data) {
157-
console.log('visualpython - loaded library', data);
158-
} } }, { silent: false });
159-
}).fail(function() {
160-
console.log('visualpython - failed to load getPath library');
161-
});
162-
})
163-
}
164-
165142
var _setGlobalVariables = function() {
166143
/**
167144
* visualpython log util
@@ -231,7 +208,7 @@
231208

232209
let cfg = readConfig();
233210

234-
_readKernelFunction();
211+
vpConfig.readKernelFunction();
235212
_addToolBarVpButton();
236213
_loadVpResource(cfg);
237214

@@ -243,7 +220,7 @@
243220
events.on('kernel_ready.Kernel', function (evt, info) {
244221
vpLog.display(VP_LOG_TYPE.LOG, 'vp operations for kernel ready...');
245222
// read vp functions
246-
_readKernelFunction();
223+
vpConfig.readKernelFunction();
247224
});
248225
}
249226

js/menu/MenuFrame.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ define([
8181
$(this.wrapSelector('#vp_toggleBoard')).on('click', function() {
8282
that.prop.parent.toggleNote();
8383
});
84+
// Click extra menu item
85+
$(this.wrapSelector('#vp_headerExtraMenu li')).on('click', function() {
86+
let menu = $(this).data('menu');
87+
switch(menu) {
88+
case 'restart':
89+
// restart vp
90+
vpConfig.readKernelFunction();
91+
break;
92+
case 'about':
93+
case 'vpnote':
94+
break;
95+
}
96+
})
8497
}
8598

8699
_unbindResizable() {

0 commit comments

Comments
 (0)