def add_button(text=None, callback=None, scr=None, y=700): """Helper function that creates a button with a text label""" if scr is None: scr = lv.scr_act() btn = lv.btn(scr) btn.set_width(HOR_RES - 2 * PADDING) btn.set_height(BTN_HEIGHT) if text is not None: lbl = lv.label(btn) lbl.set_text(text) lbl.set_align(lv.label.ALIGN.CENTER) btn.align(scr, lv.ALIGN.IN_TOP_MID, 0, 0) btn.set_y(y) if callback is not None: btn.set_event_cb(callback) return btn
def screen_init(): sda_pin = machine.Pin(23) scl_pin = machine.Pin(32) i2c = machine.I2C(id=1, scl=scl_pin, sda=sda_pin, speed=400000) ts.init(i2c) tft.init(tft.ST7789, width=240, invrot=3, rot=1, bgr=False, height=240, miso=2, mosi=19, clk=18, cs=5, dc=27, speed=40000000, color_bits=tft.COLOR_BITS16, backl_pin=12, backl_on=1) tft.clear(tft.RED) time.sleep(1) tft.clear(tft.GREEN) time.sleep(1) tft.clear(tft.BLUE) time.sleep(1) lv.init() disp_buf1 = lv.disp_buf_t() buf1_1 = bytes(240 * 10) lv.disp_buf_init(disp_buf1, buf1_1, None, len(buf1_1) // 4) disp_drv = lv.disp_drv_t() lv.disp_drv_init(disp_drv) disp_drv.buffer = disp_buf1 disp_drv.flush_cb = lv_h.flush disp_drv.hor_res = 240 disp_drv.ver_res = 240 lv.disp_drv_register(disp_drv) indev_drv = lv.indev_drv_t() lv.indev_drv_init(indev_drv) indev_drv.type = lv.INDEV_TYPE.POINTER indev_drv.read_cb = lv_h.read lv.indev_drv_register(indev_drv) scr = lv.obj() btn = lv.btn(scr) btn.align(lv.scr_act(), lv.ALIGN.CENTER, 0, 0) label = lv.label(btn) label.set_text("Button") lv.scr_load(scr)
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, 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 self.big_btn = lv.btn(lv.scr_act(), None) self.big_btn.set_size(TP_MAX_VALUE, TP_MAX_VALUE) self.big_btn.set_style(lv.btn.STYLE.REL, lv.style_transp) self.big_btn.set_style(lv.btn.STYLE.PR, lv.style_transp) self.big_btn.set_layout(lv.LAYOUT.OFF) self.big_btn.set_event_cb( lambda obj, event, self=self: self.calibrate_clicked() if event == lv.EVENT.CLICKED else None) # Create the screen, circle and label self.label_main = lv.label(lv.scr_act(), None) style_circ = lv.style_t() lv.style_copy(style_circ, lv.style_pretty_color) style_circ.body.radius = LV_RADIUS_CIRCLE self.circ_area = lv.obj(lv.scr_act(), None) self.circ_area.set_size(CIRCLE_SIZE, CIRCLE_SIZE) self.circ_area.set_style(style_circ) self.circ_area.set_click(False) self.show_circle()
def __init__(self, app, page): self.app = app self.page = page self.btn1 = SymbolButton(page, lv.SYMBOL.PLAY, "Play") self.btn1.set_size(140, 100) self.btn1.align(None, lv.ALIGN.IN_TOP_LEFT, 20, 0) self.btn2 = SymbolButton(page, lv.SYMBOL.PAUSE, "Pause") self.btn2.set_size(140, 100) self.btn2.align(self.btn1, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) self.label = lv.label(page) self.label.align(self.btn1, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) # Currently only single callback per object is supported for btn, name in [(self.btn1, 'Play'), (self.btn2, 'Pause')]: btn.set_action(lv.btn.ACTION.CLICK, lambda action, name=name: self.label.set_text( '%s click' % name) or lv.RES.OK)
def __init__(self, app, page): self.app = app self.page = page self.btn1 = SymbolButton(page, lv.SYMBOL.PLAY, "Play") self.btn1.set_size(140, 100) self.btn1.align(page, lv.ALIGN.IN_TOP_LEFT, 30, 30) self.btn2 = SymbolButton(page, lv.SYMBOL.PAUSE, "Pause") self.btn2.set_size(140, 100) self.btn2.align(page, lv.ALIGN.IN_TOP_RIGHT, -30, 30) self.label = lv.label(page) self.label.align(page, lv.ALIGN.IN_BOTTOM_LEFT, 30, -30) # Currently only single callback per object is supported for btn, name in [(self.btn1, 'Play'), (self.btn2, 'Pause')]: btn.set_event_cb( lambda obj=None, event=-1, name=name: self.label.set_text( '%s %s' % (name, get_member_name(lv.EVENT, event))))
def copy_open_icon_event_cb(self, obj, evt): if evt == lv.EVENT.CLICKED: self.anim_out_all(lv.scr_act(), 0) self.log.debug("copy_open_icon_event_cb") self.scan_btn_txt = "NEXT" delay = 200 self.anim_bg(150, LV_DEMO_PRINTER_BLUE, self.LV_DEMO_PRINTER_BG_FULL) arc = self.add_loader(self.scan_anim_ready) arc.align(None, lv.ALIGN.CENTER, 0, -40) txt = lv.label(lv.scr_act(), None) txt.set_text("Scanning, please wait...") self.theme.apply(txt, LV_DEMO_PRINTER_THEME_LABEL_WHITE) txt.align(arc, lv.ALIGN.OUT_BOTTOM_MID, 0, 60) self.anim_in(arc, delay) delay += self.LV_DEMO_PRINTER_ANIM_DELAY self.anim_in(txt, delay) self.icon_generic_event_cb(obj, evt)
def __init__(self, title, message, button_text=(lv.SYMBOL.LEFT + " Back"), note=None): super().__init__() self.title = add_label(title, scr=self, style="title") obj = self.title if note is not None: self.note = add_label(note, scr=self, style="hint") self.note.align(self.title, lv.ALIGN.OUT_BOTTOM_MID, 0, 5) obj = self.note self.page = lv.page(self) self.page.set_size(480, 600) self.message = add_label(message, scr=self.page) self.page.align(obj, lv.ALIGN.OUT_BOTTOM_MID, 0, 0) self.close_button = add_button(scr=self, callback=on_release(self.release)) self.close_label = lv.label(self.close_button) self.close_label.set_text(button_text)
def __init__(self, app, page): self.app = app self.page = page # slider self.slider = lv.slider(page) self.slider.align(page, lv.ALIGN.IN_TOP_LEFT, 20, 0) self.slider_label = lv.label(page) self.slider_label.align(self.slider, lv.ALIGN.OUT_RIGHT_MID, 15, 0) self.slider.set_action(self.on_slider_changed) self.on_slider_changed(0) # style selector self.styles = [('Plain', lv.style_plain), ('Plain color', lv.style_plain_color), ('Pretty', lv.style_pretty), ('Pretty color', lv.style_pretty_color)] self.style_selector = lv.ddlist(page) self.style_selector.align(self.slider, lv.ALIGN.IN_BOTTOM_LEFT, 0, 40) self.style_selector.set_options('\n'.join(x[0] for x in self.styles)) self.style_selector.set_action(self.on_style_selector_changed)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.qr = lvqr.QRCode(self) self._text = "Text" # self.label.set_long_mode(lv.label.LONG.BREAK) # self.label.set_align(lv.label.ALIGN.CENTER) self._original_size = None self._press_start = None self.note = lv.label(self) style = lv.style_t() lv.style_copy(style, qr_style) style.text.font = lv.font_roboto_16 style.text.color = lv.color_hex(0x192432) self.note.set_style(0, style) self.note.set_text("") self.note.set_align(lv.label.ALIGN.CENTER) self.set_text(self._text) self.task = asyncio.create_task(self.animate()) self.set_event_cb(self.cb)
def draw_melting_dash_line(self, y_point, melting_temp): """ Draw melting temp with dashed line over the chart """ # Container for dashed line style_cont = lv.style_t() lv.style_copy(style_cont, lv.style_transp) dashed_segments = 10 dashed_cont = lv.cont(self.chart) dashed_cont.set_style(lv.line.STYLE.MAIN, style_cont) dashed_cont.set_width(GUI.CHART_WIDTH) # Draw dashed line style_dash_line = lv.style_t() lv.style_copy(style_dash_line, lv.style_transp) style_dash_line.line.color = lv.color_make(0xFF, 0x68, 0x33) style_dash_line.line.width = 3 dash_width = int(GUI.CHART_WIDTH / (dashed_segments * 2 - 1)) dashed_points = [ {'x': 0, 'y': 0}, {'x': dash_width, 'y': 0} ] dashed_line0 = lv.line(dashed_cont) dashed_line0.set_points(dashed_points, len(dashed_points)) dashed_line0.set_style(lv.line.STYLE.MAIN, style_dash_line) dashed_line0.align(None, lv.ALIGN.IN_LEFT_MID, 0, 0) for i in range(dashed_segments - 1): dl_name = 'dashed_line' + str(i+1) parent_name = 'dashed_line' + str(i) locals()[dl_name] = lv.line(dashed_cont, dashed_line0) locals()[dl_name].align(None, lv.ALIGN.IN_LEFT_MID, dash_width * (i+1) * 2, 0) # Melting temp melt_label = lv.label(dashed_cont) melt_label.set_recolor(True) melt_label.set_text('#FF6833 ' + str(melting_temp) + '#') # Put above elements in place dashed_cont.align_origo(self.chart, lv.ALIGN.IN_BOTTOM_MID, 0, -y_point) melt_label.align(dashed_cont, lv.ALIGN.IN_TOP_LEFT, 8, 12) return dashed_cont
def __init__(self, parent): super().__init__(parent) self.set_title("Pop") msg_box_close_btn = self.add_btn_right(lv.SYMBOL.CLOSE) msg_box_close_btn.set_event_cb( lambda obj, e: e == lv.EVENT.RELEASED and self.close_msg_box()) self.set_style_local_pad_left(self.PART.HEADER, lv.STATE.DEFAULT, 20) self.set_style_local_bg_color(self.PART.HEADER, lv.STATE.DEFAULT, lv.color_hex3(0xFEE)) self.set_style_local_bg_color(self.PART.BG, lv.STATE.DEFAULT, lv.color_hex3(0xFFF)) self.set_style_local_border_side( self.PART.HEADER, lv.STATE.DEFAULT, lv.BORDER_SIDE.LEFT | lv.BORDER_SIDE.RIGHT | lv.BORDER_SIDE.TOP) self.set_style_local_border_width(self.PART.HEADER, lv.STATE.DEFAULT, 4) self.set_style_local_border_color(self.PART.HEADER, lv.STATE.DEFAULT, lv.color_hex3(0xF88)) self.set_style_local_border_width(self.PART.BG, lv.STATE.DEFAULT, 4) self.set_style_local_border_color(self.PART.BG, lv.STATE.DEFAULT, lv.color_hex3(0xF88)) self.set_style_local_shadow_color(self.PART.BG, lv.STATE.DEFAULT, lv.color_hex3(0x000)) self.set_style_local_shadow_opa(self.PART.BG, lv.STATE.DEFAULT, 50) self.set_style_local_shadow_width(self.PART.BG, lv.STATE.DEFAULT, 20) self.set_style_local_shadow_ofs_x(self.PART.BG, lv.STATE.DEFAULT, 10) self.set_style_local_shadow_ofs_y(self.PART.BG, lv.STATE.DEFAULT, 10) self.set_style_local_shadow_spread(self.PART.BG, lv.STATE.DEFAULT, 0) self.set_style_local_radius(self.PART.HEADER, lv.STATE.DEFAULT, 10) self.set_style_local_radius(self.PART.BG, lv.STATE.DEFAULT, 10) self.set_content_size(100, 40) self.set_layout(lv.LAYOUT.CENTER) self.label = lv.label(self) self.set_top(True) self.set_drag(True) self.opened = True
def __init__(self, config): self.config = config self.sensor = MAX31855(hwspi=self.config['max31855_pins']['hwspi'], cs=self.config['max31855_pins']['cs'], miso=self.config['max31855_pins']['miso'], sck=self.config['max31855_pins']['sck'], offset=self.config['temp_offset']) self.oven = machine.Pin(self.config['oven_pin'], machine.Pin.OUT, value=0) self.temp_cali_scr = lv.obj() self.page = lv.page(self.temp_cali_scr) self.page.set_size(self.temp_cali_scr.get_width(), self.temp_cali_scr.get_height()) self.page.align(None, lv.ALIGN.CENTER, 0, 0) self.label = lv.label(self.page) self.label.set_long_mode(lv.label.LONG.BREAK) self.label.set_width(self.page.get_fit_width()) self.page_text = '' self.tim = machine.Timer(-1) self.start_time = None self.start_temp = None self.last_temp = None self.lag_temp = None self.lag_time = None self.cooling_counter = 0 self.check_temp = 100
def widget_set_text(obj, text): if not obj in sys.modules['llvgl'].config["objects"]: return if not text: return; # text may actually be an array of texts if isinstance(text, str): text = [ text ] if len(text) < 1: return lv_obj = obj["lv_obj"] if obj["type"] == TYPE.LABEL or obj["type"] == TYPE.CHECKBOX: lv_obj.set_text(text[0]) elif obj["type"] == TYPE.BUTTON: # make sure there is a label in that button if not "lv_label" in obj: obj["lv_label"] = lv.label(lv_obj) obj["lv_label"].set_text(text[0]) elif obj["type"] == TYPE.DROPDOWN: lv_obj.set_options("\n".join(text)) # setting the text may resize the object and we need to re-apply alignment update_alignment(obj)
def m6(): #wifi def btn_event(obj, event): if obj == btn2 and event == lv.EVENT.CLICKED: m5() if obj == ta and event == lv.EVENT.CLICKED: kb = lv.keyboard(scr) kb.set_textarea(ta) scr = lv.obj() lv.scr_load(scr) tab = lv.tabview(scr) tab1 = tab.add_tab("Wifi Settings") btn2 = lv.btn(tab) btn2.align(tab, lv.ALIGN.IN_TOP_LEFT, 0, 0) lbl_btn2 = lv.label(btn2) lbl_btn2.set_text(lv.SYMBOL.HOME) btn2.set_fit(lv.FIT.TIGHT) btn2.set_event_cb(btn_event) cont = lv.cont(tab1) cont.align(tab1, lv.ALIGN.IN_TOP_MID, 0, 20) cont.set_fit2(lv.FIT.TIGHT, lv.FIT.TIGHT) ta = lv.textarea(cont) ta.align(cont, lv.ALIGN.IN_TOP_MID, 0, 10) ta.set_one_line(True) ta.set_event_cb(btn_event) btn = lv.btn(cont) btn.align(ta, lv.ALIGN.OUT_BOTTOM_MID, 0, 0)
# initialize lvgl # import lvgl as lv import display_driver from lv_colors import lv_colors style = lv.style_t() style.init() # Set a background color and a radius style.set_radius(lv.STATE.DEFAULT, 5) style.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) style.set_bg_color(lv.STATE.DEFAULT, lv_colors.SILVER) style.set_border_width(lv.STATE.DEFAULT, 2) style.set_border_color(lv.STATE.DEFAULT, lv_colors.BLUE) style.set_pad_top(lv.STATE.DEFAULT, 10) style.set_pad_bottom(lv.STATE.DEFAULT, 10) style.set_pad_left(lv.STATE.DEFAULT, 10) style.set_pad_right(lv.STATE.DEFAULT, 10) style.set_text_color(lv.STATE.DEFAULT, lv_colors.BLUE) style.set_text_letter_space(lv.STATE.DEFAULT, 5) style.set_text_line_space(lv.STATE.DEFAULT, 20) style.set_text_decor(lv.STATE.DEFAULT, lv.TEXT_DECOR.UNDERLINE) # Create an object with the new style obj = lv.label(lv.scr_act(), None) obj.add_style(lv.label.PART.MAIN, style) obj.set_text("Text of\n" "a label") obj.align(None, lv.ALIGN.CENTER, 0, 0)
#!/opt/bin/lv_micropython -i import lvgl as lv import display_driver import time # Set a very visible color for the screen to clearly see what happens lv.scr_act().set_style_local_bg_color(lv.obj.PART.MAIN, lv.STATE.DEFAULT, lv.color_hex3(0xf33)) om = lv.objmask(lv.scr_act(), None) om.set_size(200, 200) om.align(None, lv.ALIGN.CENTER, 0, 0) label = lv.label(om, None) label.set_long_mode(lv.label.LONG.BREAK) label.set_align(lv.label.ALIGN.CENTER) label.set_width(180) label.set_text("This label will be masked out. See how it works.") label.align(None, lv.ALIGN.IN_TOP_MID, 0, 20) cont = lv.cont(om, None) cont.set_size(180, 100) cont.set_drag(True) cont.align(None, lv.ALIGN.IN_BOTTOM_MID, 0, -10) btn = lv.btn(cont, None) btn.align(None, lv.ALIGN.CENTER, 0, 0) btn.set_style_local_value_str(lv.btn.PART.MAIN, lv.STATE.DEFAULT, "Button") lv.refr_now(None) t = lv.tick_get() while lv.tick_elaps(t) < 1000:
def m4(): scr = lv.obj() lv.scr_load(scr) #container for drop and switch cont = lv.cont(scr) cont.set_auto_realign(True) cont.set_fit2(lv.FIT.PARENT, lv.FIT.TIGHT) cont.set_layout(lv.LAYOUT.PRETTY_MID) cont.align(scr, lv.ALIGN.IN_TOP_MID, 0, 0) #dropdown drop = lv.dropdown(cont) drop.set_style_local_border_post(lv.BORDER_SIDE.NONE, lv.BORDER_SIDE.NONE, lv.BORDER_SIDE.NONE) drop.set_options( "Trigger 1\nTrigger 2\nTrigger 3\nTrigger 4\nTrigger 5\nTrigger 6\nTrigger 7\nTrigger 8\nTrigger 9\n Trigger 10" ) #label lbl1 = lv.label(cont) lbl1.set_text("Arm?") #switch switch = lv.switch(cont) #tabview tab = lv.tabview(scr) tab.align(cont, lv.ALIGN.OUT_BOTTOM_MID, 0, 0) tab1 = tab.add_tab("Time") tab2 = tab.add_tab("Auto") tab3 = tab.add_tab("Switches") #tab1 lbl2 = lv.label(tab1) lbl2.set_text("Start time [h][m][s]") lbl2.align(tab1, lv.ALIGN.IN_TOP_MID, 0, 0) trig_btn = lv.btnmatrix(tab1) trig_btn.set_height(200) trig_btn.align(lbl2, lv.ALIGN.OUT_BOTTOM_MID, 0, 0) def remap(): btn_map = [ lv.SYMBOL.UP, lv.SYMBOL.UP, lv.SYMBOL.UP, "\n", str(trigger[0].bhour), str(trigger[0].bminute), str(trigger[0].bsecond), "\n", lv.SYMBOL.DOWN, lv.SYMBOL.DOWN, lv.SYMBOL.DOWN, "\n", lv.SYMBOL.SAVE, "", "" ] print('remapped called') return btn_map trig_btn.set_map(remap()) #trig_btn.set_style def event_handler(obj, event): if event == lv.EVENT.VALUE_CHANGED: txt = obj.get_active_btn() print("{} was pressed".format(txt)) if (txt == 0): trigger[0].bhour += 1 if (txt == 1): trigger[0].bminute += 1 if (txt == 2): trigger[0].bsecond += 1 if (txt == 6): trigger[0].bhour -= 1 if (txt == 7): trigger[0].bminute -= 1 if (txt == 8): trigger[0].bsecond -= 1 trig_btn.set_map(remap()) trig_btn.set_event_cb(event_handler) #label set duration lbl3 = lv.label(tab1) lbl3.align(trig_btn, lv.ALIGN.OUT_BOTTOM_MID, -100, 0) lbl3.set_text("Set trigger duration [h][m][s]") roller = lv.roller(tab1)
def m3(): global trigger print("This is callback for M3") scr = lv.obj() lv.scr_load(scr) #make container con = lv.cont(scr) con.set_auto_realign(True) #con.set_layout(lv.LAYOUT.PRETTY_TOP) con.align(scr, lv.ALIGN.IN_TOP_MID, 0, 0) con.set_fit2(lv.FIT.PARENT, lv.FIT.TIGHT) con.set_style_local_radius(0, 0, 0) #label = lv.label(con) #label.set_text("Trigger No:") #label.align(con, lv.ALIGN.IN_TOP_LEFT,10,10) drop = lv.dropdown(con) drop.align(con, lv.ALIGN.IN_LEFT_MID, 10, 0) drop.set_drag(False) drop.set_options( "trigger 1\ntrigger 2\ntrigger 3\ntrigger 4\ntrigger 5\ntrigger 6\ntrigger 7\n" ) drop.set_event_cb(lambda obj, event: m3_1() if event == lv.EVENT.VALUE_CHANGED else None) btn = lv.btn(con) label_btn = lv.label(btn) btn.set_height(drop.get_height()) label_btn.set_text("New") btn.align(con, lv.ALIGN.IN_RIGHT_MID, -10, 0) def m3_1(): #load values to begin and duration con2 = lv.cont(scr) con2.align(con, lv.ALIGN.OUT_BOTTOM_MID, 0, 0) con2.set_fit2(lv.FIT.PARENT, lv.FIT.TIGHT) con2.set_style_local_radius(0, 0, 0) position = drop.get_selected() con3 = lv.cont(con2) con3.align(con2, lv.ALIGN.IN_TOP_MID, 0, 0) con3.set_fit2(lv.FIT.PARENT, lv.FIT.TIGHT) tittle = lv.label(con3) tittle.align(con3, lv.ALIGN.CENTER, 0, 0) tittle.set_text("Set Begin Time") minute_btn = lv.btn(con2) minute_btn.align(con3, lv.ALIGN.OUT_BOTTOM_MID, 0, 0) minute_btn.set_style_local_radius(0, 0, 0) minute_btn.set_fit(lv.FIT.TIGHT) lbl_minute_btn = lv.label(minute_btn) lbl_minute_btn.set_text(str(trigger[position].bminute)) hour_btn = lv.btn(con2) hour_btn.align(minute_btn, lv.ALIGN.OUT_LEFT_MID, 0, 0) hour_btn.set_style_local_radius(0, 0, 0) hour_btn.set_fit(lv.FIT.TIGHT) lbl_hour_btn = lv.label(hour_btn) lbl_hour_btn.set_text(str(trigger[position].bhour)) second_btn = lv.btn(con2) second_btn.align(minute_btn, lv.ALIGN.OUT_RIGHT_MID, 0, 0) second_btn.set_style_local_radius(0, 0, 0) second_btn.set_fit(lv.FIT.TIGHT) lvl_second_btn = lv.label(second_btn) lvl_second_btn.set_text(str(trigger[position].bsecond)) m3_1()
#!/opt/bin/lv_micropython -i import time import lvgl as lv import display_driver # # A default slider with a label displaying the current value # def slider_event_cb(e): slider = lv.slider.__cast__(e.get_target()) slider_label.set_text("{:d}%".format(slider.get_value())) slider_label.align_to(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) # Create a slider in the center of the display slider = lv.slider(lv.scr_act()) slider.center() slider.add_event_cb(slider_event_cb, lv.EVENT.VALUE_CHANGED, None) # Create a label below the slider slider_label = lv.label(lv.scr_act()) slider_label.set_text("0%") slider_label.align_to(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10)
import display_driver def event_handler(source, evt): if evt == lv.EVENT.VALUE_CHANGED: # print(slider.get_value()) slider_label.set_text(str(slider.get_value())) # Create a slider in the center of the display slider = lv.slider(lv.scr_act(), None) slider.set_width(200) slider.align(None, lv.ALIGN.CENTER, 0, 0) slider.set_event_cb(event_handler) slider.set_range(0, 100) # Create a label below the slider slider_label = lv.label(lv.scr_act(), None) slider_label.set_text("0") slider_label.set_auto_realign(True) slider_label.align(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) # Create an informative label info_label = lv.label(lv.scr_act(), None) info_label.set_text("""Welcome to the slider + label demo! Move the slider and see that the label updates to match it.""") info_label.align(None, lv.ALIGN.IN_TOP_LEFT, 10, 10)
WIFI_Connect() #连接WiFi #Create a style based on style_plain mystyle = lv.style_t(lv.style_plain) #mystyle.text.font = roboto_80 # font roboto 80 pixel mystyle.text.font = lv.font_roboto_28 mystyle.body.main_color = lv.color_hex(0x000000) # background top color (main), 0xRRGGBB mystyle.body.grad_color = lv.color_hex(0x000000) # background bottom color (gradient), 0xRRGGBB mystyle.text.color = lv.color_hex(0xffffff) # text-colour, 0xRRGGBB #Create screen and labels scr = lv.obj() scr.set_style(mystyle) LOGO = lv.label(scr) LOGO.set_pos(0,0) LOGO.set_drag(True) LOGO.set_text("01Studio") WIFI_ICON = lv.label(scr) WIFI_ICON.set_pos(200,0) WIFI_ICON.set_drag(True) WIFI_ICON.set_text(lv.SYMBOL.WIFI) DATE = lv.label(scr) DATE.set_pos(0,64) DATE.set_drag(True) TIME = lv.label(scr) TIME.set_pos(0,128)
def main_page(self, tile_num): # create the GUI self.weather_app_tile = self.mainbar.get_tile_obj(tile_num) weather_style = lv.style_t() weather_style.copy(self.mainbar.get_style()) weather_cont = lv.obj(self.weather_app_tile, None) weather_cont.set_size(lv.scr_act().get_disp().driver.hor_res, 30) weather_cont.add_style(lv.cont.PART.MAIN, weather_style) # create date label and left right buttons btn_style = lv.style_t() btn_style.copy(weather_style) btn_style.set_radius(lv.btn.STATE.RELEASED, 2) self.left_button = lv.btn(weather_cont, None) self.left_button.set_size(25, 25) self.left_button.add_style(lv.btn.PART.MAIN, btn_style) left_label = lv.label(self.left_button, None) left_label.set_text(lv.SYMBOL.LEFT) self.left_button.align(weather_cont, lv.ALIGN.IN_LEFT_MID, 5, 0) self.left_button.set_hidden(True) self.left_button.set_event_cb(self.decrement_day) self.date_label = lv.label(weather_cont, None) self.date_label.set_text(self.date[self.day_index]) self.date_label.align(weather_cont, lv.ALIGN.CENTER, 0, 0) self.right_button = lv.btn(weather_cont, None) self.right_button.set_size(25, 25) self.right_button.add_style(lv.btn.PART.MAIN, btn_style) right_label = lv.label(self.right_button, None) right_label.set_text(lv.SYMBOL.RIGHT) self.right_button.align(weather_cont, lv.ALIGN.IN_RIGHT_MID, -5, 0) self.right_button.set_event_cb(self.increment_day) icon_cont_style = lv.style_t() icon_cont_style.copy(weather_style) icon_cont_style.set_bg_opa(lv.obj.PART.MAIN, lv.OPA.TRANSP) icon_cont = lv.cont(self.weather_app_tile, None) icon_cont.set_layout(lv.LAYOUT.COLUMN_LEFT) icon_cont.add_style(lv.cont.PART.MAIN, icon_cont_style) icon_cont.set_fit(lv.FIT.TIGHT) self.icon = lv.img(icon_cont, None) key_list = list(self.icon_filename.keys()) self.log.debug(key_list) index = key_list.index(self.weather_state_abbr[self.day_index]) self.log.debug("index of %s: %d" % (self.weather_state_abbr[self.day_index], index)) self.icon.set_src(self.icon_dsc[index]) icon_cont.align(weather_cont, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) self.state_label = lv.label(icon_cont, None) self.state_label.set_width(100) self.state_label.set_text(self.weather_state_name[self.day_index]) info_cont_style = lv.style_t() info_cont_style.copy(weather_style) info_cont_style.set_pad_top(lv.STATE.DEFAULT, 6) info_cont_style.set_pad_inner(lv.STATE.DEFAULT, 4) info_cont = lv.cont(self.weather_app_tile, None) info_cont.set_size(lv.scr_act().get_disp().driver.hor_res, 90) info_cont.set_layout(lv.LAYOUT.COLUMN_LEFT) info_cont.add_style(lv.cont.PART.MAIN, icon_cont_style) info_cont.set_fit(lv.FIT.NONE) info_cont.align(icon_cont, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) info_cont.add_style(lv.cont.PART.MAIN, info_cont_style) self.confidence_label = lv.label(info_cont, None) self.confidence_label.set_text("Confidence level: {}%".format( self.predic[self.day_index])) self.temp_label = lv.label(info_cont, None) self.temp_label.set_text( "Temp: min: %3.1f°C, max: %3.1f°C" % (self.min_temp[self.day_index], self.max_temp[self.day_index])) self.humidity_label = lv.label(info_cont, None) self.humidity_label.set_text("Humidity: {}%".format( self.humid[self.day_index])) self.pressure_label = lv.label(info_cont, None) self.pressure_label.set_text("Air pressure: %d hPa" % self.air_pressure[self.day_index]) info_cont2 = lv.cont(self.weather_app_tile, None) # info_cont2.set_size(140,120) info_cont2.set_layout(lv.LAYOUT.COLUMN_LEFT) info_cont2.add_style(lv.cont.PART.MAIN, icon_cont_style) info_cont2.set_fit(lv.FIT.TIGHT) info_cont2.align(icon_cont, lv.ALIGN.OUT_RIGHT_TOP, -5, 0) info_cont2.add_style(lv.cont.PART.MAIN, info_cont_style) self.location_label = lv.label(info_cont2, None) self.location_label.set_text("Location: " + self.location) self.wind_label = lv.label(info_cont2, None) self.wind_label.set_text("Wind:\nspeed: %5.1f kph\ndir: %s" % (self.wind_speed[self.day_index], self.wind_direction[self.day_index])) exit_btn = lv.imgbtn(self.weather_app_tile, None) exit_btn.set_src(lv.btn.STATE.RELEASED, self.mainbar.get_exit_btn_dsc()) exit_btn.set_src(lv.btn.STATE.PRESSED, self.mainbar.get_exit_btn_dsc()) exit_btn.set_src(lv.btn.STATE.CHECKED_RELEASED, self.mainbar.get_exit_btn_dsc()) exit_btn.set_src(lv.btn.STATE.CHECKED_PRESSED, self.mainbar.get_exit_btn_dsc()) exit_btn.align(self.weather_app_tile, lv.ALIGN.IN_BOTTOM_RIGHT, -10, -10) exit_btn.set_event_cb(self.exit_weather_app_event_cb)
hybrid=True, width=320, height=240, colormode=ili9341.COLOR_MODE_BGR, rot=ili9341.MADCTL_ML, invert=False, double_buffer=False) # Create a display driver # here one can add a wifi connection script to see if there is a wifi interaction # import wifiConnect # A screen with four buttons... scr = lv.obj() btn1 = lv.btn(scr) lb1 = lv.label(btn1) lb1.set_text("1") btn1.set_size(60, 40) btn1.align(None, lv.ALIGN.IN_TOP_LEFT, 10, 10) btn2 = lv.btn(scr) lb2 = lv.label(btn2) lb2.set_text("2") btn2.set_size(60, 40) btn2.align(btn1, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) # btn3 = lv.btn(scr) lb3 = lv.label(btn3) lb3.set_text("3") btn3.set_size(60, 40) btn3.align(btn2, lv.ALIGN.OUT_RIGHT_TOP, 10, 0)
# Create a container with ROW flex direction cont_row = lv.obj(lv.scr_act()) cont_row.set_size(300, 75) cont_row.align(lv.ALIGN.TOP_MID, 0, 5) cont_row.set_flex_flow(lv.FLEX_FLOW.ROW) # Create a container with COLUMN flex direction cont_col = lv.obj(lv.scr_act()) cont_col.set_size(200, 150) cont_col.align_to(cont_row, lv.ALIGN.OUT_BOTTOM_MID, 0, 5) cont_col.set_flex_flow(lv.FLEX_FLOW.COLUMN) for i in range(10): # Add items to the row obj = lv.btn(cont_row) obj.set_size(100, lv.pct(100)) label = lv.label(obj) label.set_text("Item: {:d}".format(i)) label.center() # Add items to the column obj = lv.btn(cont_col) obj.set_size(lv.pct(100), lv.SIZE.CONTENT) label = lv.label(obj) label.set_text("Item: {:d}".format(i)) label.center()
touch = xpt2046( cs=TOUCH_CS, transpose=TFT_IS_PORTRAIT, cal_x0=touch_x0, cal_x1=touch_x1, cal_y0=touch_y0, cal_y1=touch_y1, ) TOUCH_READY = 1 #表示已经配置好触摸参数 ############################################# ################# Label ################# ############################################# if TOUCH_READY: label1 = lv.label(lv.scr_act()) label1.set_long_mode(lv.label.LONG.BREAK) # Break the long lines label1.set_recolor(True) # Enable re-coloring by commands in the text label1.set_align(lv.label.ALIGN.CENTER) # Center aligned lines label1.set_text("#0000ff Re-color# #00ff00 words# #ff0000 of a# label " + "and wrap long text automatically.") label1.set_width(150) label1.align(None, lv.ALIGN.CENTER, 0, -30) label2 = lv.label(lv.scr_act()) label2.set_long_mode(lv.label.LONG.SROLL_CIRC) # Circular scroll label2.set_width(150) label2.set_text("It is a circularly scrolling text. ") label2.align(None, lv.ALIGN.CENTER, 0, 30)
#!//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)
# Create the password box LV_HOR_RES = lv.scr_act().get_disp().driver.hor_res LV_VER_RES = lv.scr_act().get_disp().driver.ver_res pwd_ta = lv.textarea(lv.scr_act()) pwd_ta.set_text("") pwd_ta.set_password_mode(True) pwd_ta.set_one_line(True) pwd_ta.set_width(LV_HOR_RES // 2 - 20) pwd_ta.set_pos(5, 20) pwd_ta.add_event_cb(ta_event_cb, lv.EVENT.ALL, None) # Create a label and position it above the text box pwd_label = lv.label(lv.scr_act()) pwd_label.set_text("Password:"******"Text:")
#!//opt/bin/lv_micropython -i import time import lvgl as lv import display_driver # # Demonstrate how scrolling appears automatically # # Create an object with the new style panel = lv.obj(lv.scr_act()) panel.set_size(200, 200) panel.center() child = lv.obj(panel) child.set_pos(0, 0) label = lv.label(child) label.set_text("Zero") label.center() child = lv.obj(panel) child.set_pos(-40, 100) label = lv.label(child) label.set_text("Left") label.center() child = lv.obj(panel) child.set_pos(90, -30) label = lv.label(child) label.set_text("Top") label.center()
if event == lv.EVENT.CLICKED: if obj == btn: box.set_hidden(0) bg.set_hidden(0) elif obj == box: box.set_hidden(1) bg.set_hidden(1) #create screen object scr = lv.obj() #create button in center with callback btn = lv.btn(scr) btn.align(scr, lv.ALIGN.CENTER, 0, 0) btn.set_event_cb(event_handler) label = lv.label(btn) label.set_text("Press me") label.set_size(20,20) #create semi-transparrent background and set it to hidden bg = lv.obj(scr) bg.set_pos(0, 0) bg.set_size(scr.get_width(), scr.get_height()) 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,50) modal_style.body.opa = 75 bg.set_style(modal_style) bg.set_hidden(1) #create message box and set it to hidden
my_style.body.grad_color = color_red my_style.body.radius = 10 color = lv.color16_t() color.full = lcd.WHITE my_style.text.font = my_font # use new font my_style.text.color = color # root scr = lv.obj(lv.scr_act()) scr.set_style(my_style) # scr.set_pos(20, 20) scr.align(None, lv.ALIGN.CENTER, 0, -30) scr.set_size(120, 100) # label label = lv.label(scr) label.set_long_mode(label.LONG.SROLL) label.set_width(100) label.align(None, lv.ALIGN.CENTER, 0, 0) label.set_text("你好 hello") # label.set_text("\u4f60\u597d hello") # label.set_text(b"\xE4\xBD\xA0\xE5\xA5\xBDhello") def on_timer(timer): lv.tick_inc(5) timer = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PERIODIC,