From ecd72182301e8ceb100188b25448b6ec616ea5df Mon Sep 17 00:00:00 2001 From: BlueFox Date: Thu, 31 Oct 2024 20:11:12 +0000 Subject: [PATCH] Added the methods and raw structure of the class to __init__.py --- __init__.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 014da47..078fe96 100644 --- a/__init__.py +++ b/__init__.py @@ -10,5 +10,49 @@ You should have received a copy of the GNU General Public License along with thi """ class lcdMenu: - def __init__(): - pass \ No newline at end of file + # lcd: I2C_LCD - an object of the I2C_LCD class (https://git.privacynerd.de/BlueFox/micropython-libraries/src/branch/main/PCF8574T) + # buttons: dict - a dictionary with machine.Pin objects as items with following keys + # - "prev_btn" - OPTIONAL - when pressed, select the previous menu item + # - "next_btn" - REQUIRED - when pressed, select the next menu item + # - "ok_btn" - REQUIRED - when pressed, call the callback function of the menu item + # menu_items: list - a list (-> maintains order!) containing tuples with the following format: (,) + # scroll_direction: bool - if true, the scrolling direction is horizontal, if false, vertical + # cycle: bool - if true, start again with the first menu entry after the last one (and show the last before the first) + # hide_menu_name: bool - OPTIONAL - if true, hide the menu's name (won't work in combination with a vertical scrolling direction) + # name: str - OPTIONAL - a string with the name of the menu (can be hidden under certain circumstances) + # default_selection: int - OPTIONAL - the index of the item selected by default (starting with 0) - DON'T USE NEGATIVE INDEXES + def __init__(self, lcd, buttons: dict, menu_items: list, scroll_direction: bool, cycle: bool, hide_menu_name: bool = False, name: str = "CHOOSE", default_selection: int = 0): + self.lcd = lcd + if "prev_btn" in buttons.keys(): + self.prev_btn = buttons["prev_btn"] + else: + self.prev_btn = None + self.next_btn = buttons["next_btn"] + self.ok_btn = buttons["ok_btn"] + self.menu_items = menu_items + self.scroll_direction = scroll_direction + self.cycle = cycle + self.hide_menu_name = hide_menu_name + self.name = name + self.current_selection = default_selection + + + def show_selection(self): + # if you scrolling vertically, I found no elegant way to hide the name (there just need's to be something up there!) + if self.scroll_direction and self.hide_menu_name: + raise TypeError("Hiding the menu name whilst having the scroll direction set to horizontal!") + + # TODO: the real process + if self.scroll_direction: # if horizontal scrolling is activated + pass + else: # if vertical scrolling is activated + pass + + + def execute_selection(self): + self.menu_items[self.current_selection][1]() + + + def run(self): + # TODO: add btn handlers and the actual process +