uPyMenu
uPyMenu is a micropython menu implementation for LCD displays. Coming from an Arduino experience, I was used with LiquidCrystal and LiquidMenu, but they don't offer a python implementation. So I figured I could create one myself.
Development
Current development is done based on when I have to to work on it when I want to. But feel free to fork it and add your functionality. If you find any bugs or have suggestions for features, please open up a issue (or pull-request if you create the feature yourself!).
TODO
- Add arguments to callback actions in the menu
Usage
The example below renders a menu with a submenu and actions that have callbacks attached which you can use to run your own function. It requires one dependency, and that's python_lcd for interacting with the LCD itself.
from machine import Pin, I2C # Basics for creating an LCD interface
from esp8266_i2c_lcd import I2cLcd # Example LCD interface used
from upymenu import Menu, MenuAction, MenuNoop
def action_callback():
print("callback action chosen")
submenu = Menu("Submenu")
submenu_action_1 = MenuAction("Submenu Action", callback=action_callback)
submenu_action_2 = MenuAction("Submenu Action 1", callback=action_callback)
submenu.add_option(submenu_action_1)
submenu.add_option(submenu_action_2)
menu_action = MenuAction("Action", callback=action_callback)
menu = Menu("Main Menu")
menu.add_option(submenu)
menu.add_option(menu_action)
menu.add_option(MenuNoop("Nothing here"))
# Example config for LCD via i2c, you will need this
# for the menu to function, the screen size is required
# to render the menu correctly on the screen.
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
lcd = I2cLcd(i2c, 0x3F, 4, 20)
current_menu = menu.start(lcd) # Starts the menu on the LCD
menu.focus_next() # Focus on the next item in the menu
menu.focus_prev() # Focus on the previous item in the menu
# Choose the focused item, if it's and action execute
# the callback, or if it is a menu, render that menu.
menu = menu.choose()
# If it's a submenu, you can use the parent() function
# to navigate back up to the tree.
menu = menu.parent()
Testing
If you have a micropython port running locally, you can run the test suite with it, ie: micropython tests.py. This is as close I can get with my current knowledge about micropython. Any pointers and suggestions towards improvement here would be appreciated!
Metadata
Release files for upymenu 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| upymenu-0.0.1.tar.gz | 2.8 kB | Without provenance | Details for upymenu-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| upymenu-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for upymenu-0.0.1-py3-none-any.whl |
Total release size: 7.4 kB
Security for upymenu 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.