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_imgbtn_1.py (1950B)
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/imgbtn_left.png','rb') as f: 11 imgbtn_left_data = f.read() 12 except: 13 print("Could not find imgbtn_left.png") 14 sys.exit() 15 16 imgbtn_left_dsc = lv.img_dsc_t({ 17 'data_size': len(imgbtn_left_data), 18 'data': imgbtn_left_data 19 }) 20 21 try: 22 with open('../../assets/imgbtn_mid.png','rb') as f: 23 imgbtn_mid_data = f.read() 24 except: 25 print("Could not find imgbtn_mid.png") 26 sys.exit() 27 28 imgbtn_mid_dsc = lv.img_dsc_t({ 29 'data_size': len(imgbtn_mid_data), 30 'data': imgbtn_mid_data 31 }) 32 33 try: 34 with open('../../assets/imgbtn_right.png','rb') as f: 35 imgbtn_right_data = f.read() 36 except: 37 print("Could not find imgbtn_right.png") 38 sys.exit() 39 40 imgbtn_right_dsc = lv.img_dsc_t({ 41 'data_size': len(imgbtn_right_data), 42 'data': imgbtn_right_data 43 }) 44 45 # Create a transition animation on width transformation and recolor. 46 tr_prop = [lv.STYLE.TRANSFORM_WIDTH, lv.STYLE.IMG_RECOLOR_OPA, 0] 47 tr = lv.style_transition_dsc_t() 48 tr.init(tr_prop, lv.anim_t.path_linear, 200, 0, None) 49 50 style_def = lv.style_t() 51 style_def.init() 52 style_def.set_text_color(lv.color_white()) 53 style_def.set_transition(tr) 54 55 # Darken the button when pressed and make it wider 56 style_pr = lv.style_t() 57 style_pr.init() 58 style_pr.set_img_recolor_opa(lv.OPA._30) 59 style_pr.set_img_recolor(lv.color_black()) 60 style_pr.set_transform_width(20) 61 62 # Create an image button 63 imgbtn1 = lv.imgbtn(lv.scr_act()) 64 imgbtn1.set_src(lv.imgbtn.STATE.RELEASED, imgbtn_left_dsc, imgbtn_mid_dsc, imgbtn_right_dsc) 65 imgbtn1.add_style(style_def, 0) 66 imgbtn1.add_style(style_pr, lv.STATE.PRESSED) 67 68 imgbtn1.align(lv.ALIGN.CENTER, 0, 0) 69 70 # Create a label on the image button 71 label = lv.label(imgbtn1) 72 label.set_text("Button") 73 label.align(lv.ALIGN.CENTER, 0, -4) 74