Skip to main content

A micropython Menu for LCD Displays

Project description

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

upymenu-0.0.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

upymenu-0.0.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file upymenu-0.0.1.tar.gz.

File metadata

  • Download URL: upymenu-0.0.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2

File hashes

Hashes for upymenu-0.0.1.tar.gz
Algorithm Hash digest
SHA256 05c86d8690d8fd8f331ddca03544608a1e7993226d5d14ce5a7bbb96d215cc18
MD5 dc87480218b64094e9b8a4191bd6d9ef
BLAKE2b-256 8610c9555ec63106153aaaad753a281ff47f4ac79e980ff7f5d740d6649cd56a

See more details on using hashes here.

File details

Details for the file upymenu-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: upymenu-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2

File hashes

Hashes for upymenu-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 45159f7c599400fdb8ba69e898472481b2f4e72eb417c90bf425b1cea7bd0442
MD5 9a71147f342cf1a2f224bc39bab467de
BLAKE2b-256 2a1a3dd2d22a22150a74c2d664163cd3739c91612838377128cc2d3da43285f7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page