Added a small check for empty menu item lists (which make no sense)

This commit is contained in:
BlueFox 2024-11-12 21:52:05 +01:00
parent 10562d6410
commit 974229f4b2
Signed by: BlueFox
GPG Key ID: 327233DA85435270
2 changed files with 7 additions and 3 deletions

View File

@ -51,10 +51,14 @@ class lcdMenu:
def show_selection(self):
# a check:
# if you scrolling vertically, I found no elegant way to hide the name (there just need's to be something up there!)
# some checks:
# 1. 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!")
# 2. if there are no menu items to display...
if len(self.menu_items) == 0:
raise TypeError("Can't show empty menus! Maybe you forgot calling self.setup() after initializing me?")
# get some often used values into local variables
selection_name = self.menu_items[self.current_selection][0]

View File

@ -22,4 +22,4 @@ menuItems = [("first item", first_callback),
("third item", third_cb)]
menu = lcdMenu(LCD, {"prev_btn":prev_btn, "next_btn": next_btn, "ok_btn": ok_btn}, menuItems, scroll_direction=False, cycle=False, hide_menu_name=True, name="Fullscreen!")
menu.run()
menu.run()