simple_menu
- Draw a Menu¶
New in version 1.4.
To allow quickly hacking some scripts, Pycardium has a small library for displaying menus. You can use it like this:
import color
import simple_menu
class MyMenu(simple_menu.Menu):
color_1 = color.CAMPGREEN
color_2 = color.CAMPGREEN_DARK
def on_select(self, name, index):
print("{!r} was selected!".format(name))
if __name__ == "__main__":
MyMenu(["foo", "bar", "baz"]).run()
-
class
simple_menu.
Menu
(entries)[source]¶ A simple menu for card10.
This menu class is supposed to be inherited from to create a menu as shown in the example above.
To instanciate the menu, pass a list of entries to the constructor:
m = Menu(os.listdir(".")) m.run()
Then, call
run()
to start the event loop.New in version 1.4.
-
color_1
¶ Background color A.
-
color_2
¶ Background color B.
-
color_text
¶ Text color.
-
color_sel
¶ Color of the selector.
-
on_scroll
(item, index)[source]¶ Hook when the selector scrolls to a new item.
This hook is run everytime a scroll-up or scroll-down is performed. Overwrite this function in your own menus if you want to do some action every time a new item is scrolled onto.
- Parameters
item – The item which the selector now points to.
index (int) – Index into the
entries
list of theitem
.
-
on_select
(item, index)[source]¶ Hook when an item as selected.
The given
index
was selected with a SELECT button press. Overwrite this function in your menu to perform an action on select.- Parameters
item – The item which was selected.
index (int) – Index into the
entries
list of theitem
.
-
entry2name
(value)[source]¶ Convert an entry object to a string representation.
Overwrite this functio if your menu items are not plain strings.
Example:
class MyMenu(simple_menu.Menu): def entry2name(self, value): return value[0] MyMenu( [("a", 123), ("b", 321)] ).run()
-
draw_entry
(value, index, offset)[source]¶ Draw a single entry.
This is an internal function; you can override it for customized behavior.
- Parameters
value – The value for this entry. Use this to identify different entries.
index (int) – A unique index per entry. Stable for a certain entry, but not an index into
entries
.offset (int) – Y-offset for this entry.
-
-
simple_menu.
button_events
()[source]¶ Iterate over button presses (event-loop).
This is just a helper function used internally by the menu. But you can of course use it for your own scripts as well. It works like this:
import simple_menu, buttons for ev in simple_menu.button_events(): if ev == buttons.BOTTOM_LEFT: # Left pass elif ev == buttons.BOTTOM_RIGHT: # Right pass elif ev == buttons.TOP_RIGHT: # Select pass
New in version 1.4.