From 05dc7f77ccdee9ab6db9daf6650dad3d032f1654 Mon Sep 17 00:00:00 2001 From: Minku Koo Date: Wed, 3 Aug 2022 19:48:06 +0900 Subject: [PATCH 1/5] #155 - Add 'Comment Template' to comment logic block. add comment template function on comment logic block --- js/m_logic/Comment.js | 117 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 7 deletions(-) diff --git a/js/m_logic/Comment.js b/js/m_logic/Comment.js index 83ba3e75..37c36d5e 100644 --- a/js/m_logic/Comment.js +++ b/js/m_logic/Comment.js @@ -6,7 +6,7 @@ * Note : Logic > comment * License : GNU GPLv3 with Visual Python special exception * Date : 2021. 11. 18 - * Change Date : + * Change Date : 2022. 08. 02 */ //============================================================================ @@ -18,6 +18,67 @@ define([ ], function(com_String, PopupComponent) { const COMMENT_DEFAULT_CODE = '# Write down comments' + // Templates from NumPy Style Python Docstrings. + const COMMENT_CLASS_TEMPLATE = +` +"""Summarize the class in one line. + +Several sentences ... +providing an extended description. + +Note +---------- +Note about this class. + +Parameters +---------- +param1 : param_type + Parameter description. +param2 : param_type + Parameter description. + +Attributes +---------- +attr1 : attr_type + Attibute description. +attr2 : attr_type + Attibute description. + +Examples +---------- + +References +---------- + +""" +` + const COMMENT_METHOD_TEMPLATE = +` +"""Summarize the function in one line. + +Several sentences ... +providing an extended description. + +Parameters +---------- +param1 : param_type + Parameter description. +param2 : param_type + Parameter description. + +Returns +------- +return_type + Return description. + +Note +---------- + +Examples +---------- + +""" +` /** * Comment @@ -29,25 +90,67 @@ define([ this.config.dataview = false; this.config.codeview = false; this.config.saveOnly = true; + + this.cmKey = 'code'; // Code Mirror Key + this.selectBoxClassName = 'vp-ct-option'; // Select Box ClassName this.state = { code: COMMENT_DEFAULT_CODE, ...this.state + }; + + this.cmTemplates = { // a kind of templates + Template : COMMENT_DEFAULT_CODE, + Class : COMMENT_CLASS_TEMPLATE, + Method : COMMENT_METHOD_TEMPLATE } - this._addCodemirror('code', this.wrapSelector('#code')); + this._addCodemirror(this.cmKey, this.wrapSelector('#code')); } _bindEvent() { super._bindEvent(); - /** Implement binding events */ + + var commentTemplates = this.cmTemplates; + var cm_key = this.cmKey; + let cmCodeListTemp = this.cmCodeList; + + // Select box change Event + $('.' + this.selectBoxClassName).on('change', function(){ + // get code mirror object + let targetCmObj = cmCodeListTemp.filter(obj => obj.key == cm_key); + var templateOption = $(this).val(); + let cm = targetCmObj[0].cm; + + // Change Code Mirror Text + if(templateOption == 'vp_template_class'){ + cm.setValue(commentTemplates.Class); + }else if(templateOption == 'vp_template_method'){ + cm.setValue(commentTemplates.Method); + }else if(templateOption == 'vp_template_template'){ + cm.setValue(commentTemplates.Template); + } + + cm.save(); + }); + } + templateForBody() { /** Implement generating template */ var page = new com_String(); page.appendFormatLine('' , this.state.code); + // add select box + page.appendFormatLine(''); + return page.toString(); } @@ -55,19 +158,19 @@ define([ super.open(); if (this.state.code === COMMENT_DEFAULT_CODE) { - // set default selection - let cmObj = this.getCodemirror('code'); + + let cmObj = this.getCodemirror(this.cmKey); if (cmObj && cmObj.cm) { cmObj.cm.setSelection({ line: 0, ch: 2 }, { line: 0 }); cmObj.cm.focus(); } } } - + generateCode() { return this.state.code; } - + } return Comment; From 9ab1aacf2ae307f3cb7589d52b557b698b33ae32 Mon Sep 17 00:00:00 2001 From: Minku Koo Date: Wed, 3 Aug 2022 21:23:08 +0900 Subject: [PATCH 2/5] add try-except new function --- js/m_logic/Try.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/js/m_logic/Try.js b/js/m_logic/Try.js index 691c9096..e8799a90 100644 --- a/js/m_logic/Try.js +++ b/js/m_logic/Try.js @@ -6,7 +6,7 @@ * Note : Logic > try * License : GNU GPLv3 with Visual Python special exception * Date : 2021. 11. 18 - * Change Date : + * Change Date : 2022. 08. 0x */ //============================================================================ @@ -31,20 +31,38 @@ define([ this.state = { ...this.state } + + this.exceptClassName = 'vp-try-except-input'; + this.addBtnIdName = 'vp-try-add-btn'; + this.inputBoxText = 'Input Error Type'; this._addCodemirror('code', this.wrapSelector('#code')); } _bindEvent() { super._bindEvent(); + var page = new com_String(); + let that = this; /** Implement binding events */ + $(this.wrapSelector('#' + this.addBtnIdName)).on('click', function() { + alert("btn click!"); + // add except input + }); } templateForBody() { - return ''; + var page = new com_String(); + // add Except Input + page.appendLine('
Except
'); + page.appendFormatLine('' + ,this.exceptClassName , this.inputBoxText, this.inputBoxText); + // add +except btn + page.appendFormatLine('', this.addBtnIdName); + return page.toString(); } generateCode() { + // generate code new! return 'try:'; } From 4a34b5e27a232c539c19d1b5f08b35c0f8d67755 Mon Sep 17 00:00:00 2001 From: "minku.koo" Date: Thu, 4 Aug 2022 02:30:20 +0900 Subject: [PATCH 3/5] reorigin Try.js --- js/m_logic/Try.js | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/js/m_logic/Try.js b/js/m_logic/Try.js index e8799a90..691c9096 100644 --- a/js/m_logic/Try.js +++ b/js/m_logic/Try.js @@ -6,7 +6,7 @@ * Note : Logic > try * License : GNU GPLv3 with Visual Python special exception * Date : 2021. 11. 18 - * Change Date : 2022. 08. 0x + * Change Date : */ //============================================================================ @@ -31,38 +31,20 @@ define([ this.state = { ...this.state } - - this.exceptClassName = 'vp-try-except-input'; - this.addBtnIdName = 'vp-try-add-btn'; - this.inputBoxText = 'Input Error Type'; this._addCodemirror('code', this.wrapSelector('#code')); } _bindEvent() { super._bindEvent(); - var page = new com_String(); - let that = this; /** Implement binding events */ - $(this.wrapSelector('#' + this.addBtnIdName)).on('click', function() { - alert("btn click!"); - // add except input - }); } templateForBody() { - var page = new com_String(); - // add Except Input - page.appendLine('
Except
'); - page.appendFormatLine('' - ,this.exceptClassName , this.inputBoxText, this.inputBoxText); - // add +except btn - page.appendFormatLine('', this.addBtnIdName); - return page.toString(); + return ''; } generateCode() { - // generate code new! return 'try:'; } From 4f227771103f353debd04c8bad71655df1da82e5 Mon Sep 17 00:00:00 2001 From: Minku Koo Date: Fri, 5 Aug 2022 21:23:09 +0900 Subject: [PATCH 4/5] update create dict template update creating template in 'dict' --- data/m_library/pythonLibrary.js | 3 +- js/com/com_generatorV2.js | 101 +++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/data/m_library/pythonLibrary.js b/data/m_library/pythonLibrary.js index 2407ee5a..9b9b2542 100644 --- a/data/m_library/pythonLibrary.js +++ b/data/m_library/pythonLibrary.js @@ -279,7 +279,8 @@ define([ { name: 'i0', label: 'Input Data', - component: ['var_select'] + component: ['key_value'] + // component: ['var_select'] }, { name: 'o0', diff --git a/js/com/com_generatorV2.js b/js/com/com_generatorV2.js index 41f60320..e248a410 100644 --- a/js/com/com_generatorV2.js +++ b/js/com/com_generatorV2.js @@ -30,6 +30,7 @@ define([ 'scalar': 'Scalar Value', 'param': 'Param Value', 'dtype': 'Dtype', + 'key_val': 'Key Value', 'bool_checkbox': 'Boolean', 'bool_select': 'Select Boolean', 'option_select': 'Select option', @@ -256,6 +257,9 @@ define([ case 'dtype': content = renderDtypeSelector(pageThis, obj, state); break; + case 'key_value': + content = renderKeyValue(pageThis, obj, state); + break; case 'tabblock': content = renderTabBlock(pageThis, obj, state); break; @@ -635,10 +639,11 @@ define([ */ var vp_codeGenerator = function(pageThis, package, state = {}, etcOptions = '') { var code = package.code; - + console.log("code is " + code); try { package.options && package.options.forEach(function(v, i) { var val = state[v.name]; + console.log("val is " + val); if (val == undefined || val == '' || val == v.default) { val = vp_getTagValue(pageThis, v); } @@ -1101,6 +1106,43 @@ define([ return slctTag; } + // (pageThis, obj, state) + var renderKeyValue = function(pageThis, obj, state) { + let arrKey = obj.name + '_key_val'; + let arrState = [ '' ]; + let value = `${arrState.join(',')}`; + if (state[arrKey] == undefined) { + pageThis.setState({ [arrKey]: arrState }); + pageThis.setState({ [obj.name]: value}); + } else { + arrState = state[arrKey]; + value = `${arrState.join(',')}`; + } + + let contentTag = $(`
`); + $(contentTag).attr({ + 'data-id': obj.name + }); + contentTag.data('obj', obj); + // Array Items + let arrItems = $(`
`); + arrState.forEach((item, idx) => { + arrItems.append($(`
+
+ ${idx + 1} +
+ + + + +
`)); + }); + contentTag.append(arrItems); + // add button + contentTag.append($(``)); + return contentTag; + } + var renderTabBlock = function(pageThis, obj, defaultValue) { return $(''); } @@ -1313,7 +1355,7 @@ define([ pageThis.setState({ [id]: code }); $(pageThis.wrapSelector('#'+id)).val(code); }); - + //==================================================================== // Event for ndArr //==================================================================== @@ -1367,6 +1409,61 @@ define([ pageThis.setState({ [id]: code }); $(pageThis.wrapSelector('#'+id)).val(code); }); + //==================================================================== + // Event for ndArr + //==================================================================== + $(selector).on('click', '.vp-key-val-del', function() { + let id = $(this).closest('.vp-key-val-box').data('id'); + let arrId = id + '_key_val'; + let idx = $(this).parent().find('.vp-key-val-item').data('idx'); + // update state + let state = pageThis.getState(arrId); + state.splice(idx, 1); + pageThis.setState({ [arrId]: state }); + pageThis.setState({ [id]: `${state.join(',')}` }); + // re-render + let obj = $(this).closest('.vp-key-val-box').data('obj'); + $(this).closest('.vp-key-val-box').replaceWith(function() { + return renderKeyValue(pageThis, obj, pageThis.getState()); + }); + }); + + $(selector).on('click', '.vp-key-val-add', function() { + //alert("press key val add"); + let id = $(this).closest('.vp-key-val-box').data('id'); + let arrId = id + '_key_val'; + let idx = 0; + // update state + let state = pageThis.getState(arrId); + if (!state) { + state = [ ]; + } else { + idx = state.length; + } + state.push(0); + pageThis.setState({ [arrId]: state }); + pageThis.setState({ [id]: `${state.join(',')}` }); + // re-render + let obj = $(this).closest('.vp-key-val-box').data('obj'); + $(this).closest('.vp-key-val-box').replaceWith(function() { + return renderKeyValue(pageThis, obj, pageThis.getState()); + }); + }); + + $(selector).on('change', '.vp-key-val-item', function() { + //alert("change key val"); + let id = $(this).closest('.vp-key-val-box').data('id'); + let arrId = id + '_key_val'; + let idx = $(this).data('idx'); + let value = $(this).val(); + // update state + let state = pageThis.getState(arrId); + state[idx] = value; + let code = `${state.join(',')}`; + pageThis.setState({ [arrId]: state }); + pageThis.setState({ [id]: code }); + $(pageThis.wrapSelector('#'+id)).val(code); + }); //==================================================================== From 4d7866e16d0326133da7058794dcdf1dd7673897 Mon Sep 17 00:00:00 2001 From: Minku Koo Date: Sat, 6 Aug 2022 20:32:43 +0900 Subject: [PATCH 5/5] update create dict v0.2 update create dict v0.2 --- js/com/com_generatorV2.js | 4 ++++ js/com/component/NumpyComponent.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/js/com/com_generatorV2.js b/js/com/com_generatorV2.js index e248a410..bcb5922e 100644 --- a/js/com/com_generatorV2.js +++ b/js/com/com_generatorV2.js @@ -643,6 +643,8 @@ define([ try { package.options && package.options.forEach(function(v, i) { var val = state[v.name]; + console.log("v.name is " + v.name); + console.log("v is " , v); console.log("val is " + val); if (val == undefined || val == '' || val == v.default) { val = vp_getTagValue(pageThis, v); @@ -654,6 +656,7 @@ define([ } // if no value, replace it code = code.split(id).join(''); + console.log("code2 is " + code); } else { // text quotation if (v.type == 'text') { @@ -680,6 +683,7 @@ define([ } } code = code.split(id).join(val); + console.log("code3 is " + code); } }); diff --git a/js/com/component/NumpyComponent.js b/js/com/component/NumpyComponent.js index 224e74fb..7d3666af 100644 --- a/js/com/component/NumpyComponent.js +++ b/js/com/component/NumpyComponent.js @@ -39,8 +39,10 @@ define([ let findPackage = null; if (packageName == 'numpy') { findPackage = numpyLibrary.NUMPY_LIBRARIES[this.packageId]; + console.log("packge numpy"); } else if (packageName == 'python') { findPackage = pythonLibrary.PYTHON_LIBRARIES[this.packageId]; + console.log("packge python !!"); } if (findPackage) { this.package = JSON.parse(JSON.stringify(findPackage)); // deep copy of package @@ -159,6 +161,7 @@ define([ } generateCode() { + alert("this is numpy component"); let code = com_generatorV2.vp_codeGenerator(this, this.package, this.state); return code; }