Skip to content

Improvement discussions #1

@juergenpabel

Description

@juergenpabel

I came across your library for a small project of mine that's build around circuitpython on an M5stack DinMeter. Your library allows me to implement the entire application UI as a menu, which is about as much as one can do with such a small display.

I stumbled upon a few things that I will add/change in my fork - but would like to discuss these beforehand in order to adapt so that you'll accept future pull requests:

  1. library file structure
  • create a menu subdir, move *.py into menu/ and add an __init__.py
  • file reorganisation: split menu.py into menu.py, menuitem.py and action.py
  1. CircuitPython API changes
  • displayio: use a displayio.Group instance as the rendering "target" instead of displayio.Display (which doesn't exist anymore); app is responsible for activating the group onto the active display
  1. Menu
  • add (keyword-based) configuration parameters to Menu constructor
    • font: pass in a font (default=terminalio.FONT)
    • header: a header to (always) render in the first line when this menu instance is shown (default=None)
  • Menu.run()
    • add a callable parameter (keyword=display_handler) that takes a displayio.Group argument (which is the generated group of the menu)...maybe DisplayHandler should also be a new abstract class for (mostly) typing purposes (seems like a reasonable approach)
    • add a callable parameter (keyword=exit_condition) for application controlled exit conditioning (default=None, which would than effectively result in while True again)
  • Menu.debounce()
    • remove and adapt loop in Menu.run() to check for timestamp if debouncing complete (instead of busy waiting)...also important for #5 on this list
  1. Menu items
  • rename FinalMenuItem to ExitMenuItem (as it merely emits a sub-menu exit, but it doesn't need to be the final/last item in a list)
  • rename TitleMenuItem to NonselectableMenuItem
  1. async compatibility
  • I don't want to add specific async features, but want async applications to be able to use this library in an async runtime context
  • removing any locking / waiting code like time.sleep() is essential (see debouncing point, above)
  • async compatibility could be implemented by the application by providing an exit_condition callable that also does async event loop switching - but I am open to other approaches

I am sure there is more, but that's what I could think of just now. Let me know, I would like to finish my project within the next couple of weeks (including this sub-task).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions