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_list_2.py (4253B)
1 import urandom 2 3 currentButton = None 4 list1 = None 5 6 def event_handler(evt): 7 global currentButton 8 code = evt.get_code() 9 obj = evt.get_target() 10 if code == lv.EVENT.CLICKED: 11 if currentButton == obj: 12 currentButton = None 13 else: 14 currentButton = obj 15 parent = obj.get_parent() 16 for i in range( parent.get_child_cnt()): 17 child = parent.get_child(i) 18 if child == currentButton: 19 child.add_state(lv.STATE.CHECKED) 20 else: 21 child.clear_state(lv.STATE.CHECKED) 22 23 def event_handler_top(evt): 24 global currentButton 25 code = evt.get_code() 26 obj = evt.get_target() 27 if code == lv.EVENT.CLICKED: 28 if currentButton == None: 29 return 30 currentButton.move_background() 31 currentButton.scroll_to_view( lv.ANIM.ON) 32 33 def event_handler_up(evt): 34 global currentButton 35 code = evt.get_code() 36 obj = evt.get_target() 37 if code == lv.EVENT.CLICKED or code == lv.EVENT.LONG_PRESSED_REPEAT: 38 if currentButton == None: 39 return 40 index = currentButton.get_index() 41 if index <= 0: 42 return 43 currentButton.move_to_index(index - 1) 44 currentButton.scroll_to_view(lv.ANIM.ON) 45 46 def event_handler_center(evt): 47 global currentButton 48 code = evt.get_code() 49 obj = evt.get_target() 50 if code == lv.EVENT.CLICKED or code == lv.EVENT.LONG_PRESSED_REPEAT: 51 if currentButton == None: 52 return 53 parent = currentButton.get_parent() 54 pos = parent.get_child_cnt() // 2 55 currentButton.move_to_index(pos) 56 currentButton.scroll_to_view(lv.ANIM.ON) 57 58 def event_handler_dn(evt): 59 global currentButton 60 code = evt.get_code() 61 obj = evt.get_target() 62 if code == lv.EVENT.CLICKED or code == lv.EVENT.LONG_PRESSED_REPEAT: 63 if currentButton == None: 64 return 65 index = currentButton.get_index() 66 currentButton.move_to_index(index + 1) 67 currentButton.scroll_to_view(lv.ANIM.ON) 68 69 def event_handler_bottom(evt): 70 global currentButton 71 code = evt.get_code() 72 obj = evt.get_target() 73 if code == lv.EVENT.CLICKED or code == lv.EVENT.LONG_PRESSED_REPEAT: 74 if currentButton == None: 75 return 76 currentButton.move_foreground() 77 currentButton.scroll_to_view(lv.ANIM.ON) 78 79 def event_handler_swap(evt): 80 global currentButton 81 global list1 82 code = evt.get_code() 83 obj = evt.get_target() 84 if code == lv.EVENT.CLICKED: 85 cnt = list1.get_child_cnt() 86 for i in range(100): 87 if cnt > 1: 88 obj = list1.get_child(urandom.getrandbits(32) % cnt ) 89 obj.move_to_index(urandom.getrandbits(32) % cnt) 90 if currentButton != None: 91 currentButton.scroll_to_view(lv.ANIM.ON) 92 93 #Create a list with buttons that can be sorted 94 list1 = lv.list(lv.scr_act()) 95 list1.set_size(lv.pct(60), lv.pct(100)) 96 list1.set_style_pad_row( 5, 0) 97 98 for i in range(15): 99 btn = lv.btn(list1) 100 btn.set_width(lv.pct(100)) 101 btn.add_event_cb( event_handler, lv.EVENT.CLICKED, None) 102 lab = lv.label(btn) 103 lab.set_text("Item " + str(i)) 104 105 #Select the first button by default 106 currentButton = list1.get_child(0) 107 currentButton.add_state(lv.STATE.CHECKED) 108 109 #Create a second list with up and down buttons 110 list2 = lv.list(lv.scr_act()) 111 list2.set_size(lv.pct(40), lv.pct(100)) 112 list2.align(lv.ALIGN.TOP_RIGHT, 0, 0) 113 list2.set_flex_flow(lv.FLEX_FLOW.COLUMN) 114 115 btn = list2.add_btn(None, "Top") 116 btn.add_event_cb(event_handler_top, lv.EVENT.ALL, None) 117 lv.group_remove_obj(btn) 118 119 btn = list2.add_btn(lv.SYMBOL.UP, "Up") 120 btn.add_event_cb(event_handler_up, lv.EVENT.ALL, None) 121 lv.group_remove_obj(btn) 122 123 btn = list2.add_btn(lv.SYMBOL.LEFT, "Center") 124 btn.add_event_cb(event_handler_center, lv.EVENT.ALL, None) 125 lv.group_remove_obj(btn) 126 127 btn = list2.add_btn(lv.SYMBOL.DOWN, "Down") 128 btn.add_event_cb(event_handler_dn, lv.EVENT.ALL, None) 129 lv.group_remove_obj(btn) 130 131 btn = list2.add_btn(None, "Bottom") 132 btn.add_event_cb(event_handler_bottom, lv.EVENT.ALL, None) 133 lv.group_remove_obj(btn) 134 135 btn = list2.add_btn(lv.SYMBOL.SHUFFLE, "Shuffle") 136 btn.add_event_cb(event_handler_swap, lv.EVENT.ALL, None) 137 lv.group_remove_obj(btn)