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_snapshot_1.py (2170B)
1 import gc 2 import lvgl as lv 3 from imagetools import get_png_info, open_png 4 5 # Register PNG image decoder 6 decoder = lv.img.decoder_create() 7 decoder.info_cb = get_png_info 8 decoder.open_cb = open_png 9 10 # Measure memory usage 11 gc.enable() 12 gc.collect() 13 mem_free = gc.mem_free() 14 15 label = lv.label(lv.scr_act()) 16 label.align(lv.ALIGN.BOTTOM_MID, 0, -10) 17 label.set_text(" memory free:" + str(mem_free/1024) + " kB") 18 19 # Create an image from the png file 20 try: 21 with open('../../assets/img_star.png','rb') as f: 22 png_data = f.read() 23 except: 24 print("Could not find star.png") 25 sys.exit() 26 27 img_star = lv.img_dsc_t({ 28 'data_size': len(png_data), 29 'data': png_data 30 }) 31 32 def event_cb(e, snapshot_obj): 33 img = e.get_target() 34 35 if snapshot_obj: 36 # no need to free the old source for snapshot_obj, gc will free it for us. 37 38 # take a new snapshot, overwrite the old one 39 dsc = lv.snapshot_take(img.get_parent(), lv.img.CF.TRUE_COLOR_ALPHA) 40 snapshot_obj.set_src(dsc) 41 42 gc.collect() 43 mem_used = mem_free - gc.mem_free() 44 label.set_text("memory used:" + str(mem_used/1024) + " kB") 45 46 root = lv.scr_act() 47 root.set_style_bg_color(lv.palette_main(lv.PALETTE.LIGHT_BLUE), 0) 48 49 # Create an image object to show snapshot 50 snapshot_obj = lv.img(root) 51 snapshot_obj.set_style_bg_color(lv.palette_main(lv.PALETTE.PURPLE), 0) 52 snapshot_obj.set_style_bg_opa(lv.OPA.COVER, 0) 53 snapshot_obj.set_zoom(128) 54 55 # Create the container and its children 56 container = lv.obj(root) 57 container.align(lv.ALIGN.CENTER, 0, 0) 58 container.set_size(180, 180) 59 container.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP) 60 container.set_flex_align(lv.FLEX_ALIGN.SPACE_EVENLY, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER) 61 container.set_style_radius(50, 0) 62 63 for i in range(4): 64 img = lv.img(container) 65 img.set_src(img_star) 66 img.set_style_bg_color(lv.palette_main(lv.PALETTE.GREY), 0) 67 img.set_style_bg_opa(lv.OPA.COVER, 0) 68 img.set_style_transform_zoom(400, lv.STATE.PRESSED) 69 img.add_flag(img.FLAG.CLICKABLE) 70 img.add_event_cb(lambda e: event_cb(e, snapshot_obj), lv.EVENT.PRESSED, None) 71 img.add_event_cb(lambda e: event_cb(e, snapshot_obj), lv.EVENT.RELEASED, None)