def event_cb(e): dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) if dsc.part != lv.PART.INDICATOR: return obj= e.get_target() label_dsc = lv.draw_label_dsc_t() label_dsc.init() # label_dsc.font = LV_FONT_DEFAULT; value_txt = str(obj.get_value()) txt_size = lv.point_t() lv.txt_get_size(txt_size, value_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, lv.COORD.MAX, label_dsc.flag) txt_area = lv.area_t() # If the indicator is long enough put the text inside on the right if dsc.draw_area.get_width() > txt_size.x + 20: txt_area.x2 = dsc.draw_area.x2 - 5 txt_area.x1 = txt_area.x2 - txt_size.x + 1 label_dsc.color = lv.color_white() # If the indicator is still short put the text out of it on the right*/ else: txt_area.x1 = dsc.draw_area.x2 + 5 txt_area.x2 = txt_area.x1 + txt_size.x - 1 label_dsc.color = lv.color_black() txt_area.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - txt_size.y) // 2 txt_area.y2 = txt_area.y1 + txt_size.y - 1 dsc.draw_ctx.label(label_dsc, txt_area, value_txt, None)
def __init__(self): self.mask_top_id = -1 self.mask_bottom_id = -1 # # Add an fade mask to roller. # style = lv.style_t() style.init() style.set_bg_color(lv.color_black()) style.set_text_color(lv.color_white()) lv.scr_act().add_style(style, 0) roller1 = lv.roller(lv.scr_act()) roller1.add_style(style, 0) roller1.set_style_border_width(0, 0) roller1.set_style_pad_all(0, 0) roller1.set_style_bg_opa(lv.OPA.TRANSP, lv.PART.SELECTED) #if LV_FONT_MONTSERRAT_22 # lv_obj_set_style_text_font(roller1, &lv_font_montserrat_22, LV_PART_SELECTED); #endif roller1.set_options( "\n".join([ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]), lv.roller.MODE.NORMAL) roller1.center() roller1.set_visible_row_count(3) roller1.add_event_cb(self.mask_event_cb, lv.EVENT.ALL, None)
def event_cb(e): code = e.get_code() obj = e.get_target() if code == lv.EVENT.DRAW_PART_BEGIN: dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) # Change the draw descriptor the 2nd button if dsc.id == 1: dsc.rect_dsc.radius = 0 if obj.get_selected_btn() == dsc.id: dsc.rect_dsc.bg_color = lv.palette_darken(lv.PALETTE.GREY, 3) else: dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE) dsc.rect_dsc.shadow_width = 6 dsc.rect_dsc.shadow_ofs_x = 3 dsc.rect_dsc.shadow_ofs_y = 3 dsc.label_dsc.color = lv.color_white() # Change the draw descriptor the 3rd button elif dsc.id == 2: dsc.rect_dsc.radius = lv.RADIUS.CIRCLE if obj.get_selected_btn() == dsc.id: dsc.rect_dsc.bg_color = lv.palette_darken(lv.PALETTE.RED, 3) else: dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.RED) dsc.label_dsc.color = lv.color_white() elif dsc.id == 3: dsc.label_dsc.opa = lv.OPA.TRANSP # Hide the text if any if code == lv.EVENT.DRAW_PART_END: dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) # Add custom content to the 4th button when the button itself was drawn if dsc.id == 3: # LV_IMG_DECLARE(img_star); header = lv.img_header_t() res = lv.img.decoder_get_info(img_star_argb, header) if res != lv.RES.OK: print("error when getting image header") return else: a = lv.area_t() a.x1 = dsc.draw_area.x1 + (dsc.draw_area.get_width() - header.w) // 2 a.x2 = a.x1 + header.w - 1 a.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - header.h) // 2 a.y2 = a.y1 + header.h - 1 img_draw_dsc = lv.draw_img_dsc_t() img_draw_dsc.init() img_draw_dsc.recolor = lv.color_black() if obj.get_selected_btn() == dsc.id: img_draw_dsc.recolor_opa = lv.OPA._30 lv.draw_img(a, dsc.clip_area, img_star_argb, img_draw_dsc)
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 event_cb(e): code = e.get_code() chart = e.get_target() if code == lv.EVENT.VALUE_CHANGED: chart.invalidate() if code == lv.EVENT.REFR_EXT_DRAW_SIZE: e.set_ext_draw_size(20) elif code == lv.EVENT.DRAW_POST_END: id = lv.chart.get_pressed_point(chart) if id == lv.CHART_POINT.NONE: return # print("Selected point ", id) for i in range(len(series)): p = lv.point_t() chart.get_point_pos_by_id(series[i], id, p) value = series_points[i][id] buf = lv.SYMBOL.DUMMY + "$" + str(value) draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_color = lv.color_black() draw_rect_dsc.bg_opa = lv.OPA._50 draw_rect_dsc.radius = 3 draw_rect_dsc.bg_img_src = buf draw_rect_dsc.bg_img_recolor = lv.color_white() a = lv.area_t() coords = lv.area_t() chart.get_coords(coords) a.x1 = coords.x1 + p.x - 20 a.x2 = coords.x1 + p.x + 20 a.y1 = coords.y1 + p.y - 30 a.y2 = coords.y1 + p.y - 10 clip_area = lv.area_t.cast(e.get_param()) lv.draw_rect(a, clip_area, draw_rect_dsc) elif code == lv.EVENT.RELEASED: chart.invalidate()
#!//opt/bin/lv_micropython -i import time import lvgl as lv import display_driver # # Create a fake text shadow # # Create a style for the shadow style_shadow = lv.style_t() style_shadow.init() style_shadow.set_text_opa(lv.OPA._30) style_shadow.set_text_color(lv.color_black()) # Create a label for the shadow first (it's in the background) shadow_label = lv.label(lv.scr_act()) shadow_label.add_style(style_shadow, 0) # Create the main label main_label = lv.label(lv.scr_act()) main_label.set_text("A simple method to create\n" "shadows on a text.\n" "It even works with\n\n" "newlines and spaces.") # Set the same text for the shadow label shadow_label.set_text(lv.label.get_text(main_label)) # Position the main label main_label.align(lv.ALIGN.CENTER, 0, 0)
meter = lv.meter(lv.scr_act()) meter.set_size(220, 220) meter.center() # Create a scale for the minutes # 61 ticks in a 360 degrees range (the last and the first line overlaps) scale_min = meter.add_scale() meter.set_scale_ticks(scale_min, 61, 1, 10, lv.palette_main(lv.PALETTE.GREY)) meter.set_scale_range(scale_min, 0, 60, 360, 270) # Create another scale for the hours. It's only visual and contains only major ticks scale_hour = meter.add_scale() meter.set_scale_ticks(scale_hour, 12, 0, 0, lv.palette_main(lv.PALETTE.GREY)) # 12 ticks meter.set_scale_major_ticks(scale_hour, 1, 2, 20, lv.color_black(), 10) # Every tick is major meter.set_scale_range(scale_hour, 1, 12, 330, 300) # [1..12] values in an almost full circle # LV_IMG_DECLARE(img_hand) # Add the hands from images indic_min = meter.add_needle_img(scale_min, img_hand_min_dsc, 5, 5) indic_hour = meter.add_needle_img(scale_min, img_hand_hour_dsc, 5, 5) # Create an animation to set the value a1 = lv.anim_t() a1.init() a1.set_values(0, 60) a1.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
import display_driver def set_value(indic, v): meter.set_indicator_value(indic, v) # # A simple meter # meter = lv.meter(lv.scr_act()) meter.center() meter.set_size(200, 200) # Add a scale first scale = meter.add_scale() meter.set_scale_ticks(scale, 51, 2, 10, lv.palette_main(lv.PALETTE.GREY)) meter.set_scale_major_ticks(scale, 10, 4, 15, lv.color_black(), 10) indic = lv.meter_indicator_t() # Add a blue arc to the start indic = meter.add_arc(scale, 3, lv.palette_main(lv.PALETTE.BLUE), 0) meter.set_indicator_start_value(indic, 0) meter.set_indicator_end_value(indic, 20) # Make the tick lines blue at the start of the scale indic = meter.add_scale_lines(scale, lv.palette_main(lv.PALETTE.BLUE), lv.palette_main(lv.PALETTE.BLUE), False, 0) meter.set_indicator_start_value(indic, 0) meter.set_indicator_end_value(indic, 20) # Add a red arc to the end indic = meter.add_arc(scale, 3, lv.palette_main(lv.PALETTE.RED), 0)
except: print("Could not find img_skew_strip.png") sys.exit() img_skew_strip = lv.img_dsc_t({'data_size': len(png_data), 'data': png_data}) # # Image styling and offset # style = lv.style_t() style.init() style.set_bg_color(lv.palette_main(lv.PALETTE.YELLOW)) style.set_bg_opa(lv.OPA.COVER) style.set_img_recolor_opa(lv.OPA.COVER) style.set_img_recolor(lv.color_black()) img = lv.img(lv.scr_act()) img.add_style(style, 0) img.set_src(img_skew_strip) img.set_size(150, 100) img.center() a = lv.anim_t() a.init() a.set_var(img) a.set_values(0, 100) a.set_time(3000) a.set_playback_time(500) a.set_repeat_count(lv.ANIM_REPEAT.INFINITE) a.set_custom_exec_cb(lambda a, val: ofs_y_anim(img, val))
def createPage(self): global value global sound_ttf_alive print("Enter SoundTTF") # 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_radius(0, 0) win.set_style_bg_color(lv.color_black(), 0) win.clear_flag(lv.obj.FLAG.SCROLLABLE) win.set_style_pad_right(30, 0) title = lv.label(win) title.set_text("Sound TTF") title.set_style_text_color(lv.color_white(), 0) title.set_style_text_font(lv.font_montserrat_28, 0) title.align(lv.ALIGN.TOP_LEFT, 20, 0) decibel = lv.label(win) decibel.set_text(str(value) + "dB") decibel.set_style_text_color(lv.color_make(0xFF, 0xA8, 0x48), 0) decibel.set_style_text_font(lv.font_montserrat_28, 0) decibel.align(lv.ALIGN.TOP_RIGHT, 0, 0) chart = lv.chart(win) chart.set_type(lv.chart.TYPE.BAR) chart.set_style_border_opa(0, 0) chart.set_style_bg_opa(0, 0) chart.set_style_line_opa(0, 0) chart.set_width(280) chart.set_height(160) chart.set_div_line_count(6, 0) chart.set_point_count(12) chart.align(lv.ALIGN.BOTTOM_MID, 20, -5) chart.add_event_cb(chart_event_cb, lv.EVENT.DRAW_PART_END, None) ser1 = chart.add_series(lv.color_make(0x56, 0x56, 0x56), lv.chart.AXIS.PRIMARY_Y) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) chart.set_next_value(ser1, lv.rand(30, 100)) 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: sound_ttf_back_click_callback(e, win), lv.EVENT.CLICKED, None) backImg.set_ext_click_area(30) backImg.add_event_cb( lambda e: sound_ttf_back_press_callback(e, backImg), lv.EVENT.PRESSED, None) backImg.add_event_cb( lambda e: sound_ttf_back_release_callback(e, backImg), lv.EVENT.RELEASED, None) 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) sound_ttf_alive = True
# # Create a pie chart # meter = lv.meter(lv.scr_act()) # Remove the background and the circle from the middle meter.remove_style(None, lv.PART.MAIN) meter.remove_style(None, lv.PART.INDICATOR) meter.set_size(200, 200) meter.center() # Add a scale first with no ticks. scale = meter.add_scale() meter.set_scale_ticks(scale, 0, 0, 0, lv.color_black()) meter.set_scale_range(scale, 0, 100, 360, 0) # Add a three arc indicator* indic_w = 100 indic1 = meter.add_arc(scale, indic_w,lv.palette_main(lv.PALETTE.ORANGE), 0) meter.set_indicator_start_value(indic1, 0) meter.set_indicator_end_value(indic1, 40) indic2 = meter.add_arc(scale, indic_w, lv.palette_main(lv.PALETTE.YELLOW), 0) meter.set_indicator_start_value(indic2, 40) # Start from the previous meter.set_indicator_end_value(indic2, 80) indic3 = meter.add_arc(scale, indic_w, lv.palette_main(lv.PALETTE.DEEP_ORANGE), 0) meter.set_indicator_start_value(indic3, 80) # Start from the previous meter.set_indicator_end_value(indic3, 100)
def createPage(self): global isStarted global isAnimationComplete global arc global anim global timeCount global currentSelect global minuteLabel global secondLabel global millionLabel global anim_timeline global startLabel global currentValue global timer_alive print("Enter Timer") # 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_radius(0, 0) win.set_style_bg_color(lv.color_black(), 0) win.clear_flag(lv.obj.FLAG.SCROLLABLE) # back 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: timer_back_click_callback(e, win), lv.EVENT.CLICKED, None) backImg.add_event_cb(lambda e: timer_back_press_callback(e, backImg), lv.EVENT.PRESSED, None) backImg.add_event_cb(lambda e: timer_back_release_callback(e, backImg), lv.EVENT.RELEASED, None) backImg.set_ext_click_area(30) isStarted = False currentSelect = 0 # count down func_col_dsc = [40, 5, 30, 5, 20, lv.GRID_TEMPLATE.LAST] func_row_dsc = [30, lv.GRID_TEMPLATE.LAST] timeContainer = lv.obj(win) timeContainer.set_style_bg_opa(0, 0) timeContainer.set_style_border_opa(0, 0) timeContainer.set_layout(lv.LAYOUT_GRID.value) timeContainer.set_style_grid_column_dsc_array(func_col_dsc, 0) timeContainer.set_style_grid_row_dsc_array(func_row_dsc, 0) timeContainer.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN, lv.GRID_ALIGN.SPACE_BETWEEN) timeContainer.set_style_pad_all(0, 0) timeContainer.set_size(240, 70) timeContainer.center() minuteLabel = lv.label(timeContainer) minuteLabel.set_style_text_font(lv.font_montserrat_48, 0) minuteLabel.set_style_text_color(lv.color_white(), 0) minuteLabel.set_grid_cell(lv.GRID_ALIGN.START, 0, 1, lv.GRID_ALIGN.CENTER, 0, 1) signLabel = lv.label(timeContainer) signLabel.set_style_text_font(lv.font_montserrat_48, 0) signLabel.set_style_text_color(lv.color_white(), 0) signLabel.set_text(":") signLabel.set_grid_cell(lv.GRID_ALIGN.CENTER, 1, 1, lv.GRID_ALIGN.CENTER, 0, 1) secondLabel = lv.label(timeContainer) secondLabel.set_style_text_font(lv.font_montserrat_48, 0) secondLabel.set_style_text_color(lv.color_white(), 0) secondLabel.set_grid_cell(lv.GRID_ALIGN.CENTER, 2, 1, lv.GRID_ALIGN.CENTER, 0, 1) signLabel = lv.label(timeContainer) signLabel.set_style_text_font(lv.font_montserrat_48, 0) signLabel.set_style_text_color(lv.color_white(), 0) signLabel.set_text(":") signLabel.set_grid_cell(lv.GRID_ALIGN.CENTER, 3, 1, lv.GRID_ALIGN.CENTER, 0, 1) millionLabel = lv.label(timeContainer) millionLabel.set_style_text_font(lv.font_montserrat_36, 0) millionLabel.set_style_text_color(lv.color_white(), 0) millionLabel.set_grid_cell(lv.GRID_ALIGN.END, 4, 1, lv.GRID_ALIGN.START, 0, 1) setLabelValue(timeCount[currentSelect] * 60 * 50) startButton = lv.btn(win) startButton.align(lv.ALIGN.CENTER, 0, 40) startButton.set_size(126, 54) startButton.set_style_radius(45, lv.PART.MAIN) startButton.set_style_shadow_opa(0, 0) startButton.set_style_bg_color(lv.color_make(0xFF, 0xA8, 0x48), lv.PART.MAIN) startButton.align(lv.ALIGN.BOTTOM_LEFT, 12, -12) startButton.add_event_cb(start_button_event_handler, lv.EVENT.CLICKED, None) startLabel = lv.label(startButton) startLabel.set_text("START") startLabel.set_style_text_color(lv.color_black(), 0) startLabel.set_style_text_font(lv.font_montserrat_20, 0) startLabel.center() resetButton = lv.btn(win) resetButton.align(lv.ALIGN.CENTER, 0, 40) resetButton.set_size(126, 54) resetButton.set_style_radius(45, lv.PART.MAIN) resetButton.set_style_shadow_opa(0, 0) resetButton.set_style_bg_color(lv.color_white(), lv.PART.MAIN) resetButton.align(lv.ALIGN.BOTTOM_RIGHT, -12, -12) resetButton.add_event_cb(reset_button_event_handler, lv.EVENT.CLICKED, None) resetLabel = lv.label(resetButton) resetLabel.set_text("REST") resetLabel.set_style_text_color(lv.color_black(), 0) resetLabel.set_style_text_font(lv.font_montserrat_20, 0) resetLabel.center() # select time col_dsc = [75, 75, 75, 75, lv.GRID_TEMPLATE.LAST] row_dsc = [60, 80, 60, lv.GRID_TEMPLATE.LAST] funcContainer = lv.obj(win) funcContainer.set_layout(lv.LAYOUT_GRID.value) funcContainer.set_style_bg_opa(0, 0) funcContainer.set_style_border_opa(0, 0) funcContainer.set_style_grid_column_dsc_array(col_dsc, 0) funcContainer.set_style_grid_row_dsc_array(row_dsc, 0) funcContainer.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN, lv.GRID_ALIGN.SPACE_BETWEEN) funcContainer.set_size(300, 90) funcContainer.set_style_align(lv.ALIGN.TOP_MID, 0) maxMillionSecond = timeCount[0] * 60 * 50 arc[0] = lv.arc(funcContainer) arc[0].set_style_arc_color(lv.color_white(), lv.PART.INDICATOR) arc[0].set_style_arc_color(lv.color_make(0x33, 0x33, 0x33), lv.PART.MAIN) arc[0].set_range(0, maxMillionSecond) arc[0].set_size(55, 55) arc[0].set_rotation(90) arc[0].set_bg_angles(0, 360) arc[0].remove_style(None, lv.PART.KNOB) arc[0].set_value(maxMillionSecond) arc[0].set_style_arc_width(8, lv.PART.INDICATOR) arc[0].set_style_arc_width(8, lv.PART.MAIN) arc[0].set_grid_cell(lv.GRID_ALIGN.CENTER, 0, 1, lv.GRID_ALIGN.CENTER, 0, 1) arc[0].clear_flag(lv.obj.FLAG.CLICKABLE) totalTime = lv.label(funcContainer) totalTime.set_text(str(timeCount[0])) totalTime.set_style_text_font(lv.font_montserrat_18, 0) totalTime.set_style_text_color(lv.color_white(), 0) totalTime.set_grid_cell(lv.GRID_ALIGN.CENTER, 0, 1, lv.GRID_ALIGN.CENTER, 0, 1) totalTime.add_flag(lv.obj.FLAG.CLICKABLE) totalTime.add_event_cb(lambda e: arc_event_handler(e, 0), lv.EVENT.CLICKED, None) totalTime.set_ext_click_area(30) anim[0] = lv.anim_t() anim[0].init() anim[0].set_var(arc[0]) anim[0].set_time(maxMillionSecond * 20) anim[0].set_values(maxMillionSecond, 0) anim[0].set_custom_exec_cb(lambda a1, val: set_time_value(arc[0], val)) anim_timeline = lv.anim_timeline_create() lv.anim_timeline_add(anim_timeline, 0, anim[0]) arc[1] = lv.arc(funcContainer) arc[1].set_style_arc_color(lv.color_white(), lv.PART.INDICATOR) arc[1].set_style_arc_color(lv.color_make(0x33, 0x33, 0x33), lv.PART.MAIN) arc[1].set_range(0, maxMillionSecond) arc[1].set_size(55, 55) arc[1].set_rotation(90) arc[1].set_bg_angles(0, 360) arc[1].remove_style(None, lv.PART.KNOB) arc[1].set_value(0) arc[1].set_style_arc_width(2, lv.PART.INDICATOR) arc[1].set_style_arc_width(2, lv.PART.MAIN) arc[1].set_grid_cell(lv.GRID_ALIGN.CENTER, 1, 1, lv.GRID_ALIGN.CENTER, 0, 1) arc[1].clear_flag(lv.obj.FLAG.CLICKABLE) totalTime = lv.label(funcContainer) totalTime.set_text(str(timeCount[1])) totalTime.set_style_text_font(lv.font_montserrat_18, 0) totalTime.set_style_text_color(lv.color_white(), 0) totalTime.set_grid_cell(lv.GRID_ALIGN.CENTER, 1, 1, lv.GRID_ALIGN.CENTER, 0, 1) totalTime.add_flag(lv.obj.FLAG.CLICKABLE) totalTime.add_event_cb(lambda e: arc_event_handler(e, 1), lv.EVENT.CLICKED, None) totalTime.set_ext_click_area(30) arc[2] = lv.arc(funcContainer) arc[2].set_style_arc_color(lv.color_white(), lv.PART.INDICATOR) arc[2].set_style_arc_color(lv.color_make(0x33, 0x33, 0x33), lv.PART.MAIN) arc[2].set_range(0, maxMillionSecond) arc[2].set_size(55, 55) arc[2].set_rotation(90) arc[2].set_bg_angles(0, 360) arc[2].remove_style(None, lv.PART.KNOB) arc[2].set_value(0) arc[2].set_style_arc_width(2, lv.PART.INDICATOR) arc[2].set_style_arc_width(2, lv.PART.MAIN) arc[2].set_grid_cell(lv.GRID_ALIGN.CENTER, 2, 1, lv.GRID_ALIGN.CENTER, 0, 1) arc[2].clear_flag(lv.obj.FLAG.CLICKABLE) totalTime = lv.label(funcContainer) totalTime.set_text(str(timeCount[2])) totalTime.set_style_text_font(lv.font_montserrat_18, 0) totalTime.set_style_text_color(lv.color_white(), 0) totalTime.set_grid_cell(lv.GRID_ALIGN.CENTER, 2, 1, lv.GRID_ALIGN.CENTER, 0, 1) totalTime.add_flag(lv.obj.FLAG.CLICKABLE) totalTime.add_event_cb(lambda e: arc_event_handler(e, 2), lv.EVENT.CLICKED, None) totalTime.set_ext_click_area(30) arc[3] = lv.arc(funcContainer) arc[3].set_style_arc_color(lv.color_white(), lv.PART.INDICATOR) arc[3].set_style_arc_color(lv.color_make(0x33, 0x33, 0x33), lv.PART.MAIN) arc[3].set_range(0, maxMillionSecond) arc[3].set_size(55, 55) arc[3].set_rotation(90) arc[3].set_bg_angles(0, 360) arc[3].remove_style(None, lv.PART.KNOB) arc[3].set_value(0) arc[3].set_style_arc_width(2, lv.PART.INDICATOR) arc[3].set_style_arc_width(2, lv.PART.MAIN) arc[3].set_grid_cell(lv.GRID_ALIGN.CENTER, 3, 1, lv.GRID_ALIGN.CENTER, 0, 1) arc[3].clear_flag(lv.obj.FLAG.CLICKABLE) totalTime = lv.label(funcContainer) totalTime.set_text(str(timeCount[3])) totalTime.set_style_text_font(lv.font_montserrat_18, 0) totalTime.set_style_text_color(lv.color_white(), 0) totalTime.set_grid_cell(lv.GRID_ALIGN.CENTER, 3, 1, lv.GRID_ALIGN.CENTER, 0, 1) totalTime.add_flag(lv.obj.FLAG.CLICKABLE) totalTime.add_event_cb(lambda e: arc_event_handler(e, 3), lv.EVENT.CLICKED, None) totalTime.set_ext_click_area(30) 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) timer_alive = True
def load_smart_panel(): global isFirst global main_alive global needAnimation import lvgl as lv print("load_smart_panel, first: ", isFirst) # init scr scr = lv.obj() scr.set_style_bg_color(lv.color_black(), 0) # init grid layout col_dsc = [96, 96, 96, lv.GRID_TEMPLATE.LAST] row_dsc = [107, 107, lv.GRID_TEMPLATE.LAST] gridLayout = lv.obj(scr) gridLayout.set_style_bg_opa(0, 0) gridLayout.set_style_border_opa(0, 0) gridLayout.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN, lv.GRID_ALIGN.SPACE_BETWEEN) gridLayout.set_style_grid_column_dsc_array(col_dsc, 0) gridLayout.set_style_grid_row_dsc_array(row_dsc, 0) gridLayout.set_size(scr.get_width(), scr.get_height()) gridLayout.set_style_pad_left(10, 0) gridLayout.set_style_pad_right(10, 0) gridLayout.set_style_pad_top(9, 0) gridLayout.set_style_pad_bottom(9, 0) gridLayout.set_layout(lv.LAYOUT_GRID.value) for i in range(6): col = i % 3 row = i // 3 element = lv.obj(gridLayout) element.set_style_border_opa(0, 0) element.set_flex_flow(lv.FLEX_FLOW.COLUMN) element.set_flex_align(lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER) element.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) element.clear_flag(lv.obj.FLAG.SCROLLABLE) element.set_style_bg_color(lv.color_make(0xf, 0xf, 0xf), 0) element.set_style_radius(0, 0) element.set_grid_cell(lv.GRID_ALIGN.STRETCH, col, 1, lv.GRID_ALIGN.STRETCH, row, 1) element.add_event_cb(element_pressed_cb, lv.EVENT.PRESSED, None) element.add_event_cb(element_released_cb, lv.EVENT.RELEASED, None) if (titles[i] == "Environment"): element.add_event_cb(lambda e: element_click_cb(e, "Environment"), lv.EVENT.CLICKED, None) elif (titles[i] == "Hvac"): element.add_event_cb(lambda e: element_click_cb(e, "Hvac"), lv.EVENT.CLICKED, None) elif (titles[i] == "Music"): element.add_event_cb(lambda e: element_click_cb(e, "Music"), lv.EVENT.CLICKED, None) elif (titles[i] == "Timer"): element.add_event_cb(lambda e: element_click_cb(e, "Timer"), lv.EVENT.CLICKED, None) elif (titles[i] == "Compass"): element.add_event_cb(lambda e: element_click_cb(e, "Compass"), lv.EVENT.CLICKED, None) else: element.add_event_cb(lambda e: element_click_cb(e, "Sound"), lv.EVENT.CLICKED, None) img = lv.img(element) img.set_src(images[i]) label = lv.label(element) label.set_text(titles[i]) label.set_style_text_color(lv.color_make(0xcc, 0xcc, 0xcc), 0) label.set_style_text_font(lv.font_montserrat_12, 0) if (isFirst): lv.scr_load(scr) isFirst = False else: if (needAnimation): lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.MOVE_RIGHT, 500, 0, True) else: lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.NONE, 0, 0, True) main_alive = True
def createPage(self): global currentFunc global currentSelected global hvac_alive print("Enter Hvac") # 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_radius(0, 0) win.set_style_bg_color(lv.color_black(), 0) win.clear_flag(lv.obj.FLAG.SCROLLABLE) # --------- value container --------- col_dsc = [60, 65, 40, 60, lv.GRID_TEMPLATE.LAST] row_dsc = [48, lv.GRID_TEMPLATE.LAST] valueLayout = lv.obj(win) valueLayout.set_layout(lv.LAYOUT_GRID.value) valueLayout.set_style_bg_opa(0, 0) valueLayout.set_style_border_opa(0, 0) valueLayout.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT) valueLayout.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN, lv.GRID_ALIGN.SPACE_BETWEEN) valueLayout.set_style_grid_column_dsc_array(col_dsc, 0) valueLayout.set_style_grid_row_dsc_array(row_dsc, 0) valueLayout.set_style_pad_top(20, 0) valueLayout.set_style_align(lv.ALIGN.TOP_MID, 0) # ----------- - -------------- subImage = lv.img(valueLayout) subImage.set_src(RESOURCES_ROOT + "images/subtraction.png") subImage.set_grid_cell(lv.GRID_ALIGN.START, 0, 1, lv.GRID_ALIGN.CENTER, 0, 1) subImage.add_flag(lv.obj.FLAG.CLICKABLE) subImage.add_event_cb(lambda e: sub_pressed_cb(e, self), lv.EVENT.PRESSED, None) # subImage.add_event_cb(lambda e: hvac_back_press_callback(e, subImage), lv.EVENT.PRESSED, None) # subImage.add_event_cb(lambda e: hvac_back_release_callback(e, subImage), lv.EVENT.RELEASED, None) subImage.set_ext_click_area(40) # ----------- value ----------- self.label = lv.label(valueLayout) self.label.set_text(str(self.value)) self.label.set_style_text_color(lv.color_white(), 0) self.label.set_style_text_font(lv.font_montserrat_48, 0) self.label.set_grid_cell(lv.GRID_ALIGN.CENTER, 1, 1, lv.GRID_ALIGN.CENTER, 0, 1) # ----------- ºC ------------ centigradeImage = lv.img(valueLayout) centigradeImage.set_src(RESOURCES_ROOT + "images/centigrade_s.png") centigradeImage.set_style_pad_bottom(8, 0) centigradeImage.set_grid_cell(lv.GRID_ALIGN.START, 2, 1, lv.GRID_ALIGN.END, 0, 1) # ----------- + ---------------- addImage = lv.img(valueLayout) addImage.set_src(RESOURCES_ROOT + "images/addition.png") addImage.set_grid_cell(lv.GRID_ALIGN.CENTER, 3, 1, lv.GRID_ALIGN.CENTER, 0, 1) addImage.add_flag(lv.obj.FLAG.CLICKABLE) addImage.add_event_cb(lambda e: add_pressed_cb(e, self), lv.EVENT.PRESSED, None) # addImage.add_event_cb(lambda e: hvac_back_press_callback(e, addImage), lv.EVENT.PRESSED, None) # addImage.add_event_cb(lambda e: hvac_back_release_callback(e, addImage), lv.EVENT.RELEASED, None) addImage.set_ext_click_area(40) # ----------- tips ---------- tips = lv.label(win) tips.set_text("Temperature") tips.set_style_text_color(lv.color_make(0xCC, 0xCC, 0xCC), 0) tips.set_style_pad_bottom(20, 0) tips.set_align(lv.ALIGN.CENTER) # ----------- function ---------- func_col_dsc = [70, 70, 70, 70, lv.GRID_TEMPLATE.LAST] func_row_dsc = [40, lv.GRID_TEMPLATE.LAST] funcContainer = lv.obj(win) funcContainer.set_style_bg_opa(0, 0) funcContainer.set_style_border_opa(0, 0) funcContainer.set_grid_dsc_array(func_col_dsc, func_row_dsc) funcContainer.set_width(300) funcContainer.set_height(90) funcContainer.set_layout(lv.LAYOUT_GRID.value) funcContainer.set_align(lv.ALIGN.BOTTOM_MID) funcContainer.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN, lv.GRID_ALIGN.SPACE_BETWEEN) image = lv.img(funcContainer) image.set_src(functionImage[0]) image.add_flag(lv.obj.FLAG.CLICKABLE) image.set_ext_click_area(20) image.add_event_cb(lambda e: func_pressed_cb(e, 0), lv.EVENT.PRESSED, None) image.set_grid_cell(lv.GRID_ALIGN.CENTER, 0, 1, lv.GRID_ALIGN.CENTER, 0, 1) currentSelected = image currentSelected.set_src(functionImageSelected[0]) image1 = lv.img(funcContainer) image1.set_src(functionImage[1]) image1.add_flag(lv.obj.FLAG.CLICKABLE) image1.set_ext_click_area(20) image1.add_event_cb(lambda e: func_pressed_cb(e, 1), lv.EVENT.PRESSED, None) image1.set_grid_cell(lv.GRID_ALIGN.CENTER, 1, 1, lv.GRID_ALIGN.CENTER, 0, 1) image2 = lv.img(funcContainer) image2.set_src(functionImage[2]) image2.add_flag(lv.obj.FLAG.CLICKABLE) image2.set_ext_click_area(20) image2.add_event_cb(lambda e: func_pressed_cb(e, 2), lv.EVENT.PRESSED, None) image2.set_grid_cell(lv.GRID_ALIGN.CENTER, 2, 1, lv.GRID_ALIGN.CENTER, 0, 1) image3 = lv.img(funcContainer) image3.set_src(functionImage[3]) image3.add_flag(lv.obj.FLAG.CLICKABLE) image3.set_ext_click_area(20) image3.add_event_cb(lambda e: func_pressed_cb(e, 3), lv.EVENT.PRESSED, None) image3.set_grid_cell(lv.GRID_ALIGN.CENTER, 3, 1, lv.GRID_ALIGN.CENTER, 0, 1) # for i in range(4): # image = lv.img(funcContainer) # image.set_src(functionImage[i]) # image.add_flag(lv.obj.FLAG.CLICKABLE) # image.set_ext_click_area(20) # image.add_event_cb(lambda e: func_pressed_cb(e, i), lv.EVENT.PRESSED, None) # image.set_grid_cell(lv.GRID_ALIGN.CENTER, i, 1, lv.GRID_ALIGN.CENTER, 0, 1) # if (currentFunc == i): # currentSelected = image # currentSelected.set_src(functionImageSelected[i]) 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: hvac_back_click_callback(e, win), lv.EVENT.CLICKED, None) backImg.add_event_cb(lambda e: hvac_back_press_callback(e, backImg), lv.EVENT.PRESSED, None) backImg.add_event_cb(lambda e: hvac_back_release_callback(e, backImg), lv.EVENT.RELEASED, None) backImg.set_ext_click_area(20) 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) hvac_alive = True
def createPage(self): global anim global playedTime global durationTime global slider global audio_src global player global image global music_alive global currentMusic global albumCover global songTitle global albumTitle global totalTime global anim_timeline global scr print("Enter Music") # 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_radius(0, 0) win.set_style_bg_color(lv.color_black(), 0) win.clear_flag(lv.obj.FLAG.SCROLLABLE) 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: music_back_click_callback(e, win), lv.EVENT.CLICKED, None) backImg.add_event_cb(lambda e: music_back_press_callback(e, backImg), lv.EVENT.PRESSED, None) backImg.add_event_cb(lambda e: music_back_release_callback(e, backImg), lv.EVENT.RELEASED, None) backImg.set_ext_click_area(30) albumCover = lv.img(win) albumCover.set_style_pad_left(12, 0) albumCover.set_style_pad_top(10, 0) songTitle = lv.label(win) songTitle.set_style_text_font(lv.font_montserrat_20, 0) songTitle.set_style_text_color(lv.color_white(), 0) songTitle.align_to(albumCover, lv.ALIGN.TOP_LEFT, 130, 3) albumTitle = lv.label(win) albumTitle.set_style_text_font(lv.font_montserrat_16, 0) albumTitle.set_style_text_color(lv.color_make(0xCC, 0xCC, 0xCC), 0) albumTitle.align_to(songTitle, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 12) props = [lv.STYLE.BG_COLOR, 0] transition_dsc = lv.style_transition_dsc_t() transition_dsc.init(props, lv.anim_t.path_linear, 300, 0, None) style_main = lv.style_t() style_indicator = lv.style_t() style_pressed_color = lv.style_t() style_main.init() style_main.set_bg_opa(lv.OPA.COVER) style_main.set_bg_color(lv.color_make(0x66, 0x66, 0x66)) style_main.set_radius(lv.RADIUS.CIRCLE) style_main.set_line_dash_width(1) style_indicator.init() style_indicator.set_bg_opa(lv.OPA.COVER) style_indicator.set_bg_color(lv.color_white()) style_indicator.set_radius(lv.RADIUS.CIRCLE) style_indicator.set_transition(transition_dsc) style_pressed_color.init() style_pressed_color.set_bg_color(lv.color_white()) # Create a slider and add the style slider = lv.slider(win) slider.remove_style_all() # Remove the styles coming from the theme slider.add_style(style_main, lv.PART.MAIN) slider.add_style(style_indicator, lv.PART.INDICATOR) slider.add_style(style_pressed_color, lv.PART.INDICATOR | lv.STATE.PRESSED) slider.align_to(albumTitle, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 25) slider.set_size(140, 1) anim = lv.anim_t() anim.init() anim.set_var(slider) playedTime = lv.label(win) setLabelValue(playedTime, 0) playedTime.set_style_text_font(lv.font_montserrat_16, 0) playedTime.set_style_text_color(lv.color_white(), 0) playedTime.align_to(slider, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 15) totalTime = lv.label(win) totalTime.set_style_text_font(lv.font_montserrat_16, 0) totalTime.set_style_text_color(lv.color_white(), 0) totalTime.align_to(slider, lv.ALIGN.OUT_BOTTOM_RIGHT, 0, 15) func_col_dsc = [80, 80, 80, 80, lv.GRID_TEMPLATE.LAST] func_row_dsc = [40, lv.GRID_TEMPLATE.LAST] funcContainer = lv.obj(win) funcContainer.set_style_bg_opa(0x00, 0) funcContainer.set_style_border_opa(0x00, 0) funcContainer.set_layout(lv.LAYOUT_GRID.value) funcContainer.set_grid_dsc_array(func_col_dsc, func_row_dsc) funcContainer.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN, lv.GRID_ALIGN.SPACE_BETWEEN) funcContainer.set_align(lv.ALIGN.BOTTOM_MID) funcContainer.set_size(320, 70) for i in range(4): image[i] = lv.img(funcContainer) image[i].set_src(functionImage[i]) image[i].add_flag(lv.obj.FLAG.CLICKABLE) image[i].set_ext_click_area(20) image[i].set_grid_cell(lv.GRID_ALIGN.CENTER, i, 1, lv.GRID_ALIGN.CENTER, 0, 1) if (i == 0): image[i].add_event_cb(lambda e: controller_click_cb(e, "prev"), lv.EVENT.CLICKED, None) elif (i == 1): image[i].add_event_cb(lambda e: controller_click_cb(e, "play"), lv.EVENT.CLICKED, None) elif (i == 2): image[i].add_event_cb(lambda e: controller_click_cb(e, "next"), lv.EVENT.CLICKED, None) elif (i == 3): image[i].add_event_cb(lambda e: controller_click_cb(e, "fav"), lv.EVENT.CLICKED, None) anim.set_custom_exec_cb(lambda a1, val: setSpentTime(slider, val)) reset_music() 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) music_alive = True