diff --git a/apptool.js b/apptool.js index a3d4d33..2b03b4b 100644 --- a/apptool.js +++ b/apptool.js @@ -325,6 +325,15 @@ class appTool { return this.path.join(this.appDocRoot, filename); } + // Python コードフォーマッタ Black をコール + pyBeautify = (code) => { + let formatted = ''; + formatted = require('child_process').spawnSync('python3', ['-m', 'black', '-'], { input: code }).stdout.toString(); + if (!formatted) formatted = code; + return formatted; + } + + } // ブラウザ動作用 class webTool { @@ -377,6 +386,7 @@ class webTool { setWsChanged() { ; } killAllChildren() { ; } cleanupGPIO() { ; } + pyBeautify(code) { return code; } path = { join: function (a = '', b = '', c = '', d = '', e = '') { const removeTrailingSlash = path => path.endsWith('/') ? path.substr(0, path.length - 1) : path; @@ -387,6 +397,7 @@ class webTool { (e ? '/' + removeTrailingSlash(e) : '') } } + } // Electron 動作 / ブラウザ動作自動判別 @@ -437,4 +448,5 @@ if (!is_app) { } throw `ブロック「${block}」は、Web体験版ではご利用になれません。\n詳しくは https://ocoge.club/ をご覧ください。`; } + var setscriptlangtopy = () => apptool.lang = 'py'; } diff --git a/blocks/blocks.js b/blocks/blocks.js index 69a1aaa..492020a 100644 --- a/blocks/blocks.js +++ b/blocks/blocks.js @@ -1131,6 +1131,10 @@ Blockly.Blocks['oc_speechcommand_listen'] = { .appendField("を取得"); this.appendStatementInput("do") .setCheck(null); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("オーバーラップ係数") + .appendField(new FieldSlider(0.5, 0, 1, 0.05), "overlapFactor"); this.appendDummyInput() .setAlign(Blockly.ALIGN_RIGHT) .appendField("スコアしきい値") @@ -1147,10 +1151,12 @@ Blockly.JavaScript['oc_speechcommand_listen'] = function (block) { var variable_scores = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('scores'), Blockly.Names.NameType.VARIABLE); var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var number_probabilitythreshold = block.getFieldValue('probabilityThreshold'); + var number_overlapfactor = block.getFieldValue('overlapFactor'); var code = `_recognizer.listen(_result => { ${variable_scores} = _result.scores; ${statements_do} }, { + overlapFactor: ${number_overlapfactor}, probabilityThreshold: ${number_probabilitythreshold} }); `; @@ -3011,3 +3017,16 @@ Blockly.Python['ugj_controls_foreach'] = function (block) { // var code = `let _interval = setTimeout(async () => {\n${statements_do}}, ${value_sec}*1000);\n`; // return code; // }; + +Blockly.defineBlocksWithJsonArray([{ + "type": "toggle_lang", + "message0": "MicroPython Mode", + "colour": 0, + "tooltip": "実行すると秘密の MicorPython モードに移行します。JavaScript モードに戻るには、ワークスペースを再読み込みしてください。", + "helpUrl": "" +}]); +Blockly.JavaScript['toggle_lang'] = function (block) { + var code = `apptool.setLang('py'); +`; + return code; +}; diff --git a/blocks/index.js b/blocks/index.js index 8a7d5d0..c1decb0 100644 --- a/blocks/index.js +++ b/blocks/index.js @@ -1,7 +1,20 @@ +const current = (function () { + let r = ""; + if (document.currentScript) { + r = document.currentScript.src; + } else { + var scripts = document.getElementsByTagName('script'), + script = scripts[scripts.length - 1]; + if (script.src) { + r = script.src; + } + } + return r.replace(/[^/]*$/, '') +})(); var flyout_contents = []; const registerCategory = (category_dir, subcategories) => { for (let sbctgr of subcategories) { - let fname = ugj_const.blocks_dir + '/' + category_dir + "/" + sbctgr + "/index.js"; + let fname = current + category_dir + '/' + sbctgr + "/index.js"; let script = document.createElement('script'); script.type = 'text/javascript'; script.src = fname; diff --git a/index.html b/index.html index a89a69d..6d67da9 100644 --- a/index.html +++ b/index.html @@ -688,7 +688,6 @@ --> スコア - 0.75 @@ -969,7 +968,7 @@ - + @@ -1049,9 +1048,9 @@ + - diff --git a/index.js b/index.js index 4a1417a..9c20e14 100644 --- a/index.js +++ b/index.js @@ -362,18 +362,18 @@ const ugj_asyncIife = code => { return code; } -// Python コードフォーマッタ Black をコール -const ugj_pyBeautify = (code) => { - let formatted = ''; - formatted = require('child_process').spawnSync('python3', ['-m', 'black', '-'], { input: code }).stdout.toString(); - if (!formatted) formatted = code; - return formatted; -} +// // Python コードフォーマッタ Black をコール +// const ugj_pyBeautify = (code) => { +// let formatted = ''; +// formatted = require('child_process').spawnSync('python3', ['-m', 'black', '-'], { input: code }).stdout.toString(); +// if (!formatted) formatted = code; +// return formatted; +// } // コードフォーマッティング const ugj_formatCode = code => { if (apptool.lang == 'py') // フォーマッティング - code = ugj_pyBeautify(code); + code = apptool.pyBeautify(code); else code = js_beautify(code, { indent_size: 2 }); return code; diff --git a/package-lock.json b/package-lock.json index c7e5b63..6496548 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,14 +21,14 @@ "dracula-prism": "^2.1.13", "js-beautify": "^1.14.7", "node-abi": "^3.31.0", - "nodemailer": "^6.8.0", + "nodemailer": "^6.9.0", "prismjs": "^1.29.0" }, "devDependencies": { "@electron-forge/cli": "^6.0.4", "@electron-forge/maker-deb": "^6.0.4", "@electron/rebuild": "^3.2.10", - "electron": "^22.0.0" + "electron": "^22.0.1" } }, "local_modules/pigpio": { @@ -2107,9 +2107,9 @@ "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==" }, "node_modules/electron": { - "version": "22.0.0", - "resolved": "https://registry.npmjs.org/electron/-/electron-22.0.0.tgz", - "integrity": "sha512-cgRc4wjyM+81A0E8UGv1HNJjL1HBI5cWNh/DUIjzYvoUuiEM0SS0hAH/zaFQ18xOz2ced6Yih8SybpOiOYJhdg==", + "version": "22.0.1", + "resolved": "https://registry.npmjs.org/electron/-/electron-22.0.1.tgz", + "integrity": "sha512-05X/UmQOtUYwFmytY4/rc+4Iz+LYzHhftRZDkx1GQzyX/BxopStddG8LMcx3SESNk25F2J93oHv1Lzs6QWeCjA==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -4482,9 +4482,9 @@ } }, "node_modules/nodemailer": { - "version": "6.8.0", - "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz", - "integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.0.tgz", + "integrity": "sha512-jFaCEGTeT3E/m/5R2MHWiyQH3pSARECRUDM+1hokOYc3lQAAG7ASuy+2jIsYVf+RVa9zePopSQwKNVFH8DKUpA==", "engines": { "node": ">=6.0.0" } @@ -7885,9 +7885,9 @@ } }, "electron": { - "version": "22.0.0", - "resolved": "https://registry.npmjs.org/electron/-/electron-22.0.0.tgz", - "integrity": "sha512-cgRc4wjyM+81A0E8UGv1HNJjL1HBI5cWNh/DUIjzYvoUuiEM0SS0hAH/zaFQ18xOz2ced6Yih8SybpOiOYJhdg==", + "version": "22.0.1", + "resolved": "https://registry.npmjs.org/electron/-/electron-22.0.1.tgz", + "integrity": "sha512-05X/UmQOtUYwFmytY4/rc+4Iz+LYzHhftRZDkx1GQzyX/BxopStddG8LMcx3SESNk25F2J93oHv1Lzs6QWeCjA==", "dev": true, "requires": { "@electron/get": "^2.0.0", @@ -9678,9 +9678,9 @@ "dev": true }, "nodemailer": { - "version": "6.8.0", - "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz", - "integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ==" + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.0.tgz", + "integrity": "sha512-jFaCEGTeT3E/m/5R2MHWiyQH3pSARECRUDM+1hokOYc3lQAAG7ASuy+2jIsYVf+RVa9zePopSQwKNVFH8DKUpA==" }, "nopt": { "version": "5.0.0", diff --git a/package.json b/package.json index fb2819f..5c3bb82 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@electron-forge/cli": "^6.0.4", "@electron-forge/maker-deb": "^6.0.4", "@electron/rebuild": "^3.2.10", - "electron": "^22.0.0" + "electron": "^22.0.1" }, "dependencies": { "@blockly/field-slider": "^4.0.4", @@ -40,7 +40,7 @@ "dracula-prism": "^2.1.13", "js-beautify": "^1.14.7", "node-abi": "^3.31.0", - "nodemailer": "^6.8.0", + "nodemailer": "^6.9.0", "prismjs": "^1.29.0" }, "config": {