|
1 | 1 | ## Format of MicroHydra apps: |
2 | 2 | MicroHydra apps can be placed in the apps folder on the device's main storage, or in the apps folder on an SD Card (The launcher will create these folders automatically if they don't exist.) |
3 | 3 |
|
| 4 | +A MicroHydra app is basically just a MicroPython [module](https://docs.python.org/3/tutorial/modules.html) without an [import-guard](https://docs.python.org/3/library/__main__.html#name-main). |
| 5 | +Apps can also (*optionally*) import and use MicroHydra modules, in order to simplify app development, or to integrate with core MicroHydra features. |
| 6 | + |
4 | 7 | <br/> |
5 | 8 |
|
6 | | -All that is needed to make a valid MicroHydra app, is a .py file *(or a compiled .mpy file)* with some MicroPython code placed in the apps folder. |
7 | | -The file name becomes the app name, and it will be imported by main.py when launched using MicroHydra. |
8 | | -This is the simplest form of a MH app, and several apps in the [apps](https://github.com/echo-lalia/MicroHydra-Apps) repo are designed like this. |
| 9 | +### Basic App |
| 10 | + |
| 11 | +All that is needed to make a valid MicroHydra app, is a .py file *(or a compiled .mpy file)* with some MicroPython code, placed in the apps folder. |
| 12 | +The file name becomes the app name, and it will be imported by `main.py` when launched using MicroHydra. |
| 13 | +This is the simplest form of an MH app, and several apps in the [community apps repo](https://github.com/echo-lalia/MicroHydra-Apps) are designed like this. |
9 | 14 |
|
10 | 15 | <br/> |
11 | 16 |
|
12 | | -Apps that are more complex can be made as a folder, instead. This can allow you to bundle in dependencies, or split the code up into multiple files for better readability. A MicroHydra app as a folder works essentially the same as a normal Python module, where a file named `__init__.py` inside that folder will be imported at launch. |
| 17 | +### More Complex App |
13 | 18 |
|
14 | | -If you decide to format your app as a folder, you'll probably want to use 'relative' imports to access the other modules in the app folder. |
15 | | -However, relative imports don't work when running from the editor. My usual solution to this is to use both relative, and absolute imports, in a try/except statement. Here's what that looks like: |
| 19 | +Apps that are more complex can be made as a folder, instead of a single file. |
| 20 | +This can allow you to bundle in dependencies, or split the code up into multiple files for better organization. |
16 | 21 |
|
17 | | -``` Python |
18 | | -try: |
19 | | - # relative import for launching the app normally |
20 | | - from . import myothermodule |
21 | | -except: |
22 | | - # absolute path for launching from the editor (which causes the above to fail) |
23 | | - from apps.myappname import myothermodule |
24 | | -``` |
| 22 | +Inside your app's folder, you'll need an `__init__.py` file. |
| 23 | +When your app is imported, `__init__.py` is the specific file that MicroPython will actually be importing on launch. From there, you can import any other modules you'd like. |
| 24 | +*(This behavior is mostly identical to CPython)* |
| 25 | + |
| 26 | +> **Note on relative imports**: |
| 27 | +> *If you decide to format your app as a folder, you'll probably want to use 'relative' imports to access the other modules in the app folder. |
| 28 | +> However, relative imports don't work when running directly from the editor. My usual solution to this is to just use both relative, and absolute imports, in a `try...except` statement. Here's what that looks like:* |
| 29 | +> ``` Python |
| 30 | +> try: |
| 31 | +> # relative import for launching the app normally |
| 32 | +> from . import myothermodule |
| 33 | +> except ImportError: |
| 34 | +> # absolute path for launching from the editor (which causes the above to fail) |
| 35 | +> from apps.myappname import myothermodule |
| 36 | +> ``` |
25 | 37 |
|
26 | 38 | <br/><br/><br/> |
27 | 39 |
|
28 | 40 | ## App Icons: |
29 | | -> Quick note: |
30 | | -> *The previous version of MicroHydra used a bizzare method of packing vectorized/polygonal icon definitions into a short string, which would be unpacked and executed by the launcher. This strategy was chosen for memory efficiency, but it felt awkward and is not used anymore. The script `polygon_to_raw_bmp.py` from the `tools/icons` folder has been written to convert these old polygon defs if needed.* |
31 | | -
|
32 | | -<br/> |
33 | 41 |
|
34 | 42 | **To put it simply:** |
35 | 43 | MicroHydra app icons are 32x32, 1bit, raw bitmaps (not bmp files) named `icon.raw`. Your app icon should be placed in the main directory of your app, alongside the `__init__.py` file. |
@@ -65,3 +73,10 @@ The image can be any format supported by Pillow, and you can also specify other |
65 | 73 | python3 path/to/image_to_icon.py --output_file path/to/output_filename.raw --invert --preview path/to/your_image_file.png |
66 | 74 | ``` |
67 | 75 | *(use --help to see all options)* |
| 76 | +
|
| 77 | +<br/> |
| 78 | +
|
| 79 | +> Quick note on old MH icons: |
| 80 | +> *The previous version of MicroHydra used a bizzare method of packing vectorized/polygonal icon definitions into a short string, which would be unpacked and executed by the launcher. This strategy was chosen for memory efficiency, but it felt awkward and is not used anymore. The script `polygon_to_raw_bmp.py` from the `tools/icons` folder has been written to convert these old polygon defs if needed.* |
| 81 | +
|
| 82 | +<br/> |
0 commit comments