Skip to main content

日本語版

Generating a custom block file for UiFlow

This script generates a custom block file(the M5B file) from a JSON file for setting custom blocks, and MicroPython files defined codes for custom blocks.

You can also generate the JSON and MicroPython files from an existing M5B file.

Installation

I 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:

pip install git+https://github.com/3110/uiflow-custom-block-generator

Setting Custom Blocks

The 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 the UiFlow 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 in blocks:

  • name: Filename of MicroPython codes for the custom block. The setting "name": "rgb" means rgb.py is 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) and execute(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 in params.

  • name: The name of the argument. If type is label, 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 to examples/atom_babies for the sample.

Execution

Generating the M5B file from the JSON file and MicroPython files

To generate atom_babies.m5b on the same directory as the JSON file, execute the following:

python -m uiflow_custom_block_generator examples/atom_babies/atom_babies.json

You can specify --target_dir(-t) option to change the output directory of the M5B file.

For example, atom_babies.m5b is generated on the current directory if you execute the following:

python -m uiflow_custom_block_generator examples/atom_babies/atom_babies.json -t .

Caution: UiFlow Block Maker cannot read the M5B file generated from this script.

Generating the JSON file and MicroPython files from the M5B file

The following command creates the atom_babies directory in the same directory as the M5B file and generates atom_babies.json and the MicroPython files in the atom_babies directory.

python -m uiflow_custom_block_generator example/atom_babies/atom_babies.m5b

You can specify --target_dir(-t) option to change the output directory of the JSON file and MicroPython files. The following command creates atom_babies directory in the current directory.

python -m uiflow_custom_block_generator examples/atom_babies/atom_babies.m5b -t .

Notes on VS Code

  • Because Flake8 detects Invalid Syntax(E999) for ${}(the reference to the argument of the custom block), the setting in .vscode/settings.json suppresses E999.
  • If you use rgb modules in the custom block codes, you have to specify # type: ignore # noqa: F821 to ignore undefined name errors.

Release files for uiflow-custom-block-generator 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uiflow-custom-block-generator 0.0.5
File Size Uploaded
uiflow_custom_block_generator-0.0.5.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for uiflow-custom-block-generator 0.0.5
File Interpreter ABI Platform
uiflow_custom_block_generator-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / uiflow_custom_block_generator-0.0.5.tar.gz

Download URL uiflow_custom_block_generator-0.0.5.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2f755e51343ad537c71252dc655859d563a98df16ba4fbe100d9c5a9474d5500
BLAKE2b-256 checksum
How to use checksums
8cc0d7fe791914468a9fb1ca681830073836bcd70d26b79cc30c470c33683365
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release files / uiflow_custom_block_generator-0.0.5-py3-none-any.whl

Download URL uiflow_custom_block_generator-0.0.5-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d9e88787b6feaf7cf9482ab6d736f3e8d9d7ed0cdf1e0b63194fd36d5fb6ec6
BLAKE2b-256 checksum
How to use checksums
0c04de247da1a34763fb8e35152a3f5bdb902c2c5e1a76af80d7c9f7448a9a2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page