def setup_icon_event_cb(self, obj, evt): if evt == lv.EVENT.CLICKED: self.log.debug("setup_icon_event_cb") self.anim_out_all(lv.scr_act(), 0) self.anim_bg(0, LV_DEMO_PRINTER_RED, self.LV_DEMO_PRINTER_BG_FULL) delay = 200 img = lv.img(lv.scr_act(), None) img.set_src(self.img_printer2_dsc) img.align(None, lv.ALIGN.CENTER, -90, 0) self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY img = lv.img(lv.scr_act(), None) img.set_src(self.img_no_internet_dsc) img.align(None, lv.ALIGN.CENTER, 0, -40) self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY img = lv.img(lv.scr_act(), None) img.set_src(self.img_cloud_dsc) img.align(None, lv.ALIGN.CENTER, 80, -80) self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY self.info_bottom_create( "You have no permission to change the settings.", "BACK", self.back_to_home_event_cb, delay)
def mobile_icon_event_cb(self, obj, evt): if evt == lv.EVENT.CLICKED: self.anim_out_all(lv.scr_act(), 0) self.anim_bg(0, LV_DEMO_PRINTER_BLUE, self.LV_DEMO_PRINTER_BG_FULL) delay = 200 img = lv.img(lv.scr_act(), None) img.set_src(self.img_printer2_dsc) img.align(None, lv.ALIGN.CENTER, -90, 0) self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY img = lv.img(lv.scr_act(), None) img.set_src(self.img_wave_dsc) img.align(None, lv.ALIGN.CENTER, 0, 0) self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY img = lv.img(lv.scr_act(), None) img.set_src(self.img_phone_dsc) img.align(None, lv.ALIGN.CENTER, 80, 0) self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY self.info_bottom_create("Put you phone near to the printer", "BACK", self.back_to_print_event_cb, delay) self.icon_generic_event_cb(obj, evt)
def internet_icon_event_cb(self, obj, evt): if evt == lv.EVENT.CLICKED: self.anim_out_all(lv.scr_act(), 0) self.anim_bg(0, LV_DEMO_PRINTER_RED, self.LV_DEMO_PRINTER_BG_FULL) delay = 200 img = lv.img(lv.scr_act(), None) img.set_src(self.img_printer2_dsc) img.align(None, lv.ALIGN.CENTER, -90, 0) self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY img = lv.img(lv.scr_act(), None) img.set_src(self.img_no_internet_dsc) img.align(None, lv.ALIGN.CENTER, 0, -40) self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY img = lv.img(lv.scr_act(), None) img.set_src(self.img_cloud_dsc) img.align(None, lv.ALIGN.CENTER, 80, -80) self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY self.info_bottom_create("No internet connection", "BACK", self.back_to_print_event_cb, delay) self.icon_generic_event_cb(obj, evt)
def __init__(self, scr, x=300, y=50): # the pipe self.pipe_bottom = lv.img(scr) self.pipe_bottom.align(scr, lv.ALIGN.IN_LEFT_MID, x, y) self.pipe_bottom.set_src(pipe_img_bottom) self.pipe_bottom.set_drag(True) self.pipe_top = lv.img(scr) self.pipe_top.align(scr, lv.ALIGN.IN_LEFT_MID, x, y - 400) self.pipe_top.set_src(pipe_img_top) self.pipe_top.set_drag(True)
def __init__(self, parent, manifest: DandelionAppManifest): super().__init__(parent) self.set_size(80, 80) self.set_style_local_bg_opa(self.PART.MAIN, lv.STATE.DEFAULT, lv.OPA._0) self.icon = lv.img(self) with open(manifest.appPath + manifest.iconPath, 'rb') as f: icn_data = f.read() img_dsc = lv.img_dsc_t({ "header": { "always_zero": 0, "w": 64, "h": 64, "cf": lv.img.CF.INDEXED_4BIT, }, "data_size": len(icn_data), "data": icn_data, }) self.icon.set_size(64, 64) self.icon.align(self, lv.ALIGN.IN_TOP_MID, 0, 0) self.icon.set_src(img_dsc) self.icon.set_offset_x(-8) self.label = lv.label(self) self.label.set_text(manifest.name) self.label.align(self, lv.ALIGN.IN_BOTTOM_MID, 0, 0)
def m1(): scr = lv.obj() lv.scr_load(scr) scr.set_style_local_bg_color(lv.obj.PART.MAIN, lv.STATE.DEFAULT, lv.color_hex(0xffffff)) decoder = lv.img.decoder_create() decoder.info_cb = get_png_info decoder.open_cb = open_png with open('bonsai-logo.png', 'rb') as f: png_data = f.read() global png_img_dsc png_img_dsc = lv.img_dsc_t({ 'data_size':len(png_data), 'data':png_data }) img1 = lv.img(scr) img1.set_src(png_img_dsc) img1.align(scr, lv.ALIGN.CENTER,0,0) img1.fade_in(2000,0) img1.set_drag(True) time.sleep(2) img1.fade_out(2000,0) time.sleep(2) m2()
def __init__(self, scr): super().__init__(scr) try: with open('splash.png', 'rb') as f: decoder = lv.img.decoder_create() decoder.info_cb = get_png_info decoder.open_cb = open_png png_data = f.read() png_img_dsc = lv.img_dsc_t({ 'data_size': len(png_data), 'data': png_data }) img = lv.img(self) img.align(scr, lv.ALIGN.IN_TOP_LEFT, 0, 0) img.set_src(png_img_dsc) except: img = lv.obj(self) self._lbl = lv.label(img) self._lbl.set_style_local_text_color(self.PART.MAIN, lv.STATE.DEFAULT, lv.color_hex3(0xFF8)) self.label = 'Loading bios ...'
def drawImage(filename): img_height = 240 img_width = 320 # print("filename: ",filename) if '320x240' in filename: # print('320x240 image') offset = 0 else: offset = (img_width - img_height) // 2 img_width = 240 sdl_filename = '../assets/' + filename + '_argb8888.bin' ili3941_filename = 'images/' + filename + '_rgb565.bin' # print("filenames: " + sdl_filename + ", " + ili3941_filename) try: with open(sdl_filename, 'rb') as f: img_data = f.read() # print(sdl_filename + " successfully read") driver = SDL except: try: with open(ili3941_filename, 'rb') as f: img_data = f.read() # print(ili3941_filename + " successfully read") driver = ILI9341 except: print("Could not open image file") sys.exit() image = lv.img(lv.scr_act(), None) image.set_x(offset) if driver == SDL: img_dsc = lv.img_dsc_t({ "header": { "always_zero": 0, "w": img_width, "h": img_height, "cf": lv.img.CF.TRUE_COLOR_ALPHA }, "data_size": len(img_data), "data": img_data, }) else: img_dsc = lv.img_dsc_t({ "header": { "always_zero": 0, "w": img_width, "h": img_height, "cf": lv.img.CF.TRUE_COLOR }, "data_size": len(img_data), "data": img_data, }) image.set_src(img_dsc) time.sleep(5) image.delete()
def add_icon(self, parent, src_bg_dsc, src_icon_dsc, txt): bg = lv.img(parent, None) bg.set_click(True) bg.set_src(src_bg_dsc) self.theme.apply(bg, LV_DEMO_PRINTER_THEME_ICON) bg.set_antialias(False) icon = lv.img(bg, None) icon.set_src(src_icon_dsc) icon.set_style_local_image_recolor_opa(lv.img.PART.MAIN, lv.STATE.DEFAULT, lv.OPA.TRANSP) icon.align(None, lv.ALIGN.IN_TOP_RIGHT, -30, 30) label = lv.label(bg, None) label.set_text(txt) label.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 30, -30) self.theme.apply(label, lv.THEME.LABEL) return bg
def __init__(self, index, w=24, h=8): """Initialize life. Args: index (int): Life number (1-based). width (Optional int): Life width (default 24). height (Optional int): Life height (default 8). """ margin = 5 # self.display = display self.x = SCREEN_WIDTH - (index * (w + margin)) self.y = 7 self.width = w self.height = h try: with open('arkanoid_images/Paddle24x8_argb8888.bin', 'rb') as f: life_data = f.read() print('arkanoid_images/Paddle24x8_argb8888.bin successfully read') driver = SDL except: try: with open('images/Paddle24x8_rgb565.bin', 'rb') as f: life_data = f.read() print('images/Paddle24x8_rgb565.bin successfully read') driver = ILI9341 except: print('Could not open paddle 24x8 image file') sys.exit() if driver == SDL: life_dsc = lv.img_dsc_t({ "header": { "always_zero": 0, "w": w, "h": h, "cf": lv.img.CF.TRUE_COLOR_ALPHA }, "data_size": len(life_data), "data": life_data, }) else: life_dsc = lv.img_dsc_t({ "header": { "always_zero": 0, "w": w, "h": h, "cf": lv.img.CF.TRUE_COLOR }, "data_size": len(life_data), "data": life_data, }) self.life_img = lv.img(lv.scr_act()) self.life_img.set_src(life_dsc) self.life_img.set_x(self.x) self.life_img.set_y(self.y)
def createPage(self): global environment_alive global g_clickTime g_clickTime = utime.ticks_ms() # init scr scr = lv.obj() win = lv.obj(scr) win.set_size(scr.get_width(), scr.get_height()) win.set_style_border_opa(0, 0) win.set_style_bg_color(lv.color_black(), 0) win.set_style_radius(0, 0) win.clear_flag(lv.obj.FLAG.SCROLLABLE) win.add_event_cb(drawOver, lv.EVENT.DRAW_POST_END, None) backImg = lv.img(win) backImg.set_src(RESOURCES_ROOT + "images/back.png") backImg.set_style_align(lv.ALIGN.LEFT_MID, 0) backImg.add_flag(lv.obj.FLAG.CLICKABLE) backImg.add_event_cb(lambda e: environment_back_click_callback(e, win), lv.EVENT.CLICKED, None) backImg.add_event_cb( lambda e: environment_back_press_callback(e, backImg), lv.EVENT.PRESSED, None) backImg.add_event_cb( lambda e: environment_back_release_callback(e, backImg), lv.EVENT.RELEASED, None) backImg.set_ext_click_area(20) container = lv.obj(win) container.set_style_bg_opa(0, 0) container.set_style_border_opa(0, 0) container.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT) container.set_flex_flow(lv.FLEX_FLOW.COLUMN) container.set_style_align(lv.ALIGN.CENTER, 0) container.set_style_pad_left(0, 0) self.createItem(container, RESOURCES_ROOT + "images/temperature.png", "25", RESOURCES_ROOT + "images/centigrade_l.png", "Temperature") self.createInterval(container, 25) self.createItem(container, RESOURCES_ROOT + "images/humidity.png", "41 %", "", "Humidity") from smart_panel import needAnimation if (needAnimation): lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.MOVE_LEFT, 500, 0, True) else: lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.NONE, 0, 0, True) environment_alive = True currentTime = utime.ticks_ms() print("run python code use: %dms" % int((currentTime - g_clickTime)))
def createItem(self, parent, iconPath, value, unityPath, tips): col_dsc = [ lv.GRID.CONTENT, 5, lv.GRID.CONTENT, lv.GRID.CONTENT, lv.GRID_TEMPLATE.LAST ] row_dsc = [lv.GRID.CONTENT, lv.GRID.CONTENT, lv.GRID_TEMPLATE.LAST] cont = lv.obj(parent) cont.set_style_bg_opa(0, 0) cont.set_style_border_opa(0, 0) cont.set_style_pad_all(0, 0) cont.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT) cont.set_style_grid_column_dsc_array(col_dsc, 0) cont.set_style_grid_row_dsc_array(row_dsc, 0) cont.set_layout(lv.LAYOUT_GRID.value) img = lv.img(cont) img.set_src(iconPath) img.set_grid_cell(lv.GRID_ALIGN.START, 0, 1, lv.GRID_ALIGN.CENTER, 0, 2) label = lv.label(cont) label.set_text(value) label.set_style_text_color(lv.color_white(), 0) label.set_style_text_font(lv.font_montserrat_48, 0) label.set_style_pad_all(0, 0) label.set_grid_cell(lv.GRID_ALIGN.START, 2, 1, lv.GRID_ALIGN.CENTER, 0, 1) if (unityPath.strip()): iconImg = lv.img(cont) iconImg.set_src(unityPath) iconImg.set_zoom(205) iconImg.set_style_pad_bottom(0, 0) iconImg.set_grid_cell(lv.GRID_ALIGN.START, 3, 1, lv.GRID_ALIGN.CENTER, 0, 1) tip = lv.label(cont) tip.set_text(tips) tip.set_style_text_color(lv.color_make(0xCC, 0xCC, 0xCC), 0) tip.set_grid_cell(lv.GRID_ALIGN.START, 2, 2, lv.GRID_ALIGN.START, 1, 1)
def __init__(self, parent, filename, x, y): self.lv_obj = lv.img(parent) self.x = x self.y = y self.lv_obj.set_pos(x, y) self.filename = filename with open(filename, 'rb') as f: img_data = f.read() img_dsc = lv.img_dsc_t({'data_size': len(img_data), 'data': img_data}) self.lv_obj.set_src(img_dsc)
def setup_register(self, setup_name, icon_filename, event_cb): self.setup_tile = self.mainbar.gui.app_tile self.log.debug("register " + setup_name + " with icon filename " + icon_filename) setup = self.setup_tile.get_free_app_icon() if setup == None: return else: self.log.debug("Icon successfully registered") setup.active = True # reserve the icon # setup label setup.label.set_text(setup_name) setup.label.align(setup.cont, lv.ALIGN.OUT_BOTTOM_MID, 0, 0) setup.label.set_align(lv.label.ALIGN.CENTER) setup.cont.set_hidden(False) setup.label.set_hidden(False) # # setup icon and set event callback # create the img buttons allowing to start the apps # setup_style = lv.style_t() setup_style.copy(self.mainbar.get_style()) # # create the imgbtn # setup.icon_img = lv.imgbtn(app.cont, None) (setup.icon_img_data, setup.icon_img_dsc) = self.get_setup_image(icon_filename) setup.icon_img.set_src(lv.btn.STATE.RELEASED, setup.icon_img_dsc) setup.icon_img.set_src(lv.btn.STATE.PRESSED, setup.icon_img_dsc) setup.icon_img.set_src(lv.btn.STATE.CHECKED_RELEASED, setup.icon_img_dsc) setup.icon_img.set_src(lv.btn.STATE.CHECKED_PRESSED, setup.icon_img_dsc) setup.icon_img.reset_style_list(lv.obj.PART.MAIN) setup.icon_img.align(setup.cont, lv.ALIGN.IN_TOP_LEFT, 0, 0) setup.icon_img.set_event_cb(event_cb) self.log.debug("imgbtn position: %d,%d" % (setup.x, setup.y)) self.mainbar.add_slide_element(setup.icon_img) # setup the indicator setup.indicator = lv.img(setup.cont, None) setup.indicator.align(setup.cont, lv.ALIGN.IN_TOP_LEFT, 0, 0) setup.indicator.set_hidden(True) lv.obj.invalidate(lv.scr_act()) return setup
def print_start_ready(self): self.anim_bg(0, LV_DEMO_PRINTER_GREEN, self.LV_DEMO_PRINTER_BG_FULL) self.anim_out_all(lv.scr_act(), 0) img = lv.img(lv.scr_act(), None) img.set_src(self.img_ready_dsc) img.align(None, lv.ALIGN.CENTER, 0, -40) delay = 200 self.anim_in(img, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY self.info_bottom_create("Printing finished", "CONTINUE", self.back_to_home_event_cb, delay)
def welcomeGUI(): # paint welcome guis scr = lv.obj() cute_bird_img = lv.img(scr) cute_bird_img.align(scr, lv.ALIGN.CENTER, 0, 0) cute_bird_img.set_src(cute_bird_img_dsc) btn = lv.btn(scr) btn.align(lv.scr_act(), lv.ALIGN.CENTER, 0, 0) label = lv.label(btn) label.set_text("Play") lv.scr_load(scr) while True: if button.value() == 0: btn.set_toggle(True) return True
def deathGUI(): # GUI when died scr = lv.obj() sad_img = lv.img(scr) sad_img.align(scr, lv.ALIGN.IN_LEFT_MID, 0, 0) sad_img.set_src(sad_img_dsc) btn = lv.btn(scr) btn.align(lv.scr_act(), lv.ALIGN.CENTER, 0, -30) label = lv.label(btn) label.set_text("Game over") lv.scr_load(scr) while True: if button.value() == 0: btn.set_toggle(True) return True
def __init__(self): # create a logger self.log = logging.getLogger("Splashscreen") self.log.setLevel(logging.DEBUG) scr_style = lv.style_t() scr_style.set_bg_color(lv.STATE.DEFAULT, lv_colors.BLACK) lv.scr_act().add_style(lv.obj.PART.MAIN, scr_style) try: with open('images/hedgehog143x81_argb8888.bin', 'rb') as f: hedgehog_data = f.read() self.log.debug("hedgehog143x81_argb8888.bin successfully read") except: try: with open('images/hedgehog143x81_argb565.bin', 'rb') as f: hedgehog_data = f.read() self.log.debug( "hedgehog143x81_argb565.bin successfully read") except: self.log.error("Could not open hedgehog image file") sys.exit() self.image = lv.img(lv.scr_act(), None) img_dsc = lv.img_dsc_t({ "header": { "always_zero": 0, "w": 143, "h": 81, "cf": lv.img.CF.TRUE_COLOR_ALPHA }, "data_size": len(hedgehog_data), "data": hedgehog_data, }) self.image.set_src(img_dsc) self.image.align(None, lv.ALIGN.CENTER, 0, -20) self.text_style = lv.style_t() self.text_style.init() self.text_style.set_text_color(lv.STATE.DEFAULT, lv_colors.WHITE) self.label = lv.label(lv.scr_act(), None) self.label.add_style(lv.label.PART.MAIN, self.text_style) self.label.set_text("Starting up...") self.label.align(self.image, lv.ALIGN.IN_BOTTOM_MID, 0, 50)
def scan_save_event_cb(self, obj, evt): if evt == lv.EVENT.CLICKED: self.scan_img = None self.anim_out_all(lv.scr_act(), 0) self.anim_bg(0, LV_DEMO_PRINTER_GREEN, self.LV_DEMO_PRINTER_BG_FULL) delay = 200 img = lv.img(lv.scr_act(), None) img.set_src(self.img_ready_dsc) img.align(None, lv.ALIGN.CENTER, 0, -40) delay += self.LV_DEMO_PRINTER_ANIM_DELAY self.anim_in(img, delay) self.info_bottom_create("File saved", "CONTINUE", self.back_to_home_event_cb, delay)
def __init__(self, drv): self.log = logging.getLogger("gui") self.log.setLevel(logging.DEBUG) # create wallpaper self.wallpaper = lv.img(lv.scr_act(), None) self.wallpaper.set_width(lv.scr_act().get_disp().driver.hor_res) self.wallpaper.set_height(lv.scr_act().get_disp().driver.ver_res) self.set_background_image(self.wallpaper_images[2]) self.wallpaper.align(None, lv.ALIGN.CENTER, 0, 0) self.mainbar = MainBar(lv.scr_act()) self.mainbar.gui = self if hasattr(drv, 'watch'): self.log.debug("watch exists in drv") self.mainbar.pcf8563 = drv.watch.rtc else: self.log.debug("could not pass drv to mainbar") self.statusbar = StatusBar(self.mainbar) # add the four mainbar screens self.main_tile = MainTile(self.mainbar) self.mainbar.main_tile = self.main_tile self.log.debug("Creating app tile") self.app_tile = AppTile(self.mainbar) self.log.debug("Creating Note tile") self.note_tile = NoteTile(self.mainbar) self.log.debug("Creating Setup tile") self.setup_tile = SetupTile(self.mainbar) self.widget = Widget(self.mainbar) self.mainbar.widget = self # add apps example_app = ExampleApp(self.mainbar) calculator_app = Calculator(self.mainbar) calendar_app = Calendar(self.mainbar) aclock = AnalogueClock(self.mainbar) alarm_clock = AlarmClock(self.mainbar) stopwatch_app = Stopwatch(self.mainbar) weather_app = WeatherApp(self.mainbar)
def __init__(self, x, y, color_index, width=26, height=14): """Initialize brick. Args: x, y (int): X,Y coordinates. color (string): Blue, Green, Pink, Red or Yellow. w (Optional int): Block width (default 26). h (Optional int): Block height (default 14). """ # print("x: %d, y: %d, color_index: %d"%(x,y,color_index)) self.x = x self.y = y self.x2 = x + width - 1 self.y2 = y + height - 1 self.center_x = x + (width // 2) self.center_y = y + (height // 2) self.color_index = color_index self.width = width self.height = height self.img = lv.img(lv.scr_act(), None) self.img.set_src(brick_img_dsc[color_index]) self.img.set_x(self.x) self.img.set_y(self.y)
def lv_img(screen): # Image descriptor img_dsc = lv.img_dsc_t() # img_dsc.data_size = len(buff) # img_dsc.data = buff # img_dsc.header.always_zero = 0 # img_dsc.header.w = 153 # img_dsc.header.h = 154 # img_dsc.header.cf = lv.img.CF.TRUE_COLOR # img_dsc.header.cf = lv.img.CF.RAW # Image from Lvgl bin builder (doesnt work) #with open('widgets/lv_img/wf565.bin', 'rb') as f: # with open('widgets/lv_img/wf888.bin', 'rb') as f: # h = lv.img_header_t() # h = f.read(4) # lv.img.decoder_get_info(h, img_dsc.header) # img_dsc.data_size = img_dsc.header.w * img_dsc.header.h * 4 # img_dsc.data = f.read() # Use PNG from imagetools # Register new image decoder decoder = lv.img.decoder_create() decoder.info_cb = get_png_info decoder.open_cb = open_png # with open('widgets/lv_img/png_decoder_test.png', 'rb') as f: with open('widgets/lv_img/wface2_240x240.png', 'rb') as f: buff = f.read() img_dsc.data = buff img_dsc.data_size = len(buff) print('buff size:', img_dsc.data_size) img = lv.img(screen) img.set_src(img_dsc)
decoder = lv.img.decoder_create() decoder.info_cb = get_png_info decoder.open_cb = open_png # Create a screen with a draggable image with open('png_decoder_test.png', 'rb') as f: png_data = f.read() png_img_dsc = lv.img_dsc_t({'data_size': len(png_data), 'data': png_data}) scr = lv.obj() # Create an image on the left using the decoder lv.img.cache_set_size(2) img1 = lv.img(scr) img1.set_pos(0, 50) img1.set_src(png_img_dsc) # img1.set_drag(True) # Create an image on the right directly without the decoder img2 = lv.img(scr) img2.set_pos(200, 50) raw_dsc = lv.img_dsc_t() get_png_info(None, png_img_dsc, raw_dsc.header) dsc = lv.img_decoder_dsc_t({'src': png_img_dsc}) if open_png(None, dsc) == lv.RES.OK: raw_dsc.data = dsc.img_data raw_dsc.data_size = raw_dsc.header.w * raw_dsc.header.h * lv.color_t.__SIZE__ img2.set_src(raw_dsc)
def main_page(self, tile_num): # create the GUI self.weather_app_tile = self.mainbar.get_tile_obj(tile_num) weather_style = lv.style_t() weather_style.copy(self.mainbar.get_style()) weather_cont = lv.obj(self.weather_app_tile, None) weather_cont.set_size(lv.scr_act().get_disp().driver.hor_res, 30) weather_cont.add_style(lv.cont.PART.MAIN, weather_style) # create date label and left right buttons btn_style = lv.style_t() btn_style.copy(weather_style) btn_style.set_radius(lv.btn.STATE.RELEASED, 2) self.left_button = lv.btn(weather_cont, None) self.left_button.set_size(25, 25) self.left_button.add_style(lv.btn.PART.MAIN, btn_style) left_label = lv.label(self.left_button, None) left_label.set_text(lv.SYMBOL.LEFT) self.left_button.align(weather_cont, lv.ALIGN.IN_LEFT_MID, 5, 0) self.left_button.set_hidden(True) self.left_button.set_event_cb(self.decrement_day) self.date_label = lv.label(weather_cont, None) self.date_label.set_text(self.date[self.day_index]) self.date_label.align(weather_cont, lv.ALIGN.CENTER, 0, 0) self.right_button = lv.btn(weather_cont, None) self.right_button.set_size(25, 25) self.right_button.add_style(lv.btn.PART.MAIN, btn_style) right_label = lv.label(self.right_button, None) right_label.set_text(lv.SYMBOL.RIGHT) self.right_button.align(weather_cont, lv.ALIGN.IN_RIGHT_MID, -5, 0) self.right_button.set_event_cb(self.increment_day) icon_cont_style = lv.style_t() icon_cont_style.copy(weather_style) icon_cont_style.set_bg_opa(lv.obj.PART.MAIN, lv.OPA.TRANSP) icon_cont = lv.cont(self.weather_app_tile, None) icon_cont.set_layout(lv.LAYOUT.COLUMN_LEFT) icon_cont.add_style(lv.cont.PART.MAIN, icon_cont_style) icon_cont.set_fit(lv.FIT.TIGHT) self.icon = lv.img(icon_cont, None) key_list = list(self.icon_filename.keys()) self.log.debug(key_list) index = key_list.index(self.weather_state_abbr[self.day_index]) self.log.debug("index of %s: %d" % (self.weather_state_abbr[self.day_index], index)) self.icon.set_src(self.icon_dsc[index]) icon_cont.align(weather_cont, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) self.state_label = lv.label(icon_cont, None) self.state_label.set_width(100) self.state_label.set_text(self.weather_state_name[self.day_index]) info_cont_style = lv.style_t() info_cont_style.copy(weather_style) info_cont_style.set_pad_top(lv.STATE.DEFAULT, 6) info_cont_style.set_pad_inner(lv.STATE.DEFAULT, 4) info_cont = lv.cont(self.weather_app_tile, None) info_cont.set_size(lv.scr_act().get_disp().driver.hor_res, 90) info_cont.set_layout(lv.LAYOUT.COLUMN_LEFT) info_cont.add_style(lv.cont.PART.MAIN, icon_cont_style) info_cont.set_fit(lv.FIT.NONE) info_cont.align(icon_cont, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) info_cont.add_style(lv.cont.PART.MAIN, info_cont_style) self.confidence_label = lv.label(info_cont, None) self.confidence_label.set_text("Confidence level: {}%".format( self.predic[self.day_index])) self.temp_label = lv.label(info_cont, None) self.temp_label.set_text( "Temp: min: %3.1f°C, max: %3.1f°C" % (self.min_temp[self.day_index], self.max_temp[self.day_index])) self.humidity_label = lv.label(info_cont, None) self.humidity_label.set_text("Humidity: {}%".format( self.humid[self.day_index])) self.pressure_label = lv.label(info_cont, None) self.pressure_label.set_text("Air pressure: %d hPa" % self.air_pressure[self.day_index]) info_cont2 = lv.cont(self.weather_app_tile, None) # info_cont2.set_size(140,120) info_cont2.set_layout(lv.LAYOUT.COLUMN_LEFT) info_cont2.add_style(lv.cont.PART.MAIN, icon_cont_style) info_cont2.set_fit(lv.FIT.TIGHT) info_cont2.align(icon_cont, lv.ALIGN.OUT_RIGHT_TOP, -5, 0) info_cont2.add_style(lv.cont.PART.MAIN, info_cont_style) self.location_label = lv.label(info_cont2, None) self.location_label.set_text("Location: " + self.location) self.wind_label = lv.label(info_cont2, None) self.wind_label.set_text("Wind:\nspeed: %5.1f kph\ndir: %s" % (self.wind_speed[self.day_index], self.wind_direction[self.day_index])) exit_btn = lv.imgbtn(self.weather_app_tile, None) exit_btn.set_src(lv.btn.STATE.RELEASED, self.mainbar.get_exit_btn_dsc()) exit_btn.set_src(lv.btn.STATE.PRESSED, self.mainbar.get_exit_btn_dsc()) exit_btn.set_src(lv.btn.STATE.CHECKED_RELEASED, self.mainbar.get_exit_btn_dsc()) exit_btn.set_src(lv.btn.STATE.CHECKED_PRESSED, self.mainbar.get_exit_btn_dsc()) exit_btn.align(self.weather_app_tile, lv.ALIGN.IN_BOTTOM_RIGHT, -10, -10) exit_btn.set_event_cb(self.exit_weather_app_event_cb)
#!/opt/bin/lv_micropython -i import lvgl as lv import display_driver import fs_driver fs_drv = lv.fs_drv_t() fs_driver.fs_register(fs_drv, 'S') img = lv.img(lv.scr_act()) # The File system is attached to letter 'S' img.set_src("S:example_32bit.bmp") img.center()
from imagetools import get_png_info, open_png display_driver.getdisplay_landscape() # Register PNG image decoder decoder = lv.img.decoder_create() decoder.info_cb = get_png_info decoder.open_cb = open_png # Create an image from the png file try: with open('../assets/img_cogwheel_argb.png', 'rb') as f: png_data = f.read() except: print("Could not find img_cogwheel_argb.png") sys.exit() img_cogwheel_argb = lv.img_dsc_t({ 'data_size': len(png_data), 'data': png_data }) img1 = lv.img(lv.scr_act()) img1.set_src(img_cogwheel_argb) img1.align(lv.ALIGN.CENTER, 0, -20) img1.set_size(200, 200) img2 = lv.img(lv.scr_act()) img2.set_src(lv.SYMBOL.OK + "Accept") img2.align_to(img1, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
try: with open('images/hedgehog143x81_argb8888.bin','rb') as f: img_data = f.read() driver = SDL except: try: with open('images/hedgehog143x81_rgb565.bin','rb') as f: img_data = f.read() driver = TWATCH except: print("Could not open hedgehog image file") sys.exit() scr = lv.scr_act() img = lv.img(scr) img.align(scr, lv.ALIGN.CENTER, 0, 0) if driver == SDL: img_dsc = lv.img_dsc_t( { "header": {"always_zero": 0, "w": 143, "h": 81, "cf": lv.img.CF.TRUE_COLOR_ALPHA}, "data_size": len(img_data), "data": img_data, } ) else: img_dsc = lv.img_dsc_t( { "header": {"always_zero": 0, "w": 143, "h": 81, "cf": lv.img.CF.TRUE_COLOR}, "data_size": len(img_data), "data": img_data,
def scan1_open(self, btn_txt): self.log.debug("scan1_open " + btn_txt) self.anim_out_all(lv.scr_act(), 0) self.anim_bg(0, LV_DEMO_PRINTER_BLUE, self.LV_DEMO_PRINTER_BG_NORMAL) delay = 200 back = self.add_back(self.back_to_home_event_cb) title = self.add_title("ADJUST IMAGE") self.scan_img = lv.img(lv.scr_act(), None) self.scan_img.set_src(self.scan_example_dsc) self.scan_img.align(None, lv.ALIGN.IN_TOP_LEFT, 40, 100) self.scan_img.set_style_local_radius(lv.img.PART.MAIN, lv.STATE.DEFAULT, 10) self.scan_img.set_style_local_clip_corner(lv.img.PART.MAIN, lv.STATE.DEFAULT, True) self.scan_img.set_style_local_image_recolor_opa( lv.img.PART.MAIN, lv.STATE.DEFAULT, 80) box_w = 160 settings_box = lv.obj(lv.scr_act(), None) settings_box.set_size(box_w, 245) settings_box.align(self.scan_img, lv.ALIGN.OUT_RIGHT_TOP, 40, 0) self.lightness_act = 0 self.hue_act = 180 slider = lv.slider(settings_box, None) slider.set_size(8, 160) slider.align(None, lv.ALIGN.IN_TOP_MID, -35, 65) slider.set_event_cb(self.lightness_slider_event_cb) slider.set_range(-80, 80) slider.set_value(0, lv.ANIM.OFF) slider.set_ext_click_area(30, 30, 30, 30) self.theme.apply(slider, lv.THEME.SLIDER) icon = lv.img(settings_box, None) icon.set_src(self.icon_bright_dsc) icon.align(slider, lv.ALIGN.OUT_TOP_MID, 0, -30) slider = lv.slider(settings_box, slider) slider.align(None, lv.ALIGN.IN_TOP_MID, 35, 65) slider.set_event_cb(self.hue_slider_event_cb) slider.set_range(0, 359) slider.set_value(180, lv.ANIM.OFF) self.theme.apply(slider, lv.THEME.SLIDER) icon = lv.img(settings_box, None) icon.set_src(self.icon_hue_dsc) icon.align(slider, lv.ALIGN.OUT_TOP_MID, 0, -30) self.scan_img_color_refr() next_btn = lv.btn(lv.scr_act(), None) self.theme.apply(next_btn, LV_DEMO_PRINTER_THEME_BTN_CIRCLE) next_btn.set_size(box_w, 60) next_btn.align(self.scan_img, lv.ALIGN.OUT_RIGHT_BOTTOM, 40, 0) if btn_txt == "NEXT": next_btn.set_event_cb(self.scan_next_event_cb) next_btn.set_style_local_value_str(lv.obj.PART.MAIN, lv.STATE.DEFAULT, "NEXT") next_btn.set_style_local_value_font(lv.obj.PART.MAIN, lv.STATE.DEFAULT, self.theme.get_font_subtitle()) elif btn_txt == "SAVE": next_btn.set_event_cb(self.scan_save_event_cb) next_btn.set_style_local_value_str(lv.obj.PART.MAIN, lv.STATE.DEFAULT, "SAVE") next_btn.set_style_local_value_font(lv.obj.PART.MAIN, lv.STATE.DEFAULT, self.theme.get_font_subtitle()) next_btn.set_style_local_bg_color(lv.obj.PART.MAIN, lv.STATE.DEFAULT, LV_DEMO_PRINTER_GREEN) next_btn.set_style_local_bg_color( lv.obj.PART.MAIN, lv.STATE.PRESSED, LV_DEMO_PRINTER_GREEN.color_darken(lv.OPA._20))
#!/opt/bin/lv_micropython -i # change the above to the path of your lv_micropython unix binary # import time # # initialize lvgl # import lvgl as lv import display_driver from info_2_8px_argb8888 import info_2_8px_img_dsc # Create an object with the new style obj = lv.img(lv.scr_act(), None) lv.img.cache_set_size(2) obj.set_src(info_2_8px_img_dsc) obj.align(None, lv.ALIGN.CENTER, 0, 0)
def home_open(self, delay): self.bg_top.set_style_local_bg_opa(lv.obj.PART.MAIN, lv.STATE.DEFAULT, lv.OPA.COVER) self.bg_top.set_style_local_bg_color(lv.obj.PART.MAIN, lv.STATE.DEFAULT, LV_DEMO_PRINTER_BLUE) self.bg_top.set_y(self.LV_DEMO_PRINTER_BG_NORMAL) self.cont = lv.cont(lv.scr_act(), None) self.cont.set_size(350, 80) self.cont.clean_style_list(lv.cont.PART.MAIN) self.cont.align(None, lv.ALIGN.IN_TOP_LEFT, 60, 0) icon = lv.img(self.cont, None) icon.set_src(self.icon_wifi_dsc) icon.align(None, lv.ALIGN.IN_TOP_LEFT, 20, 45) self.anim_in(icon, delay) icon = lv.img(self.cont, None) icon.set_src(self.icon_tel_dsc) icon.align(None, lv.ALIGN.IN_TOP_LEFT, 110, 45) self.anim_in(icon, delay) icon = lv.img(self.cont, None) icon.set_src(self.icon_eco_dsc) icon.align(None, lv.ALIGN.IN_TOP_LEFT, 200, 45) self.anim_in(icon, delay) icon = lv.img(self.cont, None) icon.set_src(self.icon_pc_dsc) icon.align(None, lv.ALIGN.IN_TOP_LEFT, 290, 45) self.anim_in(icon, delay) title = self.add_title("23 February 2021 20:13") title.align(None, lv.ALIGN.IN_TOP_RIGHT, -60, LV_DEMO_PRINTER_TITLE_PAD) delay += self.LV_DEMO_PRINTER_ANIM_DELAY self.anim_in(title, delay) box_w = 720 box = lv.obj(lv.scr_act(), None) box.set_size(box_w, 260) self.theme.apply(box, lv.THEME.CONT) box.align(None, lv.ALIGN.IN_TOP_MID, 0, 100) delay += self.LV_DEMO_PRINTER_ANIM_DELAY self.anim_in(box, delay) icon = self.add_icon(box, self.img_btn_bg_1_dsc, self.img_copy_dsc, "COPY") icon.align(None, lv.ALIGN.IN_LEFT_MID, 1 * (box_w - 20) // 8 - 80, 0) icon.set_event_cb(self.copy_open_icon_event_cb) icon.fade_in(self.LV_DEMO_PRINTER_ANIM_TIME * 2, delay + self.LV_DEMO_PRINTER_ANIM_TIME + 50) icon = self.add_icon(box, self.img_btn_bg_2_dsc, self.img_scan_dsc, "SCAN") icon.align(None, lv.ALIGN.IN_LEFT_MID, 3 * (box_w - 20) // 8 - 80, 0) icon.fade_in(self.LV_DEMO_PRINTER_ANIM_TIME * 2, delay + self.LV_DEMO_PRINTER_ANIM_TIME + 50) icon.set_event_cb(self.scan_open_icon_event_cb) icon = self.add_icon(box, self.img_btn_bg_3_dsc, self.img_print_dsc, "PRINT") icon.align(None, lv.ALIGN.IN_LEFT_MID, 5 * (box_w - 20) // 8 - 80, 0) icon.fade_in(self.LV_DEMO_PRINTER_ANIM_TIME * 2, delay + self.LV_DEMO_PRINTER_ANIM_TIME + 50) icon.set_event_cb(self.print_open_event_cb) icon = self.add_icon(box, self.img_btn_bg_4_dsc, self.img_setup_dsc, "SETUP") icon.align(None, lv.ALIGN.IN_LEFT_MID, 7 * (box_w - 20) // 8 - 80, 0) icon.fade_in(self.LV_DEMO_PRINTER_ANIM_TIME * 2, delay + self.LV_DEMO_PRINTER_ANIM_TIME + 50) icon.set_event_cb(self.setup_icon_event_cb) box = lv.obj(lv.scr_act(), None) box.set_size(500, 80) box.align(None, lv.ALIGN.IN_BOTTOM_LEFT, self.LV_HOR_RES // 20, -self.LV_HOR_RES // 40) label = lv.label(box, None) label.set_text("What do you want to do today?") self.theme.apply(label, lv.THEME.LABEL) label.align(box, lv.ALIGN.CENTER, 0, 0) delay += self.LV_DEMO_PRINTER_ANIM_DELAY self.anim_in(box, delay) box = lv.obj(lv.scr_act(), None) box_w = 200 box.set_size(box_w, 80) box.align(None, lv.ALIGN.IN_BOTTOM_RIGHT, -self.LV_HOR_RES // 20, -self.LV_HOR_RES // 40) bar = lv.bar(box, None) bar.set_style_local_bg_color(lv.bar.PART.INDIC, lv.STATE.DEFAULT, lv.color_hex(0x01d3d4)) bar.set_size(25, 50) bar.align(None, lv.ALIGN.IN_LEFT_MID, 1 * (box_w - 20) // 8 + 10, 0) bar.set_value(60, lv.ANIM.ON) bar = lv.bar(box, None) bar.set_style_local_bg_color(lv.bar.PART.INDIC, lv.STATE.DEFAULT, lv.color_hex(0xe600e6)) bar.set_size(25, 50) bar.align(None, lv.ALIGN.IN_LEFT_MID, 3 * (box_w - 20) // 8 + 10, 0) bar.set_value(30, lv.ANIM.ON) bar = lv.bar(box, None) bar.set_style_local_bg_color(lv.bar.PART.INDIC, lv.STATE.DEFAULT, lv.color_hex(0xefef01)) bar.set_size(25, 50) bar.align(None, lv.ALIGN.IN_LEFT_MID, 5 * (box_w - 20) // 8 + 10, 0) bar.set_value(80, lv.ANIM.ON) bar = lv.bar(box, None) bar.set_style_local_bg_color(lv.bar.PART.INDIC, lv.STATE.DEFAULT, lv.color_hex(0x1d1d25)) bar.set_size(25, 50) bar.align(None, lv.ALIGN.IN_LEFT_MID, 7 * (box_w - 20) // 8 + 10, 0) bar.set_value(20, lv.ANIM.ON)