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 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 show_phrase_input(self): self.phrase_input_length = 0 self.screen = lv.obj() self.recovery_phrase_length_screen_label = lv.label(self.screen) self.recovery_phrase_length_screen_label.set_text( "Recovery phrase word {page_number}/{recovery_phrase_target_length}" .format(page_number=len(self.recovery_phrase) + 1, recovery_phrase_target_length=self. recovery_phrase_target_length)) self.recovery_phrase_length_screen_label.align(self.screen, lv.ALIGN.CENTER, 0, -350) self.recovery_phrase_input = lv.ta(self.screen) self.recovery_phrase_input.set_one_line(True) self.recovery_phrase_input.set_text("") self.recovery_phrase_input.set_max_length(16) self.recovery_phrase_input.align(self.screen, lv.ALIGN.CENTER, 0, -275) self.recovery_phrase_input.set_event_cb( self.handle_recovery_phrase_input_change) # need to keep track of this for the autocomplete self.autocompleted = False self.phrase_input_length = 0 self.prev_recovery_phrase_word_button = lv.btn(self.screen) self.prev_recovery_phrase_word_button.set_size(125, 60) self.prev_recovery_phrase_word_button_label = lv.label( self.prev_recovery_phrase_word_button) self.prev_recovery_phrase_word_button_label.set_text("Back") self.prev_recovery_phrase_word_button.align(self.screen, lv.ALIGN.CENTER, -100, -150) self.prev_recovery_phrase_word_button.set_event_cb( self.handle_previous_recovery_phrase_word_button) self.next_recovery_phrase_word_button = lv.btn(self.screen) self.next_recovery_phrase_word_button.set_size(125, 60) self.next_recovery_phrase_word_button_label = lv.label( self.next_recovery_phrase_word_button) self.next_recovery_phrase_word_button_label.set_text("Next") self.next_recovery_phrase_word_button.align(self.screen, lv.ALIGN.CENTER, 100, -150) self.next_recovery_phrase_word_button.set_state(BUTTON_DISABLED_STATE) self.next_recovery_phrase_word_button.set_event_cb( self.handle_next_recovery_phrase_word_button) self.keyboard = lv.kb(self.screen) self.keyboard.set_map(self.RECOVERY_PHRASE_KEYBOARD_MAP) self.keyboard.set_ta(self.recovery_phrase_input) lv.scr_load(self.screen)
# ********************************** # Create styles for the keyboard rel_style = lv.style_t() pr_style = lv.style_t() lv.style_copy(rel_style, lv.style_btn_rel) rel_style.body.radius = 0 rel_style.body.border.width = 1 lv.style_copy(pr_style, lv.style_btn_pr) pr_style.body.radius = 0 pr_style.body.border.width = 1 # Create a keyboard and apply the styles kb = lv.kb(lv.scr_act()) kb.set_cursor_manage(True) kb.set_style(lv.kb.STYLE.BG, lv.style_transp_tight) kb.set_style(lv.kb.STYLE.BTN_REL, rel_style) kb.set_style(lv.kb.STYLE.BTN_PR, pr_style) # Create a text area. The keyboard will write here ta = lv.ta(lv.scr_act()) ta.align(None, lv.ALIGN.IN_TOP_MID, 0, 10) ta.set_text("") # Assign the text area to the keyboard kb.set_ta(ta) # ********************************** # End your codes here.
btn2.set_event_cb(btn2_event_cb) # Create styles for the keyboard rel_style = lv.style_t() pr_style = lv.style_t() lv.style_copy(rel_style, lv.style_btn_rel) rel_style.body.radius = 0 rel_style.body.border.width = 1 lv.style_copy(pr_style, lv.style_btn_pr) pr_style.body.radius = 0 pr_style.body.border.width = 1 # Create a keyboard and apply the styles kb = lv.kb(scr1) kb.set_cursor_manage(True) # Create a text area. The keyboard will write here ta = lv.ta(scr1) ta.set_width(450) ta.set_height(70) ta.align(kb, lv.ALIGN.OUT_TOP_MID, 0, -10) ta.set_text("") # Assign the text area to the keyboard kb.set_ta(ta) # Create a style for the Preloader style = lv.style_t() lv.style_copy(style, lv.style_plain)
def __init__(self, parent, x_pos, y_pos, gui_ctrl): super().__init__(parent) self._gui_ctrl = gui_ctrl btn_style = self.get_style(lv.tabview.STYLE.BTN_REL) btn_style_or = lv.style_t() lv.style_copy(btn_style_or, btn_style) btn_style.body.padding.left = (parent.get_width() - x_pos) // 5 // 2 btn_style.body.padding.right = (parent.get_width() - x_pos) // 5 // 2 self.set_style(lv.tabview.STYLE.BTN_REL, btn_style) self.set_size(parent.get_width() - x_pos, parent.get_height() - y_pos) self.set_pos(x_pos, y_pos) self.set_anim_time(0) self.set_sliding(False) self.set_btns_pos(lv.tabview.BTNS_POS.LEFT) self.set_event_cb(self._tab_change_handler) self._t_start = self.add_tab("New Session") self._t_cal = self.add_tab("Calibration") self._t_other = self.add_tab("Other") self._t_done = self.add_tab("Done") self.set_tab_act(3, lv.ANIM.OFF) # Session screen # Stat new session self._new_sess = lv.cont(self._t_start) self._new_sess.set_fit(lv.FIT.FLOOD) self._new_sess.set_layout(lv.LAYOUT.PRETTY) self._new_session_label = RealignLabel( self._new_sess, "Set info, and start a new measuring session!", False) self._material_sel = lv.roller(self._new_sess) self._material_sel.set_options( "\n".join(material for material in MATERIAL_TYPE), lv.roller.MODE.INIFINITE) self._thickness_sel = lv.roller(self._new_sess) self._thickness_sel.set_options( "\n".join(thickness for thickness in THICKNESS_TYPE), lv.roller.MODE.INIFINITE) self._start_btn = TextBtn(self._new_sess, "Start", self._new_sess_cb) self._start_btn.set_style(lv.btn.STYLE.REL, btn_style_or) # Measuring Screen self._session = lv.cont(self._t_start) self._session.set_fit(lv.FIT.FLOOD) self._session.set_layout(lv.LAYOUT.PRETTY) self._session_label = RealignLabel(self._session, "\n\n\n", True) self._start_measure_btn = TextBtn(self._session, "New Panel", self._start_measure_cb) self._start_measure_btn.set_style(lv.btn.STYLE.REL, btn_style_or) self._done_measure_btn = TextBtn(self._session, "Finish", self._done_measure_cb) self._done_measure_btn.set_style(lv.btn.STYLE.REL, btn_style_or) self._re_measure_btn = TextBtn(self._session, "Re-measure", self._re_measure_cb) self._re_measure_btn.set_style(lv.btn.STYLE.REL, btn_style_or) self._chart = lv.chart(self._session) self._chart.set_height(90) self._chart.set_point_count(700) self._chart.set_range(11000, 13000) self._ser1 = self._chart.add_series(lv.color_hex(0x0000b3)) self._ser2 = self._chart.add_series(lv.color_hex(0xe60000)) self._ser3 = self._chart.add_series(lv.color_hex(0x00e600)) self._ser4 = self._chart.add_series(lv.color_hex(0xffffff)) self._session.set_hidden(True) lv.page.glue_obj(self._new_sess, True) lv.page.glue_obj(self._session, True) self._preload_cont = lv.cont(self._t_start) self._preload_cont.set_fit(lv.FIT.FLOOD) self._preload_cont.set_layout(lv.LAYOUT.CENTER) self._preload = lv.preload(self._preload_cont) self._preload_cont.set_hidden(True) # Calibration Screen self._cal_label = RealignLabel(self._t_cal, "Output: \n", False) self._cal_num_input = NumTextArea(self._t_cal, self.ta_test) self._cal_num_input.set_auto_realign(True) self._cal_num_input.align(self._cal_label, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) self._set_cal_1 = TextBtn(self._t_cal, "Set Amp 1", self._set_amp_1_cb) self._set_cal_1.set_style(lv.btn.STYLE.REL, btn_style_or) self._set_cal_1.align(self._cal_num_input, lv.ALIGN.OUT_RIGHT_MID, 0, 0) self._set_cal_2 = TextBtn(self._t_cal, "Set Amp 2", self._set_amp_2_cb) self._set_cal_2.set_style(lv.btn.STYLE.REL, btn_style_or) self._set_cal_2.align(self._set_cal_1, lv.ALIGN.OUT_RIGHT_MID, 0, 0) self._kb = lv.kb(self._t_cal) self._kb.set_map(["1", "2", "3","\n","4","5", "6",\ "\n","7", "8", "9","\n","0",".","Bksp",""]) self._kb.set_height(180) self._kb.set_y(85) self._kb.set_ta(self._cal_num_input) # Laser Off Screen self._text = RealignLabel(self._t_done, "Laser Off", False) # Other Screen self._cal = lv.calendar(self._t_other) return
def popup_pid_params(self): """ The popup window of PID params settings """ 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) # init mbox and title popup_pid = lv.mbox(bg) popup_pid.set_text('Set PID Params') popup_pid.set_size(220, 300) popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0) input_cont = lv.cont(popup_pid) input_cont.set_size(210, 180) def input_event_cb(ta, event): if event == lv.EVENT.CLICKED: self.current_input_placeholder = ta.get_placeholder_text() if self.current_input_placeholder == 'Set Offset': popup_pid.align(bg, lv.ALIGN.CENTER, 0, -55) else: popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0) if kb.get_hidden(): kb.set_hidden(False) # Focus on the clicked text area kb.set_ta(ta) def keyboard_event_cb(event_kb, event): event_kb.def_event_cb(event) if event == lv.EVENT.CANCEL or event == lv.EVENT.APPLY: kb.set_hidden(True) if self.current_input_placeholder == 'Set Offset': popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0) # init keyboard kb = lv.kb(bg) kb.set_cursor_manage(True) kb.set_event_cb(keyboard_event_cb) lv.kb.set_mode(kb, lv.kb.MODE.NUM) rel_style = lv.style_t() pr_style = lv.style_t() lv.style_copy(rel_style, lv.style_btn_rel) rel_style.body.radius = 0 rel_style.body.border.width = 1 lv.style_copy(pr_style, lv.style_btn_pr) pr_style.body.radius = 0 pr_style.body.border.width = 1 kb.set_style(lv.kb.STYLE.BG, lv.style_transp_tight) kb.set_style(lv.kb.STYLE.BTN_REL, rel_style) kb.set_style(lv.kb.STYLE.BTN_PR, pr_style) # init text areas kp_input = lv.ta(input_cont) kp_input.set_text(str(self.pid_params.get('kp'))) kp_input.set_placeholder_text('Set Kp') kp_input.set_accepted_chars('0123456789.+-') kp_input.set_one_line(True) kp_input.set_width(120) kp_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 20) kp_input.set_event_cb(input_event_cb) kp_label = lv.label(input_cont) kp_label.set_text("Kp: ") kp_label.align(kp_input, lv.ALIGN.OUT_LEFT_MID, 0, 0) pid_title_label = lv.label(input_cont) pid_title_label.set_text("PID Params:") pid_title_label.align(kp_input, lv.ALIGN.OUT_TOP_LEFT, -65, 0) ki_input = lv.ta(input_cont) ki_input.set_text(str(self.pid_params.get('ki'))) ki_input.set_placeholder_text('Set Ki') ki_input.set_accepted_chars('0123456789.+-') ki_input.set_one_line(True) ki_input.set_width(120) ki_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 55) ki_input.set_event_cb(input_event_cb) ki_input.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN) ki_label = lv.label(input_cont) ki_label.set_text("Ki: ") ki_label.align(ki_input, lv.ALIGN.OUT_LEFT_MID, 0, 0) kd_input = lv.ta(input_cont) kd_input.set_text(str(self.pid_params.get('kd'))) kd_input.set_placeholder_text('Set Kd') kd_input.set_accepted_chars('0123456789.+-') kd_input.set_one_line(True) kd_input.set_width(120) kd_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 90) kd_input.set_event_cb(input_event_cb) kd_input.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN) kd_label = lv.label(input_cont) kd_label.set_text("Kd: ") kd_label.align(kd_input, lv.ALIGN.OUT_LEFT_MID, 0, 0) temp_offset_input = lv.ta(input_cont) temp_offset_input.set_text(str(self.temp_offset)) temp_offset_input.set_placeholder_text('Set Offset') temp_offset_input.set_accepted_chars('0123456789.+-') temp_offset_input.set_one_line(True) temp_offset_input.set_width(120) temp_offset_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 145) temp_offset_input.set_event_cb(input_event_cb) temp_offset_input.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN) temp_offset_label = lv.label(input_cont) temp_offset_label.set_text("Offset: ") temp_offset_label.align(temp_offset_input, lv.ALIGN.OUT_LEFT_MID, 0, 0) offset_title_label = lv.label(input_cont) offset_title_label.set_text("Temp Correction:") offset_title_label.align(temp_offset_input, lv.ALIGN.OUT_TOP_LEFT, -65, 0) # set btns to mbox btns = ['Save', 'Cancel', ''] popup_pid.add_btns(btns) lv.cont.set_fit(popup_pid, lv.FIT.NONE) mbox_style = popup_pid.get_style(popup_pid.STYLE.BTN_REL) popup_pid_style = lv.style_t() lv.style_copy(popup_pid_style, mbox_style) popup_pid_style.body.padding.bottom = 46 popup_pid.set_style(popup_pid.STYLE.BTN_REL, popup_pid_style) popup_pid.set_size(220, 300) def event_handler(obj, event): if event == lv.EVENT.VALUE_CHANGED: active_btn_text = popup_pid.get_active_btn_text() if active_btn_text == 'Save': kp_value = float(kp_input.get_text()) ki_value = float(ki_input.get_text()) kd_value = float(kd_input.get_text()) temp_offset_value = float(temp_offset_input.get_text()) self.config['pid'] = { 'kp': kp_value, 'ki': ki_value, 'kd': kd_value } self.config['sensor_offset'] = temp_offset_value self.pid_params = self.config.get('pid') self.temp_offset = self.config.get('sensor_offset') # Save settings to config.json with open('config.json', 'w') as f: ujson.dump(self.config, f) # Apply settings immediately self.pid.reset(kp_value, ki_value, kd_value) self.sensor.set_offset(temp_offset_value) bg.del_async() popup_pid.start_auto_close(5) popup_pid.set_event_cb(event_handler) popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0) kb.set_ta(kp_input) kb.set_hidden(True)