1from imagetools import get_png_info, open_png
2
3# Register PNG image decoder
4decoder = lv.img.decoder_create()
5decoder.info_cb = get_png_info
6decoder.open_cb = open_png
7
8# Create an image from the png file
9try:
10    with open('../../assets/img_caret_down.png','rb') as f:
11        png_data = f.read()
12except:
13    print("Could not find img_caret_down.png")
14    sys.exit()
15
16img_caret_down_argb = lv.img_dsc_t({
17  'data_size': len(png_data),
18  'data': png_data
19})
20
21def event_cb(e):
22    dropdown = e.get_target()
23    option = " "*64 # should be large enough to store the option
24    dropdown.get_selected_str(option, len(option))
25    print(option.strip() +" is selected")
26#
27# Create a menu from a drop-down list and show some drop-down list features and styling
28#
29
30# Create a drop down list
31dropdown = lv.dropdown(lv.scr_act())
32dropdown.align(lv.ALIGN.TOP_LEFT, 10, 10)
33dropdown.set_options("\n".join([
34    "New project",
35    "New file",
36    "Open project",
37    "Recent projects",
38    "Preferences",
39    "Exit"]))
40
41# Set a fixed text to display on the button of the drop-down list
42dropdown.set_text("Menu")
43
44# Use a custom image as down icon and flip it when the list is opened
45# LV_IMG_DECLARE(img_caret_down)
46dropdown.set_symbol(img_caret_down_argb)
47dropdown.set_style_transform_angle(1800, lv.PART.INDICATOR | lv.STATE.CHECKED)
48
49# In a menu we don't need to show the last clicked item
50dropdown.set_selected_highlight(False)
51
52dropdown.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None)
53
54