Package: uiflow-custom-block-generator
日本語版Generating a custom block file forUiFlowThis script generates a custom block file(the M5B file) from a JSON file for setting custom blocks, andMicroPythonfiles defined codes for custom blocks.You can also generate the JSON and MicroPython files from an existing M5B file.InstallationI have developed and tested this script using VS Code, Git Bash, and Python v3.10.4 on the Windows 11 environment.To install this script, execute the following:pipinstallgit+https://github.com/3110/uiflow-custom-block-generatorSetting Custom BlocksThe structure of the JSON file for setting custom blocks is the following:{"category":"ATOM_Babies","color":"#115f07","blocks":[{"name":"init_atom_babies","type":"execute","params":[{"name":"Initialize ATOM Babies","type":"label"},{"name":"_eye_color","type":"variable"},{"name":"_cheek_color","type":"variable"},{"name":"_background_color","type":"variable"}]},{"name":"rgb","type":"value","params":[{"name":"Specify the color","type":"label"},{"name":"_r","type":"number"},{"name":"_g","type":"number"},{"name":"_b","type":"number"}]}]}category: Same as Namespace on theUiFlow Block Maker.color: Specify the color of custom blocks with#RRGGBB.blocks: Define custom blocks. They are arranged in the order in which they appear here.To define custom blocks, specify the following items inblocks:name: Filename of MicroPython codes for the custom block. The setting"name": "rgb"meansrgb.pyis read from the same directory as the JSON file.type: Type of the custom block. You can specify the two types of blocks:value(the block returns a value) andexecute(the block does not return any value).params: Arguments for the custom block. They are arranged in the order in witch they appear here.To define arguments of the custom block, specify the following items inparams.name: The name of the argument. Iftypeislabel, this is the label shown on the block.type: The type of the argument. There are four types:label: The label displayed on the block. Multiple specifications are allowed.string: String.number: Number.variable: Variable.Please refer toexamples/atom_babiesfor the sample.ExecutionGenerating the M5B file from the JSON file and MicroPython filesTo generateatom_babies.m5bon the same directory as the JSON file, execute the following:python-muiflow_custom_block_generatorexamples/atom_babies/atom_babies.jsonYou can specify--target_dir(-t) option to change the output directory of the M5B file.For example,atom_babies.m5bis generated on the current directory if you execute the following:python-muiflow_custom_block_generatorexamples/atom_babies/atom_babies.json-t.Caution:UiFlow Block Makercannot read the M5B file generated from this script.Generating the JSON file and MicroPython files from the M5B fileThe following command creates theatom_babiesdirectory in the same directory as the M5B file and generatesatom_babies.jsonand the MicroPython files in theatom_babiesdirectory.python-muiflow_custom_block_generatorexample/atom_babies/atom_babies.m5bYou can specify--target_dir(-t) option to change the output directory of the JSON file and MicroPython files. The following command createsatom_babiesdirectory in the current directory.python-muiflow_custom_block_generatorexamples/atom_babies/atom_babies.m5b-t.Notes on VS CodeBecause Flake8 detects Invalid Syntax(E999) for${}(the reference to the argument of the custom block), the setting in.vscode/settings.jsonsuppresses E999.If you usergbmodules in the custom block codes, you have to specify# type: ignore # noqa: F821to ignore undefined name errors.