acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_dropdown_3.py (1483B)

      1 from imagetools import get_png_info, open_png
      2 
      3 # Register PNG image decoder
      4 decoder = lv.img.decoder_create()
      5 decoder.info_cb = get_png_info
      6 decoder.open_cb = open_png
      7 
      8 # Create an image from the png file
      9 try:
     10     with open('../../assets/img_caret_down.png','rb') as f:
     11         png_data = f.read()
     12 except:
     13     print("Could not find img_caret_down.png")
     14     sys.exit()
     15 
     16 img_caret_down_argb = lv.img_dsc_t({
     17   'data_size': len(png_data),
     18   'data': png_data
     19 })
     20 
     21 def 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
     31 dropdown = lv.dropdown(lv.scr_act())
     32 dropdown.align(lv.ALIGN.TOP_LEFT, 10, 10)
     33 dropdown.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
     42 dropdown.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)
     46 dropdown.set_symbol(img_caret_down_argb)
     47 dropdown.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
     50 dropdown.set_selected_highlight(False)
     51 
     52 dropdown.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None)
     53