From 974229f4b21d07c5839bfdc7b5852ad7e0155689 Mon Sep 17 00:00:00 2001 From: BlueFox Date: Tue, 12 Nov 2024 21:52:05 +0100 Subject: [PATCH] Added a small check for empty menu item lists (which make no sense) --- __init__.py | 8 ++++++-- example_simple.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index 57c11cd..0ab760e 100644 --- a/__init__.py +++ b/__init__.py @@ -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] diff --git a/example_simple.py b/example_simple.py index b182061..d1b2e32 100644 --- a/example_simple.py +++ b/example_simple.py @@ -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() \ No newline at end of file +menu.run()