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_1.py (1096B)

      1 def textarea_event_handler(e, ta):
      2     print("Enter was pressed. The current text is: " + ta.get_text())
      3 
      4 
      5 def btnm_event_handler(e, ta):
      6     obj = e.get_target()
      7     txt = obj.get_btn_text(obj.get_selected_btn())
      8     if txt == lv.SYMBOL.BACKSPACE:
      9         ta.del_char()
     10     elif txt == lv.SYMBOL.NEW_LINE:
     11         lv.event_send(ta, lv.EVENT.READY, None)
     12     elif txt:
     13         ta.add_text(txt)
     14 
     15 
     16 ta = lv.textarea(lv.scr_act())
     17 ta.set_one_line(True)
     18 ta.align(lv.ALIGN.TOP_MID, 0, 10)
     19 ta.add_event_cb(lambda e: textarea_event_handler(e, ta), lv.EVENT.READY, None)
     20 ta.add_state(lv.STATE.FOCUSED)   # To be sure the cursor is visible
     21 
     22 btnm_map = ["1", "2", "3", "\n",
     23             "4", "5", "6", "\n",
     24             "7", "8", "9", "\n",
     25             lv.SYMBOL.BACKSPACE, "0", lv.SYMBOL.NEW_LINE, ""]
     26 
     27 btnm = lv.btnmatrix(lv.scr_act())
     28 btnm.set_size(200, 150)
     29 btnm.align(lv.ALIGN.BOTTOM_MID, 0, -10)
     30 btnm.add_event_cb(lambda e: btnm_event_handler(e, ta), lv.EVENT.VALUE_CHANGED, None)
     31 btnm.clear_flag(lv.obj.FLAG.CLICK_FOCUSABLE)    # To keep the text area focused on button clicks
     32 btnm.set_map(btnm_map)