From f34ad70a2ec4bb3142a96a2e0790a00ac7c379ea Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Mon, 17 Jan 2022 14:32:55 +0900 Subject: [PATCH 1/9] Hotfix for using metadata from notebook --- js/com/com_Config.js | 17 ++++++++++++++--- js/m_apps/Import.js | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/js/com/com_Config.js b/js/com/com_Config.js index 472227df..af94bf6f 100644 --- a/js/com/com_Config.js +++ b/js/com/com_Config.js @@ -90,7 +90,17 @@ define([], function() { ' except ValueError:', ' return 0.0' ] - } + }, + 'vpimport': [ + { library: 'numpy', alias:'np' }, + { library: 'pandas', alias:'pd' }, + { library: 'matplotlib.pyplot', alias:'plt', + include: [ + '%matplotlib inline' + ] + }, + { library: 'seaborn', alias:'sns' } + ] } this.data = { @@ -165,7 +175,8 @@ define([], function() { Jupyter.notebook.config.loaded.then(function() { var data = Jupyter.notebook.config.data[configKey]; if (data == undefined) { - data = {}; + reject('No data available.'); + return; } if (dataKey == '') { resolve(data); @@ -184,7 +195,7 @@ define([], function() { Jupyter.notebook.config.load(); var data = Jupyter.notebook.config.data[configKey]; if (data == undefined) { - data = {}; + return undefined; } if (dataKey == '') { return data; diff --git a/js/m_apps/Import.js b/js/m_apps/Import.js index 866c1823..6f2161cc 100644 --- a/js/m_apps/Import.js +++ b/js/m_apps/Import.js @@ -81,7 +81,7 @@ define([ page.appendLine(''); page.appendLine(''); let that = this; - this.state.importMeta.forEach((lib, idx) => { + this.state.importMeta && this.state.importMeta.forEach((lib, idx) => { page.appendLine(that.templateForLibrary(idx, lib.library, lib.alias)); }); page.appendLine(''); From d6b964b1feeb16073fe258dd1a2f46caf40395ff Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Mon, 17 Jan 2022 15:19:46 +0900 Subject: [PATCH 2/9] Instance's inner subset popup fixed, Instance shows error as alert --- js/com/component/InstanceEditor.js | 8 ++++++++ js/m_apps/Instance.js | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/js/com/component/InstanceEditor.js b/js/com/component/InstanceEditor.js index 251b9eab..626ba0c4 100644 --- a/js/com/component/InstanceEditor.js +++ b/js/com/component/InstanceEditor.js @@ -433,6 +433,14 @@ define([ if (callback) { callback(varObj); } + }).catch(function(resultObj) { + let { result } = resultObj; + // show alert + com_util.renderAlertModal(result.ename + ': ' + result.evalue); + // callback + if (callback) { + callback(''); + } }); diff --git a/js/m_apps/Instance.js b/js/m_apps/Instance.js index 4cbfb1d2..8e05de59 100644 --- a/js/m_apps/Instance.js +++ b/js/m_apps/Instance.js @@ -157,6 +157,10 @@ define([ let component = evt.component; component.close(); }); + $(this.wrapSelector('#vp_instanceVariable')).on('focus_option_page', function(evt) { + let component = evt.component; + component.focus(); + }); $(this.wrapSelector('#vp_instanceVariable')).on('apply_option_page', function(evt) { let component = evt.component; // apply its value @@ -219,6 +223,21 @@ define([ return sbCode.toString(); } + hide() { + super.hide(); + this.state.subsetEditor && this.state.subsetEditor.hide(); + } + + close() { + super.close(); + this.state.subsetEditor && this.state.subsetEditor.close(); + } + + remove() { + super.remove(); + this.state.subsetEditor && this.state.subsetEditor.remove(); + } + updateValue(value) { let cmObj = this.getCodemirror('vp_instanceVariable'); if (cmObj && cmObj.cm) { From 215871d495f3315728f07a0c063d9063e1d4137f Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Mon, 17 Jan 2022 15:27:01 +0900 Subject: [PATCH 3/9] Load vp functions on kernel restart --- js/loadVisualpython.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/loadVisualpython.js b/js/loadVisualpython.js index 7ecf9025..78cde851 100644 --- a/js/loadVisualpython.js +++ b/js/loadVisualpython.js @@ -238,6 +238,13 @@ if (cfg.vp_section_display && vpFrame) { vpFrame.openVp(); } + + // Operations on kernel restart + events.on('kernel_ready.Kernel', function (evt, info) { + vpLog.display(VP_LOG_TYPE.LOG, 'vp operations for kernel ready...'); + // read vp functions + _readKernelFunction(); + }); } return { initVisualpython: initVisualpython, readConfig: readConfig }; From afcab1613f765a2e6a3ee6e6a1610e297f6284cc Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Mon, 17 Jan 2022 15:59:36 +0900 Subject: [PATCH 4/9] Snippets - hide menu after click --- js/m_apps/Snippets.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/m_apps/Snippets.js b/js/m_apps/Snippets.js index 11b0291c..713a52c4 100644 --- a/js/m_apps/Snippets.js +++ b/js/m_apps/Snippets.js @@ -194,6 +194,7 @@ define([ com_util.renderSuccessMessage('Default snippets imported'); } + $(that.wrapSelector('.vp-sn-menu-box')).hide(); evt.stopPropagation(); }); From 535ff59d01d2b9397392647738afae7ddd1c4618 Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Mon, 17 Jan 2022 16:02:35 +0900 Subject: [PATCH 5/9] Elif - popup same as if --- data/libraries.json | 2 +- js/m_logic/Elif.js | 59 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/data/libraries.json b/data/libraries.json index c4556704..812d75c7 100644 --- a/data/libraries.json +++ b/data/libraries.json @@ -384,7 +384,7 @@ "type" : "function", "level": 1, "name" : "elif", - "tag" : "ELSE,LOGIC", + "tag" : "ELIF,LOGIC", "path" : "visualpython - logic - control - elif", "desc" : "elif", "file" : "m_logic/Elif", diff --git a/js/m_logic/Elif.js b/js/m_logic/Elif.js index 3081f57a..a520c9f2 100644 --- a/js/m_logic/Elif.js +++ b/js/m_logic/Elif.js @@ -1,16 +1,16 @@ /* * Project Name : Visual Python * Description : GUI-based Python code generator - * File Name : If.js + * File Name : Elif.js * Author : Black Logic - * Note : Logic > if + * Note : Logic > elif * License : GNU GPLv3 with Visual Python special exception * Date : 2021. 11. 18 * Change Date : */ //============================================================================ -// [CLASS] If +// [CLASS] Elif //============================================================================ define([ 'vp_base/js/com/com_String', @@ -20,9 +20,9 @@ define([ ], function(com_String, com_util, PopupComponent, SuggestInput) { /** - * If + * Elif */ - class If extends PopupComponent { + class Elif extends PopupComponent { _init() { super._init(); /** Write codes executed before rendering */ @@ -31,7 +31,7 @@ define([ this.config.saveOnly = true; this.state = { - v1: [], + v1: [{ type: 'condition', value: {} }], ...this.state } } @@ -43,11 +43,23 @@ define([ // Add param $(this.wrapSelector('#vp_addCondition')).on('click', function() { that.state.v1.push({ type: 'condition', value: {} }); - $(that.wrapSelector('.v1 tbody')).append(that.templateForList(that.state.v1.length, {})); + $(that.wrapSelector('.v1-table')).append(that.templateForList(that.state.v1.length, {})); + + // enable and disable last one + // enable all operator + $(that.wrapSelector('.v1 .v1-i4')).prop('disabled', false); + // disable last operator + $(that.wrapSelector('.v1 tr:last .v1-i4')).prop('disabled', true); }); $(this.wrapSelector('#vp_addUserInput')).on('click', function() { that.state.v1.push({ type: 'input', value: {} }); - $(that.wrapSelector('.v1 tbody')).append(that.templateForInput(that.state.v1.length, {})); + $(that.wrapSelector('.v1-table')).append(that.templateForInput(that.state.v1.length, {})); + + // enable and disable last one + // enable all operator + $(that.wrapSelector('.v1 .v1-i4')).prop('disabled', false); + // disable last operator + $(that.wrapSelector('.v1 tr:last .v1-i4')).prop('disabled', true); }); // Delete param @@ -61,6 +73,9 @@ define([ $(that.wrapSelector('.v1-tr')).each((idx, tag) => { $(tag).find('th').text(idx + 1); }); + + // disable last operator + $(that.wrapSelector('.v1 tr:last .v1-i4')).prop('disabled', true); }); } @@ -94,7 +109,8 @@ define([ var page = new com_String(); page.appendLine(''); // page.appendLine(''); - page.appendLine(''); + page.appendLine(''); + page.appendLine(''); this.state.v1.forEach((v, idx) => { if (v.type == 'condition') { page.appendLine(this.templateForList(idx + 1, v.value)); @@ -118,8 +134,20 @@ define([ page.appendFormatLine('', idx); page.appendFormatLine('' , 'v1-i1', v.i1, 'Variable'); - page.appendFormatLine('' - , 'v1-i2', v.i2, 'Operator'); + // suggestInput for operator + let operList = ['', '==', '!=', 'in', 'not in', '<', '<=', '>', '>=']; + var suggestInput = new SuggestInput(); + suggestInput.addClass('vp-input w100 v1-i2'); + suggestInput.setSuggestList(function() { return operList; }); + suggestInput.setPlaceholder('Operator'); + suggestInput.setNormalFilter(false); + suggestInput.setValue(v.i2); + suggestInput.setSelectEvent(function(selectedValue) { + // trigger change + $(this.wrapSelector()).val(selectedValue); + $(this.wrapSelector()).trigger('change'); + }); + page.appendFormatLine('', suggestInput.toTagString()); page.appendFormatLine('' , 'v1-i3', v.i3, 'Variable'); page.appendFormatLine('
ParameterDefault Value
{0}{0}