def __init__(self, parent): scr_style = lv.style_t() scr_style.set_bg_color(lv.STATE.DEFAULT, lv_colors.BLACK) parent.add_style(lv.obj.PART.MAIN, scr_style) label1_style = lv.style_t() label1_style.set_text_font(lv.STATE.DEFAULT, lv.font_montserrat_48) self.label1 = lv.label(parent, None) self.label1.set_long_mode(lv.label.LONG.BREAK) # Break the long lines self.label1.set_recolor( True) # Enable re-coloring by commands in the text self.label1.set_align(lv.label.ALIGN.LEFT) # Center aligned lines self.label1.set_text("#00ff00 11:35:00#") self.label1.set_width(240) self.label1.align(None, lv.ALIGN.CENTER, 30, -30) self.label1.add_style(lv.label.PART.MAIN, label1_style) self.label2 = lv.label(parent, None) self.label2.align(self.label1, lv.ALIGN.OUT_BOTTOM_LEFT, 40, 20) self.label2.set_recolor(True) self.label2.set_text("#ffffff Mon 30.11.2020#") self.task = lv.task_create_basic() self.task.set_cb(lambda task: self.updateClock(task)) self.task.set_period(1000) self.task.set_prio(lv.TASK_PRIO.LOWEST)
def main_page(self, tile_num): self.aclock_tile = self.mainbar.get_tile_obj(tile_num) self.aclock_style = lv.style_t() self.aclock_style.copy(self.mainbar.get_style()) self.CANVAS_HEIGHT = lv.scr_act().get_disp().driver.ver_res self.CANVAS_WIDTH = self.CANVAS_HEIGHT cbuf = bytearray(self.CANVAS_HEIGHT * self.CANVAS_HEIGHT * 4) self.canvas = lv.canvas(self.aclock_tile, None) self.canvas.set_buffer(cbuf, self.CANVAS_HEIGHT, self.CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) self.canvas.align(self.aclock_tile, lv.ALIGN.CENTER, 0, 0) circle_dsc = lv.draw_line_dsc_t() circle_dsc.init() circle_dsc.color = lv_colors.GREEN self.radius = 90 xo = self.CANVAS_WIDTH // 2 yo = self.CANVAS_HEIGHT // 2 - 20 self.canvas.draw_arc(xo, yo, self.radius, 0, 360, circle_dsc) vor = xo + 1j * yo vtstart = 0.9 * self.radius + 0j # start of tick vtick = 0.1 * self.radius + 0j # tick vrot = cmath.exp(2j * cmath.pi / 12) # unit rotation for _ in range(12): polar(self.canvas, vor + conj(vtstart), vtick, 1, lv_colors.GREEN) vtick *= vrot vtstart *= vrot vtick = 0.05 * self.radius + 0j # tick vrot = cmath.exp(2j * cmath.pi / 60) # unit rotation for _ in range(60): polar(self.canvas, vor + conj(vtstart), vtick, 1, lv_colors.GREEN) vtick *= vrot vtstart *= vrot self.hrs_radius = self.radius - 32 self.min_radius = self.radius - 12 self.sec_radius = self.radius - 12 self.task = lv.task_create_basic() self.task.set_cb(lambda task: self.updateClock(self.task)) self.task.set_period(100) self.task.set_prio(lv.TASK_PRIO.LOWEST) exit_btn = lv.imgbtn(self.aclock_tile, None) exit_btn.set_src(lv.btn.STATE.RELEASED, self.mainbar.get_exit_btn_dsc()) exit_btn.add_style(lv.imgbtn.PART.MAIN, self.aclock_style) exit_btn.align(self.aclock_tile, lv.ALIGN.IN_BOTTOM_LEFT, 10, -10) self.log.debug("setting up exit callback") exit_btn.set_event_cb(self.exit_aclock_app_event_cb) self.aclock_style.set_text_opa(lv.obj.PART.MAIN, lv.OPA.COVER)
def start_stopwatch_event_cb(self,obj,evt): if evt == lv.EVENT.CLICKED: self.log.debug("start_stopwatch_event_cb called") self.start_button.set_hidden(True) self.stop_button.set_hidden(False) # create a task that runs every second self.is_running=True self.start_time = time.time() self.secs = self.start_time self.hundred_ms = 0 self.stopwatch_app_task = lv.task_create_basic() self.stopwatch_app_task.set_cb(lambda task: self.update(self.stopwatch_app_task)) self.stopwatch_app_task.set_period(100) self.stopwatch_app_task.set_prio(lv.TASK_PRIO.LOWEST)
def __init__(self,parent): self.CANVAS_HEIGHT = lv.scr_act().get_disp().driver.ver_res self.CANVAS_WIDTH = self.CANVAS_HEIGHT cbuf=bytearray(self.CANVAS_HEIGHT * self.CANVAS_HEIGHT * 4) self.canvas = lv.canvas(parent,None) self.canvas.set_buffer(cbuf,self.CANVAS_HEIGHT,self.CANVAS_HEIGHT,lv.img.CF.TRUE_COLOR) self.canvas.align(None,lv.ALIGN.CENTER,0,0) circle_dsc = lv.draw_line_dsc_t() circle_dsc.init() circle_dsc.color = lv_colors.GREEN self.radius = 90 xo=self.CANVAS_WIDTH//2 yo=self.CANVAS_HEIGHT//2-20 self.canvas.draw_arc(xo,yo,self.radius,0,360,circle_dsc) vor = xo + 1j * yo vtstart = 0.9 * self.radius + 0j # start of tick vtick = 0.1 * self.radius + 0j # tick vrot = cmath.exp(2j * cmath.pi/12) # unit rotation for _ in range(12): polar(self.canvas, vor + conj(vtstart), vtick, 1, lv_colors.GREEN) vtick *= vrot vtstart *= vrot vtick = 0.05 * self.radius + 0j # tick vrot = cmath.exp(2j * cmath.pi/60) # unit rotation for _ in range(60): polar(self.canvas, vor + conj(vtstart), vtick, 1, lv_colors.GREEN) vtick *= vrot vtstart *= vrot self.hrs_radius = self.radius-32 self.min_radius = self.radius -12 self.sec_radius = self.radius -12 self.task = lv.task_create_basic() self.task.set_cb(lambda task: self.updateClock(self.task)) self.task.set_period(100) self.task.set_prio(lv.TASK_PRIO.LOWEST)
def visuals_create(parent): page = lv.page.__cast__(parent) lv.page.set_scrl_layout(page, lv.LAYOUT.PRETTY_TOP) disp_size = display.get_size_category() grid_h_chart = lv.page.get_height_grid(page, 1, 1) if disp_size <= lv.DISP_SIZE.LARGE: grid_w_chart = lv.page.get_width_grid(page, 1, 1) else: grid_w_chart = lv.page.get_width_grid(page, 1, 2) chart = lv.chart(parent, None) chart.add_style(lv.chart.PART.BG, style_box) if disp_size <= lv.DISP_SIZE.SMALL: chart.set_style_local_text_font(lv.chart.PART.SERIES_BG, lv.STATE.DEFAULT, lv.theme_get_font_small()) chart.set_drag_parent(True) chart.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Line chart") chart.set_width_margin(grid_w_chart) chart.set_height_margin(grid_h_chart) chart.set_div_line_count(3, 0) chart.set_point_count(8) chart.set_type(lv.chart.TYPE.LINE) if disp_size > lv.DISP_SIZE.SMALL: chart.set_style_local_pad_left(lv.chart.PART.BG, lv.STATE.DEFAULT, 4 * (LV_DPI // 10)) chart.set_style_local_pad_bottom(lv.chart.PART.BG, lv.STATE.DEFAULT, 3 * (LV_DPI // 10)) chart.set_style_local_pad_right(lv.chart.PART.BG, lv.STATE.DEFAULT, 2 * (LV_DPI // 10)) chart.set_style_local_pad_top(lv.chart.PART.BG, lv.STATE.DEFAULT, 2 * (LV_DPI // 10)) chart.set_y_tick_length(0, 0) chart.set_x_tick_length(0, 0) chart.set_y_tick_texts("600\n500\n400\n300\n200", 0, lv.chart.AXIS.DRAW_LAST_TICK) chart.set_x_tick_texts("Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug", 0, lv.chart.AXIS.DRAW_LAST_TICK) s1 = chart.add_series(LV_THEME_DEFAULT_COLOR_PRIMARY) s2 = chart.add_series(LV_THEME_DEFAULT_COLOR_SECONDARY) chart.set_next(s1, 10) chart.set_next(s1, 90) chart.set_next(s1, 30) chart.set_next(s1, 60) chart.set_next(s1, 10) chart.set_next(s1, 90) chart.set_next(s1, 30) chart.set_next(s1, 60) chart.set_next(s1, 10) chart.set_next(s1, 90) chart.set_next(s2, 32) chart.set_next(s2, 66) chart.set_next(s2, 5) chart.set_next(s2, 47) chart.set_next(s2, 32) chart.set_next(s2, 32) chart.set_next(s2, 66) chart.set_next(s2, 5) chart.set_next(s2, 47) chart.set_next(s2, 66) chart.set_next(s2, 5) chart.set_next(s2, 47) chart2 = lv.chart(parent, chart) chart2.set_type(lv.chart.TYPE.COLUMN) chart2.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Column chart") s1 = chart2.add_series(LV_THEME_DEFAULT_COLOR_PRIMARY) s2 = chart2.add_series(LV_THEME_DEFAULT_COLOR_SECONDARY) chart2.set_next(s1, 10) chart2.set_next(s1, 90) chart2.set_next(s1, 30) chart2.set_next(s1, 60) chart2.set_next(s1, 10) chart2.set_next(s1, 90) chart2.set_next(s1, 30) chart2.set_next(s1, 60) chart2.set_next(s1, 10) chart2.set_next(s1, 90) chart2.set_next(s2, 32) chart2.set_next(s2, 66) chart2.set_next(s2, 5) chart2.set_next(s2, 47) chart2.set_next(s2, 32) chart2.set_next(s2, 32) chart2.set_next(s2, 66) chart2.set_next(s2, 5) chart2.set_next(s2, 47) chart2.set_next(s2, 66) chart2.set_next(s2, 5) chart2.set_next(s2, 47) if disp_size <= lv.DISP_SIZE.SMALL: grid_w_meter = lv.page.get_width_grid(page, 1, 1) elif disp_size <= lv.DISP_SIZE.MEDIUM: grid_w_meter = lv.page.get_width_grid(page, 2, 1) else: grid_w_meter = lv.page.get_width_grid(page, 3, 1) meter_h = lv.page.get_height_fit(page) if grid_w_meter < meter_h: meter_size = grid_w_meter else: meter_size = meter_h lmeter = lv.linemeter(parent, None) lmeter.set_drag_parent(True) lmeter.set_value(50) lmeter.set_size(meter_size, meter_size) lmeter.add_style(lv.linemeter.PART.MAIN, style_box) lmeter.set_style_local_value_str(lv.linemeter.PART.MAIN, lv.STATE.DEFAULT, "Line meter") label = lv.label(lmeter, None) label.align(lmeter, lv.ALIGN.CENTER, 0, 0) label.set_style_local_text_font(lv.label.PART.MAIN, lv.STATE.DEFAULT, lv.theme_get_font_title()) a_lm = lv.anim_t() a_lm.init() a_lm.set_custom_exec_cb(lambda a, val: linemeter_anim(a, lmeter, val)) a_lm.set_values(0, 100) a_lm.set_time(4000) a_lm.set_playback_time(1000) a_lm.set_repeat_count(LV_ANIM_REPEAT_INFINITE) lv.anim_t.start(a_lm) gauge = lv.gauge(parent, None) gauge.set_drag_parent(True) gauge.set_size(meter_size, meter_size) gauge.add_style(lv.gauge.PART.MAIN, style_box) gauge.set_style_local_value_str(lv.gauge.PART.MAIN, lv.STATE.DEFAULT, "Gauge") label = lv.label(gauge, label) label.align(gauge, lv.ALIGN.CENTER, 0, grid_w_meter // 3) a_ga = lv.anim_t() a_ga.init() a_ga.set_custom_exec_cb(lambda a, val: linemeter_anim(a, lmeter, val)) a_ga.set_values(0, 100) a_ga.set_time(4000) a_ga.set_playback_time(1000) a_ga.set_repeat_count(LV_ANIM_REPEAT_INFINITE) a_ga.set_custom_exec_cb(lambda a, val: gauge_anim(a, gauge, val)) lv.anim_t.start(a_ga) arc = lv.arc(parent, None) arc.set_drag_parent(True) arc.set_bg_angles(0, 360) arc.set_rotation(270) arc.set_angles(0, 0) arc.set_size(meter_size, meter_size) arc.add_style(lv.arc.PART.BG, style_box) arc.set_style_local_value_str(lv.arc.PART.BG, lv.STATE.DEFAULT, "Arc") label = lv.label(arc) label.align(arc, lv.ALIGN.CENTER, 0, 0) a_arc = lv.anim_t() a_arc.init() a_arc.set_custom_exec_cb(lambda a_arc, val: anim_phase1(a_arc, arc, val)) a_arc.set_values(0, 360) a_arc.set_ready_cb(lambda a: arc_phase1_ready_cb(a, arc)) # a_arc.set_repeat_count(LV_ANIM_REPEAT_INFINITE) a_arc.set_time(1000) lv.anim_t.start(a_arc) # Create a bar and use the backgrounds value style property to display the current value bar_h = lv.cont(parent, None) bar_h.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT) bar_h.add_style(lv.cont.PART.MAIN, style_box) bar_h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Bar") if disp_size <= lv.DISP_SIZE.SMALL: bar_h.set_width(lv.page_get_width_grid(page, 1, 1)) elif disp_size <= lv.DISP_SIZE.MEDIUM: bar_h.set_width(lv.page.get_width_grid(page, 2, 1)) else: bar_h.set_width(lv.page.get_width_grid(parent, 3, 2)) bar = lv.bar(bar_h, None) bar.set_width(lv.cont.get_width_fit(bar_h)) bar.set_style_local_value_font(lv.bar.PART.BG, lv.STATE.DEFAULT, lv.theme_get_font_small()) bar.set_style_local_value_align(lv.bar.PART.BG, lv.STATE.DEFAULT, lv.ALIGN.OUT_BOTTOM_MID) bar.set_style_local_value_ofs_y(lv.bar.PART.BG, lv.STATE.DEFAULT, LV_DPI // 20) bar.set_style_local_margin_bottom(lv.bar.PART.BG, lv.STATE.DEFAULT, LV_DPI // 7) bar.align(None, lv.ALIGN.CENTER, 0, 0) bar.set_value(30, lv.ANIM.OFF) led_h = lv.cont(parent, None) led_h.set_layout(lv.LAYOUT.PRETTY_MID) if disp_size <= lv.DISP_SIZE.SMALL: led_h.set_width(lv.page.get_width_grid(page, 1, 1)) elif disp_size <= lv.DISP_SIZE.MEDIUM: led_h.set_width(lv.page.get_width_grid(page, 2, 1)) else: led_h.set_width(lv.page.get_width_grid(page, 3, 1)) led_h.set_height(lv.obj.get_height(lv.obj.__cast__(bar_h))) led_h.add_style(lv.cont.PART.MAIN, style_box) led_h.set_drag_parent(True) led_h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "LEDs") led = lv.led(led_h, None) led_size = lv.obj.get_height_fit(lv.obj.__cast__(led_h)) led.set_size(led_size, led_size) led.off() led = lv.led(led_h, led) led.set_bright((LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN) // 2 + LV_LED_BRIGHT_MIN) led = lv.led(led_h, led) led.on() if disp_size == lv.DISP_SIZE.MEDIUM: led_h.add_protect(lv.PROTECT.POS) led_h.align( bar_h, lv.ALIGN.OUT_BOTTOM_MID, 0, lv.obj.get_style_margin_top(lv.obj.__cast__(led_h), lv.obj.PART.MAIN) + lv.obj.get_style_pad_inner(parent, lv.page.PART.SCROLLABLE)) task = lv.task_create_basic() task.set_cb(lambda task: bar_anim(task, bar)) task.set_period(100) task.set_prio(lv.TASK_PRIO.LOWEST)
def __init__(self, mainbar): self.log = logging.getLogger("main_tile") self.log.setLevel(logging.DEBUG) self.log.debug("Creating main tile") self.mainbar = mainbar main_tile_no = mainbar.add_tile(0, 0, "main tile") main_tile = mainbar.get_tile_obj(main_tile_no) style = mainbar.get_style() self.clock_cont = lv.obj(main_tile, None) self.clock_cont.set_size(lv.scr_act().get_disp().driver.hor_res, lv.scr_act().get_disp().driver.ver_res // 2) self.clock_cont.add_style(lv.obj.PART.MAIN, style) self.clock_cont.align(main_tile, lv.ALIGN.IN_TOP_MID, 0, 0) clocklabel_style = lv.style_t() clocklabel_style.set_text_font(lv.STATE.DEFAULT, lv.font_montserrat_48) self.clocklabel = lv.label(self.clock_cont, None) self.clocklabel.set_long_mode( lv.label.LONG.BREAK) # Break the long lines self.clocklabel.set_recolor( True) # Enable re-coloring by commands in the text self.clocklabel.set_align(lv.label.ALIGN.LEFT) # Center aligned lines self.clocklabel.set_text("#00ff00 11:35:00#") self.clocklabel.set_width(240) self.clocklabel.align(None, lv.ALIGN.OUT_TOP_MID, 30, 50) self.clocklabel.add_style(lv.label.PART.MAIN, clocklabel_style) self.datelabel = lv.label(self.clock_cont, None) self.datelabel.align(self.clocklabel, lv.ALIGN.OUT_BOTTOM_LEFT, 40, 20) self.datelabel.set_recolor(True) self.datelabel.set_text("#ffffff Mon 30.11.2020#") self.task = lv.task_create_basic() self.task.set_cb(lambda task: self.updateClock(task)) self.task.set_period(1000) self.task.set_prio(lv.TASK_PRIO.MID) mainbar.main_tile = self # # init widgets # for i in range(MAX_WIDGET_NUM): self.widget_table[i] = Icon() self.widget_table[i].active = False self.widget_table[i].cont = mainbar.obj_create(main_tile) self.widget_table[i].cont.add_style(lv.obj.PART.MAIN, style) self.widget_table[i].cont.set_size(Constants.WIDGET_X_SIZE, Constants.WIDGET_Y_SIZE + 20) # create app label self.widget_table[i].label = lv.label(self.widget_table[i].cont, None) mainbar.add_slide_element(self.widget_table[i].label) self.widget_table[i].label.add_style(lv.obj.PART.MAIN, style) self.widget_table[i].label.set_size(Constants.WIDGET_X_SIZE, Constants.WIDGET_LABEL_Y_SIZE) self.widget_table[i].label.set_align(lv.label.ALIGN.CENTER) self.widget_table[i].label.align(self.widget_table[i].cont, lv.ALIGN.IN_BOTTOM_LEFT, 0, -20) # create app label self.widget_table[i].ext_label = lv.label( self.widget_table[i].cont, None) mainbar.add_slide_element(self.widget_table[i].ext_label) self.widget_table[i].ext_label.add_style(lv.obj.PART.MAIN, style) self.widget_table[i].ext_label.set_size( Constants.WIDGET_X_SIZE, Constants.WIDGET_LABEL_Y_SIZE) self.widget_table[i].ext_label.set_align(lv.label.ALIGN.CENTER) self.widget_table[i].ext_label.align(self.widget_table[i].label, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) # create img and indicator self.widget_table[i].button_img = lv.imgbtn( self.widget_table[i].cont, None) # self.widget_table[i].indicator = lv.img(self.widget_table[i].cont, None) # hide all self.widget_table[i].cont.set_hidden(True) self.widget_table[i].button_img.set_hidden(True) # self.widget_table[i].indicator.set_hidden(True) self.widget_table[i].label.set_hidden(True) self.widget_table[i].ext_label.set_hidden(True)
import display_driver import time def arc_loader(task, arc): angle = arc.get_value() # print("angle: ",angle) angle += 5 if angle > 360: task._del() else: arc.set_value(angle) # create an arc which acts as a loader arc = lv.arc(lv.scr_act(), None) arc.set_range(0, 360) arc.set_bg_angles(0, 360) arc.set_angles(0, 360) arc.set_rotation(270) arc.align(None, lv.ALIGN.CENTER, 0, 0) arc.set_value(10) # Create an `lv_task` to update the arc. task = lv.task_create_basic() task.set_cb(lambda task: arc_loader(task, arc)) task.set_period(20) task.set_prio(lv.TASK_PRIO.LOWEST)