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_textarea_3.py (1385B)
1 def ta_event_cb(e): 2 ta = e.get_target() 3 txt = ta.get_text() 4 # print(txt) 5 pos = ta.get_cursor_pos() 6 # print("cursor pos: ",pos) 7 # find position of ":" in text 8 colon_pos= txt.find(":") 9 # if there are more than 2 digits before the colon, remove the last one entered 10 if colon_pos == 3: 11 ta.del_char() 12 if colon_pos != -1: 13 # if there are more than 3 digits after the ":" remove the last one entered 14 rest = txt[colon_pos:] 15 if len(rest) > 3: 16 ta.del_char() 17 18 if len(txt) < 2: 19 return 20 if ":" in txt: 21 return 22 if txt[0] >= '0' and txt[0] <= '9' and \ 23 txt[1] >= '0' and txt[1] <= '9': 24 if len(txt) == 2 or txt[2] != ':' : 25 ta.set_cursor_pos(2) 26 ta.add_char(ord(':')) 27 # 28 # Automatically format text like a clock. E.g. "12:34" 29 # Add the ':' automatically 30 # 31 # Create the text area 32 33 LV_HOR_RES = lv.scr_act().get_disp().driver.hor_res 34 LV_VER_RES = lv.scr_act().get_disp().driver.ver_res 35 36 ta = lv.textarea(lv.scr_act()) 37 ta.add_event_cb(ta_event_cb, lv.EVENT.VALUE_CHANGED, None) 38 ta.set_accepted_chars("0123456789:") 39 ta.set_max_length(5) 40 ta.set_one_line(True) 41 ta.set_text("") 42 ta.add_state(lv.STATE.FOCUSED) 43 44 # Create a keyboard 45 kb = lv.keyboard(lv.scr_act()) 46 kb.set_size(LV_HOR_RES, LV_VER_RES // 2) 47 kb.set_mode(lv.keyboard.MODE.NUMBER) 48 kb.set_textarea(ta) 49 50