mirror of
https://github.com/ocogeclub/ocoge.git
synced 2024-11-21 15:19:48 +00:00
[update] いくつかのクラスの名前を変更
This commit is contained in:
parent
a37760af85
commit
49f3712704
@ -21,9 +21,9 @@ const ugj_const = {
|
||||
dev_hash: '4e9205f9b7e571bec1aa52ab7871f420684fcf96149672a4d550a95863d6b072'
|
||||
}
|
||||
|
||||
/** クラス elUtil ****************************************************************** */
|
||||
/** クラス appTool ****************************************************************** */
|
||||
// Electron 動作用
|
||||
class elUtil {
|
||||
class appTool {
|
||||
constructor() {
|
||||
this.path = require('path') //window.ocogeapi.path
|
||||
this.fs = require('fs') //window.ocogeapi.fs
|
||||
@ -316,7 +316,7 @@ class elUtil {
|
||||
|
||||
// PyBfm を起動
|
||||
launchPyBfm() {
|
||||
let script_path = this.path.join(elutil.library_path, 'pybfm.py');
|
||||
let script_path = this.path.join(apptool.library_path, 'pybfm.py');
|
||||
require('child_process').spawn('python3', [script_path]);
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ class elUtil {
|
||||
|
||||
}
|
||||
// ブラウザ動作用
|
||||
class brUtil {
|
||||
class webTool {
|
||||
constructor() {
|
||||
// GPIOブロックは使えません
|
||||
this.gpio_backend = ugj_const.pig;
|
||||
@ -385,24 +385,24 @@ class brUtil {
|
||||
|
||||
// Electron 動作 / ブラウザ動作自動判別
|
||||
// const is_el = (typeof window.ocogeapi !== 'undefined')
|
||||
const is_el = (typeof require === 'function');
|
||||
const is_app = (typeof require === 'function');
|
||||
|
||||
// utilクラスのインスタンスを返す
|
||||
const elUtil_new = () => {
|
||||
if (is_el) {
|
||||
let el = new elUtil;
|
||||
el.init();
|
||||
return el;
|
||||
const appTool_new = () => {
|
||||
if (is_app) {
|
||||
let ap = new appTool;
|
||||
ap.init();
|
||||
return ap;
|
||||
}
|
||||
else return new brUtil;
|
||||
else return new webTool;
|
||||
}
|
||||
|
||||
// "require" for web browsers if contextIsolation is false && nodeIntegration is true:
|
||||
if (!is_el) {
|
||||
if (!is_app) {
|
||||
var require = module_name => {
|
||||
let block;
|
||||
switch (module_name) {
|
||||
case '@tensorflow/tfjs':
|
||||
case '@tensorflow/tfjs-node':
|
||||
block = 'TensorFlow';
|
||||
break;
|
||||
case '@tensorflow-models/blazeface':
|
@ -185,7 +185,7 @@ Blockly.Blocks['ugj_gpio_open'] = {
|
||||
};
|
||||
Blockly.JavaScript['ugj_gpio_open'] = function (block) {
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + elutil.gpio_backend + `');`]
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||
);
|
||||
var code = `await _pi.gpio_open();\n`; //
|
||||
return code;
|
||||
@ -540,7 +540,7 @@ Blockly.JavaScript['ugj_serial_open'] = function (block) {
|
||||
// var value_tty = Blockly.JavaScript.valueToCode(block, 'tty', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var dropdown_baud = block.getFieldValue('baud');
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + elutil.gpio_backend + `');`]
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||
);
|
||||
var code = `await _pi.serial_open('/dev/serial0', ${dropdown_baud});\n`;
|
||||
return code;
|
||||
@ -680,9 +680,9 @@ Blockly.Blocks['ugj_i2c_open'] = {
|
||||
Blockly.JavaScript['ugj_i2c_open'] = function (block) {
|
||||
var value_i2c_address = Blockly.JavaScript.valueToCode(block, 'i2c_address', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + elutil.gpio_backend + `');`]
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||
);
|
||||
var code = `await _pi.i2c_open(${elutil.i2c_bus}, ${value_i2c_address});\n`;
|
||||
var code = `await _pi.i2c_open(${apptool.i2c_bus}, ${value_i2c_address});\n`;
|
||||
return code;
|
||||
};
|
||||
Blockly.Python['ugj_i2c_open'] = function (block) {
|
||||
@ -1106,8 +1106,8 @@ Blockly.JavaScript['oc_speechcommands_init'] = function (block) {
|
||||
let cp = undefined, md = undefined;
|
||||
if (value_custom_model != "''") {
|
||||
let cm = value_custom_model.replace(/(^'|'$)/g, '');
|
||||
cp = `'file://${elutil.path.join(cm, 'model.json')}'`;
|
||||
md = `'file://${elutil.path.join(cm, 'metadata.json')}'`;
|
||||
cp = `'file://${apptool.path.join(cm, 'model.json')}'`;
|
||||
md = `'file://${apptool.path.join(cm, 'metadata.json')}'`;
|
||||
}
|
||||
var code = `const _checkpointURL = ${cp};
|
||||
const _metadataURL = ${md};
|
||||
@ -1262,7 +1262,7 @@ Blockly.JavaScript['ugj_canvas_loadimg'] = function (block) {
|
||||
var value_imgfilename = Blockly.JavaScript.valueToCode(block, 'imgfilename', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var code = [
|
||||
`let _img = new Image();`,
|
||||
`_img.src = '${elutil.doc_root}' + ${value_imgfilename};`,
|
||||
`_img.src = '${apptool.doc_root}' + ${value_imgfilename};`,
|
||||
`_img.onload = () => _ctx.drawImage(img,0,0);`,
|
||||
// `ugj_canvasImg('${ugj_const.doc_root}' + ${value_imgfilename});`,
|
||||
''
|
||||
@ -1739,7 +1739,7 @@ Blockly.Blocks['ugj_library_skyway'] = {
|
||||
}
|
||||
};
|
||||
Blockly.JavaScript['ugj_library_skyway'] = function (block) {
|
||||
var code = `'${elutil.path.join(elutil.library_path, 'skyway.min.js')}'`;
|
||||
var code = `'${apptool.path.join(apptool.library_path, 'skyway.min.js')}'`;
|
||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||
};
|
||||
|
||||
@ -2044,7 +2044,7 @@ Blockly.Blocks['ugj_file_readsync'] = {
|
||||
Blockly.JavaScript['ugj_file_readsync'] = function (block) {
|
||||
var value_filename = Blockly.JavaScript.valueToCode(block, 'filename', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var dropdown_encoding = block.getFieldValue('encoding');
|
||||
let filepath = elutil.path.join(elutil.doc_root, value_filename.replace(/\'/g, ''));
|
||||
let filepath = apptool.path.join(apptool.doc_root, value_filename.replace(/\'/g, ''));
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_fs', [`const _fs = require('fs');`]
|
||||
);
|
||||
@ -2270,7 +2270,7 @@ Blockly.Blocks['aquestalk_pi'] = {
|
||||
};
|
||||
Blockly.JavaScript['aquestalk_pi'] = function (block) {
|
||||
var value_talk = Blockly.JavaScript.valueToCode(block, 'talk', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var code = `'${elutil.path.join(elutil.executable_path, 'aquestalkpi/AquesTalkPi')} -g 50 ' + ${value_talk} + ' | aplay', { shell: true }`;
|
||||
var code = `'${apptool.path.join(apptool.executable_path, 'aquestalkpi/AquesTalkPi')} -g 50 ' + ${value_talk} + ' | aplay', { shell: true }`;
|
||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||
};
|
||||
|
||||
@ -2292,7 +2292,7 @@ Blockly.Blocks['ugj_child_fswebcam'] = {
|
||||
};
|
||||
Blockly.JavaScript['ugj_child_fswebcam'] = function (block) {
|
||||
var value_filename = Blockly.JavaScript.valueToCode(block, 'filename', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var code = `'fswebcam', ['-r', '480x360', '${elutil.doc_root}' + ${value_filename}]`;
|
||||
var code = `'fswebcam', ['-r', '480x360', '${apptool.doc_root}' + ${value_filename}]`;
|
||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||
};
|
||||
|
||||
@ -2310,7 +2310,7 @@ Blockly.Blocks['ugj_child_julius'] = {
|
||||
}
|
||||
};
|
||||
Blockly.JavaScript['ugj_child_julius'] = function (block) {
|
||||
var code = `'${elutil.path.join(elutil.executable_path, 'julius/julius-simple')}', ['-C', '${elutil.path.join(elutil.executable_path, 'julius/dictation-kit/am-gmm.jconf')}', '-gram', '${elutil.path.join(elutil.executable_path, 'julius/dic/assistant')}', '-nostrip']`;
|
||||
var code = `'${apptool.path.join(apptool.executable_path, 'julius/julius-simple')}', ['-C', '${apptool.path.join(apptool.executable_path, 'julius/dictation-kit/am-gmm.jconf')}', '-gram', '${apptool.path.join(apptool.executable_path, 'julius/dic/assistant')}', '-nostrip']`;
|
||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||
};
|
||||
// irrp.py - pigpioによる赤外線リモコンの学習
|
||||
@ -2331,7 +2331,7 @@ Blockly.Blocks['ugj_child_irrecord'] = {
|
||||
};
|
||||
Blockly.JavaScript['ugj_child_irrecord'] = function (block) {
|
||||
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var code = `'python3', ['${elutil.path.join(elutil.library_path, 'irrp.py')}', '-r', '-g', '${value_gpio}', 'signal', '--post', '130']`;
|
||||
var code = `'python3', ['${apptool.path.join(apptool.library_path, 'irrp.py')}', '-r', '-g', '${value_gpio}', 'signal', '--post', '130']`;
|
||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||
};
|
||||
// 送信
|
||||
@ -2356,7 +2356,7 @@ Blockly.Blocks['ugj_child_irplayback'] = {
|
||||
Blockly.JavaScript['ugj_child_irplayback'] = function (block) {
|
||||
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var value_signal = Blockly.JavaScript.valueToCode(block, 'signal', Blockly.JavaScript.ORDER_ATOMIC);//.replace('{','\\{').replace('}','\\}').replace(/"/g,'\\"').replace(/ /g,'\\ ')
|
||||
var code = `'python3', ['${elutil.path.join(elutil.library_path, 'irrp.py')}', '-p', '-g', '${value_gpio}', '--irdata', ${value_signal}, 'signal']`;
|
||||
var code = `'python3', ['${apptool.path.join(apptool.library_path, 'irrp.py')}', '-p', '-g', '${value_gpio}', '--irdata', ${value_signal}, 'signal']`;
|
||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||
};
|
||||
// ハッシュ生成
|
||||
@ -2378,7 +2378,7 @@ Blockly.Blocks['ugj_child_irrcvr'] = {
|
||||
Blockly.JavaScript['ugj_child_irrcvr'] = function (block) {
|
||||
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
// var code = `'python3', ['./scripts/irrcvr.py', '-g', '${value_gpio}']`;
|
||||
var code = `'${elutil.path.join(elutil.executable_path, 'ir_hash/ir_hash')}', ['${value_gpio}']`;
|
||||
var code = `'${apptool.path.join(apptool.executable_path, 'ir_hash/ir_hash')}', ['${value_gpio}']`;
|
||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||
};
|
||||
|
||||
@ -2398,7 +2398,7 @@ Blockly.Blocks['ugj_child_pyscript'] = {
|
||||
Blockly.JavaScript['ugj_child_pyscript'] = function (block) {
|
||||
var value_script_path = Blockly.JavaScript.valueToCode(block, 'script_path', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
// TODO: Assemble JavaScript into code variable.
|
||||
var code = `'python3', ['${elutil.doc_root}/' + ${value_script_path}]`;
|
||||
var code = `'python3', ['${apptool.doc_root}/' + ${value_script_path}]`;
|
||||
// TODO: Change ORDER_NONE to the correct strength.
|
||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||
};
|
||||
|
@ -59,13 +59,13 @@ Blockly.Blocks['ugj_grideye_init'] = {
|
||||
Blockly.JavaScript['ugj_grideye_init'] = function (block) {
|
||||
var dropdown_addr = block.getFieldValue('addr');
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + elutil.gpio_backend + `');`]
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||
);
|
||||
let modpath = elutil.path.join(elutil.blocks_sensors_dir, 'amg8833', 'AMG8833x.js');
|
||||
let modpath = apptool.path.join(apptool.blocks_sensors_dir, 'amg8833', 'AMG8833x.js');
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_amg8833', [`const _amg8833 = require('${modpath}');`]
|
||||
);
|
||||
var code = `await _amg8833.init(${elutil.i2c_bus}, ${dropdown_addr}, window.addEventListener);\n`;
|
||||
var code = `await _amg8833.init(${apptool.i2c_bus}, ${dropdown_addr}, window.addEventListener);\n`;
|
||||
return code;//
|
||||
};
|
||||
/********************** */
|
||||
|
@ -18,14 +18,14 @@ Blockly.Blocks['ugj_bme280'] = {
|
||||
Blockly.JavaScript['ugj_bme280'] = function (block) {
|
||||
var dropdown_addr = block.getFieldValue('addr');
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + elutil.gpio_backend + `');`]
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||
);
|
||||
let modpath = elutil.path.join(elutil.blocks_sensors_dir, 'bme280', 'BME280x.js');
|
||||
let modpath = apptool.path.join(apptool.blocks_sensors_dir, 'bme280', 'BME280x.js');
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_bme280', [`const _bme280 = require('${modpath}');`]
|
||||
);
|
||||
var code = `const options = {
|
||||
i2cBusNo: ${elutil.i2c_bus},
|
||||
i2cBusNo: ${apptool.i2c_bus},
|
||||
i2cAddress: ${dropdown_addr}
|
||||
};
|
||||
await _bme280.init(options);
|
||||
|
@ -15,7 +15,7 @@ Blockly.Blocks['ugj_dht11'] = {
|
||||
};
|
||||
Blockly.JavaScript['ugj_dht11'] = function (block) {
|
||||
var value_pin = Blockly.JavaScript.valueToCode(block, 'pin', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
let pypath = elutil.path.join(elutil.blocks_sensors_dir, 'dht11', 'dht11.py');
|
||||
let pypath = apptool.path.join(apptool.blocks_sensors_dir, 'dht11', 'dht11.py');
|
||||
var code = `let _th = require('child_process').spawnSync('python3', ['${pypath}', '${value_pin}'], {timeout: 5000}).stdout.toString();
|
||||
let _dhtdata = JSON.parse(_th);`;
|
||||
// let _dht11data[0] =
|
||||
|
@ -33,13 +33,13 @@ Blockly.Blocks['ugj_gesture_init'] = {
|
||||
Blockly.JavaScript['ugj_gesture_init'] = function (block) {
|
||||
var value_i2c_addr = Blockly.JavaScript.valueToCode(block, 'i2c_addr', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + elutil.gpio_backend + `');`]
|
||||
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||
);
|
||||
let modpath = elutil.path.join(elutil.blocks_sensors_dir, 'paj7620', 'PAJ7620x.js');
|
||||
let modpath = apptool.path.join(apptool.blocks_sensors_dir, 'paj7620', 'PAJ7620x.js');
|
||||
Blockly.JavaScript.provideFunction_(
|
||||
'require_paj7620', [`const _paj7620 = require('${modpath}');`]
|
||||
);
|
||||
var code = `await _paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr}, window.addEventListener);
|
||||
var code = `await _paj7620.init(${apptool.i2c_bus}, ${value_i2c_addr}, window.addEventListener);
|
||||
`;
|
||||
return code;
|
||||
};
|
||||
|
@ -1044,7 +1044,7 @@
|
||||
<script src="./node_modules/@blockly/field-slider/dist/index.js"></script>
|
||||
<script src="./lib/custom-dialog.js"></script>
|
||||
<script src="./blocks/blocks.js"></script>
|
||||
<script src="./apptools.js"></script>
|
||||
<script src="./apptool.js"></script>
|
||||
<script src="./index.js"></script>
|
||||
<script src="./node_modules/js-beautify/js/lib/beautify.js"></script>
|
||||
<script src="./node_modules/prismjs/prism.js"></script>
|
||||
|
50
index.js
50
index.js
@ -2,12 +2,12 @@
|
||||
|
||||
const { checkPrimeSync } = require('crypto');
|
||||
|
||||
let elutil = elUtil_new();
|
||||
let apptool = appTool_new();
|
||||
|
||||
|
||||
const testfunc = async () => {
|
||||
elutil.openURL('http://ocoge.club');
|
||||
// console.log(elutil.app_path);
|
||||
apptool.openURL('http://ocoge.club');
|
||||
// console.log(apptool.app_path);
|
||||
}
|
||||
|
||||
//============ User Customize Start ===============
|
||||
@ -258,10 +258,10 @@ let ugj_sounds = (names => { // サウンドファイルのいろいろの配列
|
||||
|
||||
// マスコット選択
|
||||
const ugj_selectMascot = async () => {
|
||||
let fname = await elutil.selectMascotFile();
|
||||
let fname = await apptool.selectMascotFile();
|
||||
if (fname) {
|
||||
ugj_canvasBgImg(fname, -1, -1);
|
||||
elutil.setMascotFilePath(fname);
|
||||
apptool.setMascotFilePath(fname);
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,7 +289,7 @@ const ugj_newWorkspace = () => {
|
||||
ugj_confirm('新規ワークスペース', '保存していない内容はすべて破棄されます。よろしいですか?', okey => {
|
||||
if (okey) {
|
||||
workspace.clear();
|
||||
elutil.newFile();
|
||||
apptool.newFile();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -298,12 +298,12 @@ const ugj_newWorkspace = () => {
|
||||
const ugj_saveWorkspaceToFile = async () => {
|
||||
let xml = Blockly.Xml.workspaceToDom(workspace);
|
||||
let xml_text = Blockly.Xml.domToText(xml);
|
||||
if (await elutil.saveWsFile(xml_text) === false) {
|
||||
if (await apptool.saveWsFile(xml_text) === false) {
|
||||
window.alert('保存できませんでした。');
|
||||
}
|
||||
}
|
||||
const ugj_loadWorkspaceFromFile = async () => {
|
||||
let xml_text = await elutil.loadWsFile();
|
||||
let xml_text = await apptool.loadWsFile();
|
||||
if (xml_text.length > 0) {
|
||||
let xml = Blockly.Xml.textToDom(xml_text);
|
||||
Blockly.Xml.domToWorkspace(xml, workspace);
|
||||
@ -312,7 +312,7 @@ const ugj_loadWorkspaceFromFile = async () => {
|
||||
|
||||
// ワークスペースを別名で保存
|
||||
const ugj_saveWorkspaceAs = () => {
|
||||
elutil.newFile();
|
||||
apptool.newFile();
|
||||
ugj_saveWorkspaceToFile();
|
||||
}
|
||||
|
||||
@ -337,7 +337,7 @@ const ugj_loadWorkspace = () => {
|
||||
// コード生成
|
||||
const ugj_generateCode = () => {
|
||||
let code;
|
||||
if (elutil.lang == 'py') { // Python コード出力
|
||||
if (apptool.lang == 'py') { // Python コード出力
|
||||
try {
|
||||
code = Blockly.Python.workspaceToCode(workspace);
|
||||
} catch (e) { // Pythonコードを持たないブロックがある場合
|
||||
@ -372,7 +372,7 @@ const ugj_pyBeautify = (code) => {
|
||||
|
||||
// コードフォーマッティング
|
||||
const ugj_formatCode = code => {
|
||||
if (elutil.lang == 'py') // フォーマッティング
|
||||
if (apptool.lang == 'py') // フォーマッティング
|
||||
code = ugj_pyBeautify(code);
|
||||
else
|
||||
code = js_beautify(code, { indent_size: 2 });
|
||||
@ -385,12 +385,12 @@ const ugj_runCode = async () => {
|
||||
let btnel = document.getElementById('runbtn');
|
||||
btnel.disabled = true;
|
||||
let code = ugj_generateCode();
|
||||
if (elutil.lang == 'js') {
|
||||
if (apptool.lang == 'js') {
|
||||
let AsyncFunction = Object.getPrototypeOf(async function () { }).constructor
|
||||
let ocogeFunc = new AsyncFunction(code);
|
||||
await ocogeFunc().catch(e => { window.alert(e); });
|
||||
console.log('Code Execution done.');
|
||||
} else if (elutil.lang == 'py') {
|
||||
} else if (apptool.lang == 'py') {
|
||||
if (code) ugj_spawnPyboard(code, 'r');
|
||||
}
|
||||
btnel.disabled = false;
|
||||
@ -398,7 +398,7 @@ const ugj_runCode = async () => {
|
||||
|
||||
// Pyboard ocoge
|
||||
const ugj_spawnPyboard = (code, mode) => {
|
||||
let script_path = elutil.path.join(elutil.library_path, 'pybtool.py');
|
||||
let script_path = apptool.path.join(apptool.library_path, 'pybtool.py');
|
||||
let p = require('child_process').spawn('python3', [script_path, mode], { env: { "PYTHONUTF8": "1" } });
|
||||
p.stdin.write(code);
|
||||
p.stdin.end();
|
||||
@ -420,14 +420,14 @@ const ugj_showCode = () => {
|
||||
let code = ugj_generateCode(); // コード生成
|
||||
|
||||
content.innerHTML = ugj_htmlEntities(ugj_formatCode(code));
|
||||
if (elutil.lang == 'py') content.setAttribute('class', 'language-python');
|
||||
if (apptool.lang == 'py') content.setAttribute('class', 'language-python');
|
||||
else content.setAttribute('class', 'language-javascript');
|
||||
Prism.highlightElement(content);
|
||||
|
||||
dialog.showModal();
|
||||
|
||||
const save_to_file = code => {
|
||||
if (elutil.saveFile(code, elutil.lang) === false) window.alert('保存できませんでした。');
|
||||
if (apptool.saveFile(code, apptool.lang) === false) window.alert('保存できませんでした。');
|
||||
}
|
||||
|
||||
const close_cb = () => {
|
||||
@ -437,7 +437,7 @@ const ugj_showCode = () => {
|
||||
document.removeEventListener('keyup', keyev_cb);
|
||||
}
|
||||
const export_cb = () => {
|
||||
if (elutil.lang == 'js') {
|
||||
if (apptool.lang == 'js') {
|
||||
save_to_file(ugj_formatCode(ugj_asyncIife(code)));
|
||||
} else {
|
||||
ugj_spawnPyboard(ugj_formatCode(code), 'd');
|
||||
@ -446,12 +446,12 @@ const ugj_showCode = () => {
|
||||
}
|
||||
const keyev_cb = ev => {
|
||||
if (ev.key == 's' && ev.ctrlKey) {
|
||||
if (elutil.lang == 'js') {
|
||||
if (apptool.lang == 'js') {
|
||||
// JS-CLI モード
|
||||
// blackboardWrite()とwindow.alert()、fukidashi()をconsole.log()に書き換え、
|
||||
// document... と ugj_... と elutil... をコメントアウト(ブラウザ関連部分の追放という意味では不完全なので注意)
|
||||
// document... と ugj_... と apptool... をコメントアウト(ブラウザ関連部分の追放という意味では不完全なので注意)
|
||||
// あと正規表現もいい加減
|
||||
code = code.replace(/const appendDiv[^#]*\/\/#/gm, 'const blackboardWrite = text => console.log(text);').replace('window.alert', 'console.log').replace(/_fukidashi(.*), \d+(\);)/gm, 'console.log$1$2').replace(/(^(?=.*document.)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*ugj_)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*elutil.)[^;]*;)/gm, '/* $1 */');
|
||||
code = code.replace(/const appendDiv[^#]*\/\/#/gm, 'const blackboardWrite = text => console.log(text);').replace('window.alert', 'console.log').replace(/_fukidashi(.*), \d+(\);)/gm, 'console.log$1$2').replace(/(^(?=.*document.)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*ugj_)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*apptool.)[^;]*;)/gm, '/* $1 */');
|
||||
}
|
||||
save_to_file(ugj_formatCode(ugj_asyncIife(code)));
|
||||
close_cb();
|
||||
@ -623,7 +623,7 @@ Blockly.svgResize(workspace);
|
||||
// ワークスペースの未保存の変更のフラグ
|
||||
const ugj_wsUpdateCB = event => {
|
||||
if (event.type != Blockly.Events.UI) {
|
||||
elutil.setWsChanged(true);
|
||||
apptool.setWsChanged(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -648,17 +648,17 @@ window.onload = () => {
|
||||
|
||||
// ワークスペースといくつかの環境のオートリストア
|
||||
ugj_loadWorkspace();
|
||||
elutil.loadPrefsFromLS();
|
||||
apptool.loadPrefsFromLS();
|
||||
setTimeout(() => { // 環境設定のロードが終わってからイベントリスナを作成
|
||||
workspace.addChangeListener(ugj_wsUpdateCB);
|
||||
}, 100);
|
||||
// 背景canvas
|
||||
ugj_canvasBgImg(elutil.getMascotFilePath(), -1, -1);
|
||||
ugj_canvasBgImg(apptool.getMascotFilePath(), -1, -1);
|
||||
}
|
||||
window.addEventListener('beforeunload', () => {
|
||||
// window.onbeforeunload = () => {
|
||||
ugj_saveWorkspace();
|
||||
elutil.savePrefsToLS();
|
||||
elutil.cleanupGPIO();
|
||||
apptool.savePrefsToLS();
|
||||
apptool.cleanupGPIO();
|
||||
// }
|
||||
});
|
||||
|
10
main.js
10
main.js
@ -166,7 +166,7 @@ let template = [
|
||||
click: (item, focusedWindow) => {
|
||||
if (focusedWindow) {
|
||||
toggleCheck_i2c("i2c-1");
|
||||
focusedWindow.webContents.executeJavaScript('elutil.setI2cbusNo("1")');
|
||||
focusedWindow.webContents.executeJavaScript('apptool.setI2cbusNo("1")');
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -177,7 +177,7 @@ let template = [
|
||||
click: (item, focusedWindow) => {
|
||||
if (focusedWindow) {
|
||||
toggleCheck_i2c("i2c-6");
|
||||
focusedWindow.webContents.executeJavaScript('elutil.setI2cbusNo("6")');
|
||||
focusedWindow.webContents.executeJavaScript('apptool.setI2cbusNo("6")');
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -196,7 +196,7 @@ let template = [
|
||||
if (focusedWindow) {
|
||||
// menu.getMenuItemById('py').checked = false;
|
||||
toggleCheck_lang("js");
|
||||
focusedWindow.webContents.executeJavaScript('elutil.setLang("js")');
|
||||
focusedWindow.webContents.executeJavaScript('apptool.setLang("js")');
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -208,7 +208,7 @@ let template = [
|
||||
if (focusedWindow) {
|
||||
// menu.getMenuItemById('js').checked = false;
|
||||
toggleCheck_lang("py");
|
||||
focusedWindow.webContents.executeJavaScript('elutil.setLang("py")');
|
||||
focusedWindow.webContents.executeJavaScript('apptool.setLang("py")');
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -224,7 +224,7 @@ let template = [
|
||||
{
|
||||
label: "Launch PyBfm",
|
||||
click: (item, focusedWindow) => {
|
||||
focusedWindow.webContents.executeJavaScript('elutil.launchPyBfm()');
|
||||
focusedWindow.webContents.executeJavaScript('apptool.launchPyBfm()');
|
||||
},
|
||||
},
|
||||
]
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ocoge",
|
||||
"version": "0.1.9",
|
||||
"version": "0.1.10",
|
||||
"description": "ブロックベースビジュアルプログラム開発・実行環境",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
@ -62,4 +62,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user