def interface(): def event_handler(source, evt): if evt == lv.EVENT.VALUE_CHANGED: date = lv.calendar.get_pressed_date(source) if date: print("Clicked date: %02d.%02d.%02d" % (date.day, date.month, date.year)) # Create a screen and load it scr = lv.obj() lv.scr_load(scr) # create a calendar calendar = lv.calendar(lv.scr_act(), None) calendar.set_size(235, 235) calendar.align(None, lv.ALIGN.CENTER, 0, 0) calendar.set_event_cb(event_handler) # Make the date number smaller to be sure they fit into their area calendar.set_style_local_text_font(lv.calendar.PART.DATE, lv.STATE.DEFAULT, lv.theme_get_font_small()) today = lv.calendar_date_t() date = cetTime() today.year = date[0] today.month = date[1] today.day = date[2] calendar.set_today_date(today) calendar.set_showed_date(today) watch.tft.backlight_fade(100)
def show_recovery_phrase_warning(self): self.screen = lv.obj() self.recovery_phrase_header_label = lv.label(self.screen) self.recovery_phrase_header_label.set_text( "WRITE DOWN YOUR\nRECOVERY PHRASE!") self.recovery_phrase_header_label.align(self.screen, lv.ALIGN.CENTER, 0, -300) self.recovery_phrase_instruction_label = lv.label(self.screen) self.recovery_phrase_instruction_label.set_text( "If you lose your wallet,\nyou can recover it on any\n computer " "ONLY with BOTH:\n\n1)Your recovery phrase\n2)Your password") self.recovery_phrase_instruction_label.align(self.screen, lv.ALIGN.CENTER, 0, -85) self.show_recovery_phrase_button = lv.btn(self.screen) self.show_recovery_phrase_button.set_size(400, 100) self.show_recovery_phrase_button.align(self.screen, lv.ALIGN.CENTER, 0, 150) self.show_recovery_phrase_button.set_event_cb( self.handle_show_recovery_phrase_button) self.show_recovery_phrase_button_label = lv.label( self.show_recovery_phrase_button) self.show_recovery_phrase_button_label.set_text("Show recovery phrase") lv.scr_load(self.screen)
def __init__(self): # Create a container with grid col_dsc = [LV_GRID_FR(1), 200, LV_GRID_FR(1), lv.GRID_TEMPLATE.LAST] row_dsc = [30, 10, 10, LV_GRID_FR(1), lv.GRID_TEMPLATE.LAST] self.p1 = 0 self.p2 = 0 self.cont = lv.obj(lv.scr_act()) self.cont.set_style_pad_all(2, lv.PART.MAIN) self.cont.set_style_pad_column(10, lv.PART.MAIN) self.cont.set_style_pad_row(10, lv.PART.MAIN) self.cont.set_grid_dsc_array(col_dsc, row_dsc) self.cont.set_size(320, 240) self.cont.center() self.page_obj_init(self.cont) self.a = lv.anim_t() self.a.init() self.a.set_var(self.anim_obj) end = self.cont.get_style_width( lv.PART.MAIN) - self.anim_obj.get_style_width(lv.PART.MAIN) - 10 self.a.set_values(5, end) self.a.set_time(2000) self.a.set_custom_exec_cb( lambda a, val: self.anim_x_cb(self.anim_obj, val)) self.a.set_path_cb(self.anim_path_bezier3_cb) self.refer_chart_cubic_bezier()
def popup_confirm_stop(self): modal_style = lv.style_t() lv.style_copy(modal_style, lv.style_plain_color) modal_style.body.main_color = modal_style.body.grad_color = lv.color_make( 0, 0, 0) modal_style.body.opa = lv.OPA._50 bg = lv.obj(self.main_scr) bg.set_style(modal_style) bg.set_pos(0, 0) bg.set_size(self.main_scr.get_width(), self.main_scr.get_height()) bg.set_opa_scale_enable(True) popup_stop = lv.mbox(bg) popup_stop.set_text( 'Do you really want to stop the soldering process?') btns = ['OK', 'Cancel', ''] popup_stop.add_btns(btns) this = self def event_handler(obj, event): if event == lv.EVENT.VALUE_CHANGED: if popup_stop.get_active_btn() == 0: this.set_reflow_process_on(False) else: pass bg.del_async() popup_stop.start_auto_close(5) popup_stop.set_event_cb(event_handler) popup_stop.align(None, lv.ALIGN.CENTER, 0, 0)
def __init__(self): # init LVGL lv.init() # TFT and TS driver # POTENTIAL: move into LaserMcu self._tft = tftwing.TFTFeatherWing(tft_mhz=24) self._tft.init() # Register display buffer, driver and input device driver self._register_disp_drv() self._register_indev_drv() th = lv.theme_night_init(210, lv.font_roboto_16) lv.theme_set_current(th) blank_scr = lv.obj() lv.scr_load(blank_scr) # MCU Control self.mcu = laser_mcu.LaserMCU() # Laser Measuring Control self.laser = laser_ctrl.LaserCtrl() self.laser.off() # Load Time # TODO: also move into LaserMcu try: self.mcu.set_time_ntp() except OSError as err: print("OSError: {0}".format(err)) self.mcu.load_time() self.mcu.set_creation_time() # Create screen self._load_screen() # Register Tasks self._register_tasks() # Create lock for panel wait process self._lock = _thread.allocate_lock() return
def show_phrase_length_selection(self): self.screen = lv.obj() self.recovery_phrase_length_screen_label = lv.label(self.screen) self.recovery_phrase_length_screen_label.set_text( "How many words are in\n your recovery phrase?") self.recovery_phrase_length_screen_label.align(self.screen, lv.ALIGN.CENTER, 0, -300) self.recovery_phrase_length_roller = lv.roller(self.screen) recovery_phrase_length_options_str = "\n".join( str(phrase_length) for phrase_length in self.RECOVERY_PHRASE_LENGTHS) self.recovery_phrase_length_roller.set_options( recovery_phrase_length_options_str, 0) self.recovery_phrase_length_roller.set_fix_width(True) self.recovery_phrase_length_roller.set_selected(2, 0) self.recovery_phrase_length_roller.set_size(200, 200) self.recovery_phrase_length_roller.align(self.screen, lv.ALIGN.CENTER, 0, -75) self.recovery_phrase_length_roller.set_visible_row_count(5) self.confirm_phrase_length_button = lv.btn(self.screen) self.confirm_phrase_length_button.set_size(125, 60) self.confirm_phrase_length_button.align(self.screen, lv.ALIGN.CENTER, 0, 100) self.confirm_phrase_length_button.set_event_cb( self.handle_confirm_phrase_length_button) self.confirm_phrase_length_button_label = lv.label( self.confirm_phrase_length_button) self.confirm_phrase_length_button_label.set_text("Ok") lv.scr_load(self.screen)
def __init__(self, profiles_obj, config_dict): self.profiles = profiles_obj self.config = config_dict self.alloy_list = self.profiles.get_profile_alloy_names() self.has_started = False self.main_scr = lv.obj() self.oven_title = self.oven_title_init() self.chart, self.chart_series = self.chart_init() self.profile_title_label, self.profile_title_cont, self.profile_title_text = self.profile_title_init( ) self.timer_label, self.timer_cont, self.timer_text = self.timer_init() self.profile_alloy_selector = self.profile_selector_init() self.start_btn, self.start_label = self.start_btn_init() self.stage_cont, self.stage_label = self.stage_init() self.cali_btn = self.cali_btn_init() self.temp_text = self.temp_init() self.led = self.led_init() self.line = None self.dashed_line = None self.null_chart_point_list = None self.profile_detail_init() self.profile_alloy_selector.move_foreground() self.show_cali_btn_hide_stage() self.reflow_process_start_cb = None self.reflow_process_stop_cb = None lv.scr_load(self.main_scr)
def btn_event_cb(btn, evt): if evt == lv.EVENT.CLICKED: # Create a full-screen background #Create a base object for the modal background obj = lv.obj(lv.scr_act(), None) obj.reset_style_list(lv.obj.PART.MAIN) obj.add_style(lv.obj.PART.MAIN, style_modal) obj.set_pos(0, 0) obj.set_size(LV_HOR_RES, LV_VER_RES) #obj.set_style_local_bg_opa(lv.obj.PART.MAIN, lv.STATE.DEFAULT, lv.OPA._80) btns2 = ["Ok", "Cancel", ""] # Create the message box as a child of the modal background mbox = lv.msgbox(obj, None) mbox.add_btns(btns2) mbox.set_text("Hello world!") mbox.align(None, lv.ALIGN.CENTER, 0, 0) mbox.set_event_cb(mbox_event_cb) # Fade the message box in with an animation a = lv.anim_t() a.init() a.set_var(obj) a.set_time(500) a.set_values(lv.OPA.TRANSP, lv.OPA._70) a.set_custom_exec_cb(lambda a, val: opa_anim(mbox, val)) lv.anim_t.start(a) info.set_text(in_msg_info) info.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 5, -5)
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 m2(): print("This is callback for M2") scr = lv.obj() lv.scr_load(scr) #make container con = lv.cont(scr) con.set_auto_realign(True) con.set_layout(lv.LAYOUT.CENTER) con.align(scr, lv.ALIGN.CENTER, 0, 0) con.set_fit(lv.FIT.TIGHT) #make label in container label = lv.label(con) label.set_text(""" This is the second screen""") ta = lv.textarea(con) kb = lv.keyboard(con) #kb.set_style_local_radius(0,0,0) kb.set_textarea(ta) btn = lv.btn(con) label = lv.label(btn) label.set_text("Skip la") btn.set_event_cb(lambda obj, event: m4() if event == lv.EVENT.CLICKED else None)
def create_density_controls(self, style): self.controls = lv.obj(self) self.controls.set_style(lv.style_transp_tight) self.controls.set_size(480, BTNSIZE) self.controls.set_y(740) plus = lv.btn(self.controls) lbl = lv.label(plus) lbl.set_text(lv.SYMBOL.PLUS) plus.set_size(BTNSIZE, BTNSIZE) plus.align(self.controls, lv.ALIGN.CENTER, 144, 0) plus.set_event_cb(self.on_plus) minus = lv.btn(self.controls) lbl = lv.label(minus) lbl.set_text(lv.SYMBOL.MINUS) minus.set_size(BTNSIZE, BTNSIZE) minus.align(self.controls, lv.ALIGN.CENTER, -144, 0) minus.set_event_cb(self.on_minus) lbl = lv.label(self.controls) lbl.set_text("QR code density") lbl.set_style(0, style) lbl.set_align(lv.label.ALIGN.CENTER) lbl.align(self.controls, lv.ALIGN.CENTER, 0, 0) self.controls.set_hidden(True)
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 __init__(self, name, display, buttons, th=MATERIAL_THEME, debug=False, roll_over=False, border=False, kill=False, **kwargs): gc.collect() self.disp = display self.buttons = buttons self.theme = th # lv.theme_set_current(self.theme) self.scr = lv.obj() self.name = name self.game = g.Game(SCR_X, SCR_Y, debugger=debug) self.sprites = {} self.roll_over = roll_over self.border = border self.kill = kill self.set_buttons( kwargs.get("btn_left", lambda x: print("undefined left")), kwargs.get("btn_right", lambda x: print("undefined right")), kwargs.get("btn_up", lambda x: print("undefined up")), kwargs.get("btn_down", lambda x: print("undefined down")), kwargs.get("btn_a", lambda x: print("undefined a")), kwargs.get("btn_b", lambda x: print("undefined b")), kwargs.get("btn_x", lambda x: print("undefined x")), kwargs.get("btn_y", lambda x: print("undefined y")), ) gc.collect()
def __init__(self, profiles_obj, config_dict, pid_obj, sensor_obj): self.profiles = profiles_obj self.config = config_dict self.pid = pid_obj self.sensor = sensor_obj self.pid_params = self.config.get('pid') self.temp_offset = self.config.get('sensor_offset') self.alloy_list = self.profiles.get_profile_alloy_names() self.has_started = False self.main_scr = lv.obj() self.oven_title = self.oven_title_init() self.chart, self.chart_series = self.chart_init() self.profile_title_label, self.profile_title_cont, self.profile_title_text = self.profile_title_init( ) self.timer_label, self.timer_cont, self.timer_text = self.timer_init() self.profile_alloy_selector = self.profile_selector_init() self.start_btn, self.start_label = self.start_btn_init() self.stage_cont, self.stage_label = self.stage_init() self.settings_btn = self.settings_btn_init() self.temp_text = self.temp_init() self.led = self.led_init() self.line = None self.dashed_line = None self.point_count = None self.chart_point_list = None self.profile_detail_init() self.profile_alloy_selector.move_foreground() self.show_set_btn_hide_stage() self.reflow_process_start_cb = None self.reflow_process_stop_cb = None self.current_input_placeholder = 'Set Kp' lv.scr_load(self.main_scr)
def create_scr2(self): scr2 = lv.obj() btn2 = lv.btn(scr2) btn2.align(scr2, lv.ALIGN.CENTER, 0, 0) label2 = lv.label(btn2) label2.set_text("Button 2") label2.set_size(20,20) return scr2
def create_scr1(self): scr1 = lv.obj() btn1 = lv.btn(scr1) btn1.align(scr1, lv.ALIGN.CENTER, 0, 0) label1 = lv.label(btn1) label1.set_text("Button 1") label1.set_size(20,20) return scr1
def show_rejected_tx(self, message): self.screen = lv.obj() self.rejected_tx_label = lv.label( self.screen) self.rejected_tx_label.set_text(message) self.rejected_tx_label.align( self.screen, lv.ALIGN.CENTER, 0, -200) lv.scr_load(self.screen)
def show_password_input(self): self.screen = lv.obj() self.wallet_paddword_screen_label = lv.label(self.screen) self.wallet_paddword_screen_label.set_text( " Enter your recovery\nphrase password (if any)") self.wallet_paddword_screen_label.align(self.screen, lv.ALIGN.CENTER, 0, -350) self.password_input = lv.ta(self.screen) self.password_input.set_one_line(True) self.password_input.set_text("") self.password_input.align(self.screen, lv.ALIGN.CENTER, 0, -275) self.password_back_button = lv.btn(self.screen) self.password_back_button.set_size(125, 60) self.password_back_button_label = lv.label(self.password_back_button) self.password_back_button_label.set_text("Back") self.password_back_button.align(self.screen, lv.ALIGN.CENTER, -100, -150) self.password_back_button.set_event_cb( self.handle_password_back_button) self.password_finish_button = lv.btn(self.screen) self.password_finish_button.set_size(150, 60) self.password_finish_button_label = lv.label( self.password_finish_button) self.password_finish_button_label.set_text("Finish") self.password_finish_button.align(self.screen, lv.ALIGN.CENTER, 100, -150) self.password_finish_button.set_event_cb( self.handle_password_finish_button) self.toggle_keyboard_button = lv.btn(self.screen) self.toggle_keyboard_button.set_size(230, 100) self.toggle_keyboard_button_label = lv.label( self.toggle_keyboard_button) self.toggle_keyboard_button_label.set_text( self.UPPER_CASE_KEYBOARD_SYMBOL) self.toggle_keyboard_button.align(self.screen, lv.ALIGN.CENTER, -118, 50) self.toggle_keyboard_button.set_event_cb( self.handle_toggle_password_keyboard_button) self.backspace_button = lv.btn(self.screen) self.backspace_button.set_size(230, 100) self.backspace_button_label = lv.label(self.backspace_button) self.backspace_button_label.set_text("Bksp") self.backspace_button.align(self.screen, lv.ALIGN.CENTER, 118, 50) self.backspace_button.set_event_cb( self.handle_password_backspace_button) self.keyboard = lv.kb(self.screen) self.keyboard.set_height(300) self.keyboard.align(self.screen, lv.ALIGN.IN_BOTTOM_MID, 0, 0) self.keyboard.set_map(self.PASSWORD_KEYBOARD_MAP_LOWER_CASE) self.keyboard.set_ta(self.password_input) lv.scr_load(self.screen)
def __init__(self, points, calibrate, touch_count=5): self.points = points self.calibrate = calibrate self.touch_count = touch_count self.med = [lv.point_t() for i in range(0, self.touch_count) ] # Storage point to calculate median self.cur_point = 0 self.cur_touch = 0 self.scr = lv.obj(None) self.scr.set_size(TP_MAX_VALUE, TP_MAX_VALUE) lv.scr_load(self.scr) # Create a big transparent button screen to receive clicks style_transp = lv.style_t() style_transp.init() style_transp.set_bg_opa(lv.OPA.TRANSP) self.big_btn = lv.btn(lv.scr_act()) self.big_btn.set_size(TP_MAX_VALUE, TP_MAX_VALUE) self.big_btn.add_style(style_transp, lv.PART.MAIN) self.big_btn.add_style(style_transp, lv.PART.MAIN) #self.big_btn.set_layout(lv.LAYOUT.OFF) self.big_btn.add_event_cb( lambda event, self=self: self.calibrate_clicked(), lv.EVENT.CLICKED, None) # Create the screen, circle and label self.label_main = lv.label(lv.scr_act()) style_circ = lv.style_t() style_circ.init() style_circ.set_radius(LV_RADIUS_CIRCLE) self.circ_area = lv.obj(lv.scr_act()) self.circ_area.set_size(CIRCLE_SIZE, CIRCLE_SIZE) self.circ_area.add_style(style_circ, lv.STATE.DEFAULT) self.circ_area.clear_flag( lv.obj.FLAG.CLICKABLE) # self.circ_area.set_click(False) self.show_circle()
def init(blocking=True): display.init(not blocking) # Initialize the styles init_styles() scr = lv.obj() lv.scr_load(scr) update()
def _load_screen(self): # Create screen obj self.scr = lv.obj() # Add header and body self.hdr = GuiHeader(self.scr, 0, 0, self.mcu.get_creation_time_str()) self.body = GuiLaserMain(self.scr, 0, self.hdr.get_height(), self) # Load screen lv.scr_load(self.scr) return
def show_recovery_succeeded(self): self.screen = lv.obj() self.recovery_succeeded_label = lv.label(self.screen) self.recovery_succeeded_label.set_text( "Wallet successfully\n recovered") self.recovery_succeeded_label.align(self.screen, lv.ALIGN.CENTER, 0, -200) lv.scr_load(self.screen)
def show_set_password(self): self.screen = lv.obj() self.create_password_screen_label = lv.label(self.screen) self.create_password_screen_label.set_text("Set a password (optional)") self.create_password_screen_label.align(self.screen, lv.ALIGN.CENTER, 0, -360) self.password_input = lv.ta(self.screen) self.password_input.set_one_line(True) self.password_input.set_text("") self.password_input.align(self.screen, lv.ALIGN.CENTER, 0, -285) self.submit_password_button = lv.btn(self.screen) self.submit_password_button.set_size(125, 60) self.submit_password_button.align(self.screen, lv.ALIGN.CENTER, 0, -220) self.submit_password_button.set_event_cb( self.handle_submit_password_button) self.submit_password_button_label = lv.label( self.submit_password_button) self.submit_password_button_label.set_text("Set") self.password_tips_label = lv.label(self.screen) self.password_tips_label.set_text( "-Avoid common passwords\n" "-Use at least 11 characters\n" "-Use letters, numbers and\nspecial characters") self.password_tips_label.align(self.screen, lv.ALIGN.CENTER, 0, -90) self.toggle_keyboard_button = lv.btn(self.screen) self.toggle_keyboard_button.set_size(230, 100) self.toggle_keyboard_button_label = lv.label( self.toggle_keyboard_button) self.toggle_keyboard_button_label.set_text( self.UPPER_CASE_KEYBOARD_SYMBOL) self.toggle_keyboard_button.align(self.screen, lv.ALIGN.CENTER, -118, 50) self.toggle_keyboard_button.set_event_cb( self.handle_toggle_password_keyboard_button) self.backspace_button = lv.btn(self.screen) self.backspace_button.set_size(230, 100) self.backspace_button_label = lv.label(self.backspace_button) self.backspace_button_label.set_text("Bksp") self.backspace_button.align(self.screen, lv.ALIGN.CENTER, 118, 50) self.backspace_button.set_event_cb( self.handle_password_backspace_button) self.keyboard = lv.kb(self.screen) self.keyboard.set_height(300) self.keyboard.align(self.screen, lv.ALIGN.IN_BOTTOM_MID, 0, 0) self.keyboard.set_map(self.PASSWORD_KEYBOARD_MAP_LOWER_CASE) self.keyboard.set_ta(self.password_input) lv.scr_load(self.screen)
def setup_page(self,tile_num): example_setup_tile = self.mainbar.get_tile_obj(tile_num) setup_style = lv.style_t() setup_style.copy(self.mainbar.get_style()) setup_style.set_bg_color(lv.obj.PART.MAIN, lv_colors.GRAY) setup_style.set_bg_opa(lv.obj.PART.MAIN, lv.OPA.COVER) setup_style.set_border_width(lv.obj.PART.MAIN, 0) example_setup_tile.add_style(lv.obj.PART.MAIN, setup_style) exit_cont = lv.obj(example_setup_tile,None) exit_cont.set_size(lv.scr_act().get_disp().driver.hor_res,40) exit_cont.add_style(lv.obj.PART.MAIN, setup_style) exit_btn = lv.imgbtn(example_setup_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(exit_cont,lv.ALIGN.IN_TOP_LEFT, 10, 0) exit_btn.set_event_cb(self.exit_example_app_setup_event_cb) exit_label = lv.label(exit_cont,None) exit_label.add_style(lv.obj.PART.MAIN, setup_style) exit_label.set_text("my app setup") exit_label.align(exit_btn, lv.ALIGN.OUT_RIGHT_MID, 5, 0 ) foobar_switch_cont = lv.obj(example_setup_tile,None) foobar_switch_cont.set_size(lv.scr_act().get_disp().driver.hor_res,40) foobar_switch_cont.add_style(lv.obj.PART.MAIN, setup_style) foobar_switch_cont.align(exit_cont,lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0 ) foobar_switch = lv.switch(foobar_switch_cont,None) foobar_switch.add_protect(lv.PROTECT.CLICK_FOCUS) foobar_switch.add_style(lv.switch.PART.INDIC, setup_style) foobar_switch.off(lv.ANIM.ON) foobar_switch.align(foobar_switch_cont,lv.ALIGN.IN_RIGHT_MID, -5, 0 ) self.log.debug("setting up the foobar switch callback") foobar_switch.set_event_cb(self.example_app_foobar_switch_event_cb) foobar_switch_label = lv.label(foobar_switch_cont,None) foobar_switch_label.add_style(lv.obj.PART.MAIN, setup_style) foobar_switch_label.set_text("foo bar") foobar_switch_label.align(foobar_switch_cont,lv.ALIGN.IN_LEFT_MID, 5, 0 )
def __init__(self): def event_handler1(obj, event): lv.scr_load(scr1) def event_handler2(obj, event): lv.scr_load(scr2) def event_handler3(obj, event): lv.scr_load(scr) # Create a list scr = lv.obj() list1 = lv.list(scr) list1.set_size(160, 200) list1.align(None, lv.ALIGN.CENTER, 0, 0) # Add buttons to the list list_btn = list1.add_btn(lv.SYMBOL.BLUETOOTH, "BT") list_btn.set_event_cb(event_handler1) list_btn = list1.add_btn(lv.SYMBOL.WIFI, "WF") list_btn.set_event_cb(event_handler2) lv.scr_load(scr) scr1 = lv.obj() list1 = lv.list(scr1) list1.set_size(160, 200) list1.align(None, lv.ALIGN.CENTER, 0, 0) # Add buttons to the list list_btn = list1.add_btn(lv.SYMBOL.BLUETOOTH, "111") list_btn.set_event_cb(event_handler3) list_btn = list1.add_btn(lv.SYMBOL.WIFI, "222") scr2 = lv.obj() list1 = lv.list(scr2) list1.set_size(160, 200) list1.align(None, lv.ALIGN.CENTER, 0, 0) # Add buttons to the list list_btn = list1.add_btn(lv.SYMBOL.BLUETOOTH, "3333") list_btn.set_event_cb(event_handler3) list_btn = list1.add_btn(lv.SYMBOL.WIFI, "4444")
def interface(): def update_task(task): set_usb_voltage(power.getVbusVoltage()) set_usb_pwr(power.getVbusCurrent()) if power.isBatteryConnect(): set_batt_voltage(power.getBattVoltage()) if power.isChargeing(): set_batt_pwr("Charging", power.getBattChargeCurrent()) batt_percent.set_hidden(True) else: set_batt_pwr("Discharging", power.getBattDischargeCurrent()) set_batt_per(power.getBattPercentage()) batt_percent.set_hidden(False) def event_cb(obj, event): if event == lv.EVENT.VALUE_CHANGED: tft.set_backlight_level(obj.get_value()) def set_usb_pwr(pwr): usb_pwr.set_text("USB current: {} mA".format(pwr)) def set_usb_voltage(volts): usb_voltage.set_text("USB voltage: {} mV".format(volts)) def set_batt_voltage(volts): batt_voltage.set_text("Battery voltage: {} mV".format(volts)) def set_batt_pwr(mode, pwr): batt_pwr.set_text("{} battery \ncurrent: {} mA".format(mode, pwr)) def set_batt_per(per): batt_percent.set_text("Battery percent: {}%".format(per)) scr = lv.obj() tabview = lv.tabview(scr) vbus_tab = tabview.add_tab("USB") usb_voltage = lv.label(vbus_tab) usb_pwr = lv.label(vbus_tab) usb_pwr.set_y(usb_voltage.get_y() + 20) la = lv.switch(vbus_tab) batt_tab = tabview.add_tab("Battery") batt_voltage = lv.label(batt_tab) batt_pwr = lv.label(batt_tab) batt_pwr.set_y(batt_voltage.get_y() + 20) batt_percent = lv.label(batt_tab) batt_percent.set_y(batt_pwr.get_y() + 40) brightness_slider = lv.slider(batt_tab) brightness_slider.align(None, lv.ALIGN.IN_BOTTOM_MID, 0, 0) brightness_slider.set_range(0, 100) brightness_slider.set_value(100, 1) brightness_slider.set_event_cb(event_cb) update_task(None) lv.scr_load(scr) watch.tft.backlight_fade(100) lv.task_create(update_task, 1000, 5, None)
def popup_calibration(self): modal_style = lv.style_t() lv.style_copy(modal_style, lv.style_plain_color) modal_style.body.main_color = modal_style.body.grad_color = lv.color_make( 0, 0, 0) modal_style.body.opa = lv.OPA._50 bg = lv.obj(self.main_scr) bg.set_style(modal_style) bg.set_pos(0, 0) bg.set_size(self.main_scr.get_width(), self.main_scr.get_height()) bg.set_opa_scale_enable(True) popup_cali = lv.mbox(bg) popup_cali.set_text('What would you like to calibrate?') btns = ['Temp Sensor', '\n', 'Touch Screen', '\n', 'Cancel', ''] popup_cali.add_btns(btns) lv.cont.set_fit(popup_cali, lv.FIT.NONE) mbox_style = popup_cali.get_style(popup_cali.STYLE.BTN_REL) popup_cali_style = lv.style_t() lv.style_copy(popup_cali_style, mbox_style) popup_cali_style.body.padding.bottom = 96 popup_cali.set_style(popup_cali.STYLE.BTN_REL, popup_cali_style) popup_cali.set_height(186) this = self def event_handler(obj, event): if event == lv.EVENT.VALUE_CHANGED: active_btn_text = popup_cali.get_active_btn_text() tim = machine.Timer(-1) if active_btn_text == 'Temp Sensor': this.config['has_calibrated'] = False with open('config.json', 'w') as f: ujson.dump(this.config, f) tim.init(period=500, mode=machine.Timer.ONE_SHOT, callback=lambda t: machine.reset()) elif active_btn_text == 'Touch Screen': uos.remove(this.config.get('touch_cali_file')) tim.init(period=500, mode=machine.Timer.ONE_SHOT, callback=lambda t: machine.reset()) else: tim.deinit() bg.del_async() popup_cali.start_auto_close(5) popup_cali.set_event_cb(event_handler) popup_cali.align(None, lv.ALIGN.CENTER, 0, 0) self.popup_cali = popup_cali return self.popup_cali
async def show_environmental_screen(self): # # Environmental screen using a table # # # lv.table.STYLE.CELL1 = normal cell # lv.table.STYLE.CELL2 = header cell # lv.table.STYLE.CELL3 = ? # lv.table.STYLE.CELL4 = ? environmental_screen = lv.obj() # set background color, with no gradient screenstyle = lv.style_t(lv.style_plain) #screenstyle.body.main_color = lv.color_make(0xFF, 0xA5, 0x00) # 0xFF, 0x00, 0x00 Red # 0xC0, 0xC0, 0xC0 Silver # 0xFF, 0xA5, 0x00 Orange #screenstyle.body.grad_color = lv.color_make(0xFF, 0xA5, 0x00) #screenstyle.body.border.color = lv.color_hex(0xe32a19) #screenstyle.body.border.width = 5 environmental_screen.set_style(screenstyle) tablestyle = lv.style_t(lv.style_plain) tablestyle.body.border.width = 0 tablestyle.body.opa = 0 cellstyle = lv.style_t(lv.style_plain) cellstyle.text.color = lv.color_hex(0xa028d4) cellstyle.text.font = lv.font_roboto_28 cellstyle.body.padding.top = 1 cellstyle.body.padding.bottom = 1 cellstyle.body.border.width = 0 cellstyle.body.opa = 0 mtable = lv.table(environmental_screen) mtable.set_row_cnt(2) mtable.set_col_cnt(3) mtable.set_col_width(0, 130) mtable.set_col_width(1, 90) mtable.set_col_width(2, 90) mtable.set_style(lv.table.STYLE.BG, tablestyle) mtable.set_style(lv.table.STYLE.CELL1, cellstyle) mtable.set_cell_value(0,0, "Temp") mtable.set_cell_value(1,0, "Humidity") mtable.set_cell_value(0,1, '{:.1f}'.format(repo.get('tdegc').current)) mtable.set_cell_value(1,1, '{:.1f}'.format(repo.get('rh').current)) mtable.set_cell_value(0,2, "degC") mtable.set_cell_value(1,2, "%") lv.scr_load(environmental_screen) self.backlight_ctrl.value(1)
async def show_voltage_monitor_screen(self): # # Measurement screen using a table # # # lv.table.STYLE.CELL1 = normal cell # lv.table.STYLE.CELL2 = header cell # lv.table.STYLE.CELL3 = ? # lv.table.STYLE.CELL4 = ? voltage_screen = lv.obj() # set background color, with no gradient screenstyle = lv.style_t(lv.style_plain) #screenstyle.body.main_color = lv.color_make(0xFF, 0xA5, 0x00) # 0xFF, 0x00, 0x00 Red # 0xC0, 0xC0, 0xC0 Silver # 0xFF, 0xA5, 0x00 Orange #screenstyle.body.grad_color = lv.color_make(0xFF, 0xA5, 0x00) #screenstyle.body.border.color = lv.color_hex(0xe32a19) #screenstyle.body.border.width = 5 voltage_screen.set_style(screenstyle) tablestyle = lv.style_t(lv.style_plain) tablestyle.body.border.width = 0 tablestyle.body.opa = 0 cellstyle = lv.style_t(lv.style_plain) cellstyle.text.color = lv.color_hex(0xa028d4) cellstyle.text.font = lv.font_roboto_28 cellstyle.body.padding.top = 1 cellstyle.body.padding.bottom = 1 cellstyle.body.border.width = 0 cellstyle.body.opa = 0 mtable = lv.table(voltage_screen) mtable.set_row_cnt(2) mtable.set_col_cnt(3) mtable.set_col_width(0, 110) mtable.set_col_width(1, 100) mtable.set_col_width(2, 100) mtable.set_style(lv.table.STYLE.BG, tablestyle) mtable.set_style(lv.table.STYLE.CELL1, cellstyle) mtable.set_cell_value(0,0, "Vbat") mtable.set_cell_value(1,0, "Vusb") mtable.set_cell_value(0,2, "V") mtable.set_cell_value(1,2, "V") mtable.set_cell_value(0,1, '{:.2f}'.format(repo.get('vbat').current)) mtable.set_cell_value(1,1, '{:.2f}'.format(repo.get('vusb').current)) lv.scr_load(voltage_screen) self.backlight_ctrl.value(1)
def page_obj_init(self, par): self.anim_obj = lv.obj(par) self.anim_obj.set_size(30, 30) self.anim_obj.set_align(lv.ALIGN.TOP_LEFT) self.anim_obj.clear_flag(lv.obj.FLAG.SCROLLABLE) self.anim_obj.set_style_bg_color(lv.palette_main(lv.PALETTE.RED), lv.PART.MAIN) self.anim_obj.set_grid_cell(lv.GRID_ALIGN.START, 0, 1, lv.GRID_ALIGN.START, 0, 1) self.p1_label = lv.label(par) self.p2_label = lv.label(par) self.p1_label.set_text("p1:0") self.p2_label.set_text("p2:0") self.p1_label.set_grid_cell(lv.GRID_ALIGN.START, 0, 1, lv.GRID_ALIGN.START, 1, 1) self.p2_label.set_grid_cell(lv.GRID_ALIGN.START, 0, 1, lv.GRID_ALIGN.START, 2, 1) self.p1_slider = lv.slider(par) self.p2_slider = lv.slider(par) self.p1_slider.set_range(0, 1024) self.p2_slider.set_range(0, 1024) self.p1_slider.set_style_pad_all(2, lv.PART.KNOB) self.p2_slider.set_style_pad_all(2, lv.PART.KNOB) self.p1_slider.add_event_cb(self.slider_event_cb, lv.EVENT.VALUE_CHANGED, None) self.p2_slider.add_event_cb(self.slider_event_cb, lv.EVENT.VALUE_CHANGED, None) self.p1_slider.set_grid_cell(lv.GRID_ALIGN.STRETCH, 1, 1, lv.GRID_ALIGN.START, 1, 1) self.p2_slider.set_grid_cell(lv.GRID_ALIGN.STRETCH, 1, 1, lv.GRID_ALIGN.START, 2, 1) self.run_btn = lv.btn(par) self.run_btn.add_event_cb(self.run_btn_event_handler, lv.EVENT.CLICKED, None) btn_label = lv.label(self.run_btn) btn_label.set_text(lv.SYMBOL.PLAY) btn_label.center() self.run_btn.set_grid_cell(lv.GRID_ALIGN.STRETCH, 2, 1, lv.GRID_ALIGN.STRETCH, 1, 2) self.chart = lv.chart(par) self.chart.set_style_pad_all(0, lv.PART.MAIN) self.chart.set_style_size(0, lv.PART.INDICATOR) self.chart.set_type(lv.chart.TYPE.SCATTER) self.ser1 = self.chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y) self.chart.set_range(lv.chart.AXIS.PRIMARY_Y, 0, 1024) self.chart.set_range(lv.chart.AXIS.PRIMARY_X, 0, 1024) self.chart.set_point_count(CHART_POINTS_NUM) self.chart.set_grid_cell(lv.GRID_ALIGN.STRETCH, 0, 3, lv.GRID_ALIGN.STRETCH, 3, 1)