def __init__(self, parent): super().__init__(parent, 20) self.vect = lv.point_t() self.set_size(100, 80) self.add_title("Pop") msg_box_close_btn = self.add_btn(lv.SYMBOL.CLOSE, 20) msg_box_close_btn.add_event_cb(lambda e: self.close_msg_box(), lv.EVENT.RELEASED, None) header = self.get_header() header.set_style_bg_color(lv.color_hex3(0xFEE), lv.PART.MAIN) content = self.get_content() content.set_style_bg_color(lv.color_hex3(0xFFF), lv.PART.MAIN) self.set_style_border_width(4, lv.PART.MAIN) self.set_style_border_color(lv.color_hex3(0xF88), lv.PART.MAIN) self.set_style_shadow_color(lv.color_hex3(0x000), lv.PART.MAIN) self.set_style_shadow_opa(50, lv.PART.MAIN) self.set_style_shadow_width(20, lv.PART.MAIN) self.set_style_shadow_ofs_x(10, lv.PART.MAIN) self.set_style_shadow_ofs_y(10, lv.PART.MAIN) self.set_style_shadow_spread(0, lv.PART.MAIN) self.set_style_radius(10, lv.PART.MAIN) self.label = lv.label(content) for element in [content, header]: element.add_event_cb(self.drag_event_handler, lv.EVENT.PRESSING, None) self.opened = True
def __init__(self, color): super().__init__() self.set_bg_opa(lv.OPA.COVER) self.set_bg_color(lv.color_hex3(color)) self.set_bg_grad_color(lv.color_hex3(0xFFF)) self.set_bg_grad_dir(lv.GRAD_DIR.VER) self.set_bg_main_stop(0) self.set_bg_grad_stop(128)
def set_status(self, which, what): labelstyle = lv.style_t() if what: labelstyle.set_text_color(lv.STATE.DEFAULT, lv.color_hex3(0x080)) else: labelstyle.set_text_color(lv.STATE.DEFAULT, lv.color_hex3(0xccc)) self.status[which].add_style(lv.label.PART.MAIN, labelstyle)
def __init__(self, text, *args, **kwds): super().__init__(*args, **kwds) # styly of the background overlay self.style = lv.style_t() self.style.init() self.style.set_bg_opa(lv.STATE.DEFAULT, lv.OPA._60) self.style.set_bg_color(lv.STATE.DEFAULT, lv.color_hex3(0x000)) # create a base object for the modal background self.reset_style_list(lv.obj.PART.MAIN) self.add_style(lv.obj.PART.MAIN, self.style) self.set_pos(0, 0) self.set_size(240, 320) self.mbox = lv.msgbox(self) self.mbox.set_text(text) self.mbox.add_btns(["OK", ""]) self.mbox.set_width(200) self.mbox.align(lv.scr_act(), lv.ALIGN.CENTER, 0, 0) self.mbox.set_event_cb(self.mbox_event_cb) self.g = lv.group_t() self.g.add_obj(self.mbox) lv.group_focus_obj(self.mbox) self.g.focus_freeze(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): super().__init__() self.set_shadow_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.set_shadow_width(lv.STATE.DEFAULT, 3) self.set_shadow_color(lv.STATE.DEFAULT, lv.color_hex3(0xAAA)) self.set_shadow_ofs_x(lv.STATE.DEFAULT, 5) self.set_shadow_ofs_y(lv.STATE.DEFAULT, 3) self.set_shadow_spread(lv.STATE.DEFAULT, 0)
def __init__(self): super().__init__() self.set_shadow_opa(lv.OPA.COVER) self.set_shadow_width(3) self.set_shadow_color(lv.color_hex3(0xAAA)) self.set_shadow_ofs_x(5) self.set_shadow_ofs_y(3) self.set_shadow_spread(0)
def __init__(self): super().__init__() self.set_radius(lv.dpx(8)) self.set_shadow_opa(lv.OPA.COVER) self.set_shadow_width(lv.dpx(10)) self.set_shadow_color(lv.color_hex3(0xAAA)) self.set_shadow_ofs_x(lv.dpx(10)) self.set_shadow_ofs_y(lv.dpx(10)) self.set_shadow_spread(0)
def __init__(self, page): self.page = page # display ftDuino32 "title" label = lv.label(page) label.set_recolor(True); label.set_text("#ff0000 f##0000ff t##00664c Duino#32") style = lv.style_t() style.set_text_font(lv.STATE.DEFAULT, lv.font_montserrat_16) label.add_style(lv.label.PART.MAIN, style) label.align(page, lv.ALIGN.CENTER, 0, -100) # display user definabled device name self.dname = lv.label(page) self.set_device_name("ftDuino32") # display release rlabel = lv.label(page) rlabel.set_text("Release: ") if hasattr(os, "uname"): rlabel.ins_text(lv.LABEL_POS.LAST, os.uname().release) else: rlabel.ins_text(lv.LABEL_POS.LAST, "<unknown>") rlabel.align(page, lv.ALIGN.CENTER, 0, -40) # display version vlabel = lv.label(page) vlabel.set_long_mode(lv.label.LONG.BREAK); vlabel.set_width(210); vlabel.set_align(lv.label.ALIGN.CENTER) if hasattr(os, "uname"): vlabel.set_text(os.uname().version) else: vlabel.set_text("<unknown version>") vlabel.align(page, lv.ALIGN.CENTER, 0, -10) scroll = lv.label(page) scroll.set_long_mode(lv.label.LONG.SROLL_CIRC); scroll.set_width(150); scroll.set_recolor(True); scroll.set_text("Thank you for using the #ff0000 f##0000ff t##00664c Duino#32 controller.") scroll.align(page, lv.ALIGN.CENTER, 0, 40) # add two status bar labels for wifi and sd card self.status = { } labelstyle = lv.style_t() labelstyle.set_text_color(lv.STATE.DEFAULT, lv.color_hex3(0xccc)) labelstyle.set_text_font(lv.STATE.DEFAULT, lv.font_montserrat_16) for i in self.ICONS: self.status[i] = lv.label(page) self.status[i].set_text(self.ICON_CHAR[i]) self.status[i].add_style(lv.label.PART.MAIN, labelstyle) self.status[i].align(page, lv.ALIGN.CENTER, 16-32*self.ICONS.index(i), 100)
def __init__(self): super().__init__() self.set_radius(lv.STATE.DEFAULT, lv.dpx(8)) self.set_shadow_opa(lv.STATE.DEFAULT, lv.OPA.COVER); self.set_shadow_width(lv.STATE.DEFAULT, lv.dpx(10)); self.set_shadow_color(lv.STATE.DEFAULT, lv.color_hex3(0xAAA)); self.set_shadow_ofs_x(lv.STATE.DEFAULT, lv.dpx(10)); self.set_shadow_ofs_y(lv.STATE.DEFAULT, lv.dpx(10)); self.set_shadow_spread(lv.STATE.DEFAULT, 0); self.set_shadow_ofs_x(lv.STATE.PRESSED, lv.dpx(0)); self.set_shadow_ofs_y(lv.STATE.PRESSED, lv.dpx(0));
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, title, cb, *args, **kwds): def kbd_event_cb(obj, evt): obj.def_event_cb(evt) if evt == lv.EVENT.DELETE: obj.get_parent().del_async() self.kbd = None elif evt == lv.EVENT.CANCEL: obj.del_async() cb(None) elif evt == lv.EVENT.APPLY: text = self.text.get_text() obj.del_async() cb(text) super().__init__(*args, **kwds) # styly of the background overlay self.style = lv.style_t() self.style.init() self.style.set_bg_opa(lv.STATE.DEFAULT, lv.OPA._100) self.style.set_bg_color(lv.STATE.DEFAULT, lv.color_hex3(0xeee)) # create a base object for the modal background self.reset_style_list(lv.obj.PART.MAIN) self.add_style(lv.obj.PART.MAIN, self.style) self.set_pos(0, 0) self.set_size(240, 320) label = lv.label(self) label.set_text(title) label.align(self, lv.ALIGN.IN_TOP_MID, 0, 60) self.text = lv.textarea(self) self.text.set_text("") self.text.set_height(40) self.text.set_width(200) self.text.align(self, lv.ALIGN.IN_TOP_MID, 0, 100) self.kbd = lv.keyboard(self) self.kbd.set_event_cb(kbd_event_cb) self.kbd.set_cursor_manage(False) self.kbd.set_textarea(self.text) self.g = lv.group_t() self.g.add_obj(self.kbd) lv.group_focus_obj(self.kbd) self.g.focus_freeze(True)
#!/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:
# # Show how to style a slider. # # Create a transition props = [lv.STYLE.BG_COLOR, 0] transition_dsc = lv.style_transition_dsc_t() transition_dsc.init(props, lv.anim_t.path_linear, 300, 0, None) style_main = lv.style_t() style_indicator = lv.style_t() style_knob = lv.style_t() style_pressed_color = lv.style_t() style_main.init() style_main.set_bg_opa(lv.OPA.COVER) style_main.set_bg_color(lv.color_hex3(0xbbb)) style_main.set_radius(lv.RADIUS.CIRCLE) style_main.set_pad_ver(-2) # Makes the indicator larger style_indicator.init() style_indicator.set_bg_opa(lv.OPA.COVER) style_indicator.set_bg_color(lv.palette_main(lv.PALETTE.CYAN)) style_indicator.set_radius(lv.RADIUS.CIRCLE) style_indicator.set_transition(transition_dsc) style_knob.init() style_knob.set_bg_opa(lv.OPA.COVER) style_knob.set_bg_color(lv.palette_main(lv.PALETTE.CYAN)) style_knob.set_border_color(lv.palette_darken(lv.PALETTE.CYAN, 3)) style_knob.set_border_width(2) style_knob.set_radius(lv.RADIUS.CIRCLE)
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) # ********************************** # Start your codes here. # ********************************** # Create a style style = lv.style_t() lv.style_copy(style, lv.style_pretty_color) style.body.main_color = lv.color_hex3(0x666) # Line color at the beginning style.body.grad_color = lv.color_hex3(0x666) # Line color at the end style.body.padding.left = 10 # Scale line length style.body.padding.inner = 8 # Scale label padding style.body.border.color = lv.color_hex3(0x333) # Needle middle circle color style.line.width = 3 style.text.color = lv.color_hex3(0x333) style.line.color = lv.color_hex3(0xF00) # Line color after the critical value # Describe the color for the needles needle_colors = [ lv.color_make(0x00, 0x00, 0xFF), lv.color_make(0xFF, 0xA5, 0x00), lv.color_make(0x80, 0x00, 0x80) ]
# # A meter with multiple arcs # meter = lv.meter(lv.scr_act()) meter.center() meter.set_size(200, 200) # Remove the circle from the middle meter.remove_style(None, lv.PART.INDICATOR) # Add a scale first scale = meter.add_scale() meter.set_scale_ticks(scale, 11, 2, 10, lv.palette_main(lv.PALETTE.GREY)) meter.set_scale_major_ticks(scale, 1, 2, 30, lv.color_hex3(0xeee), 10) meter.set_scale_range(scale, 0, 100, 270, 90) # Add a three arc indicator indic1 = meter.add_arc(scale, 10, lv.palette_main(lv.PALETTE.RED), 0) indic2 = meter.add_arc(scale, 10, lv.palette_main(lv.PALETTE.GREEN), -10) indic3 = meter.add_arc(scale, 10, lv.palette_main(lv.PALETTE.BLUE), -20) # Create an animation to set the value a1 = lv.anim_t() a1.init() a1.set_values(0, 100) a1.set_time(2000) a1.set_repeat_delay(100) a1.set_playback_delay(100) a1.set_playback_time(500)
def __init__(self, color): super().__init__() self.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.set_bg_color(lv.STATE.DEFAULT, lv.color_hex3(color)) self.set_bg_grad_color(lv.STATE.DEFAULT, lv.color_hex3(0xFFF)) self.set_bg_grad_dir(lv.STATE.DEFAULT, lv.GRAD_DIR.VER)
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) style.line.width = 10 # 10 px thick arc style.line.color = lv.color_hex3(0x258) # Blueish arc color style.body.border.color = lv.color_hex3(0xBBB) # Gray background color style.body.border.width = 0 # 11 style.body.padding.left = 0 # Create a Preloader object preload = lv.preload(scr2) preload.set_size(100, 100) preload.align(None, lv.ALIGN.CENTER, -5, 5) # preload.set_style(lv.preload.STYLE.MAIN, style) preload.set_type(lv.preload.TYPE.FILLSPIN_ARC)
def __init__(self): scr = lv.obj() #############################create a gauge################################# # Create a style style = lv.style_t() lv.style_copy(style, lv.style_pretty_color) style.body.main_color = lv.color_hex3( 0x666) # Line color at the beginning style.body.grad_color = lv.color_hex3(0x666) # Line color at the end style.body.padding.left = 10 # Scale line length style.body.padding.inner = 8 # Scale label padding style.body.border.color = lv.color_hex3( 0x333) # Needle middle circle color style.line.width = 3 style.text.color = lv.color_hex3(0x333) style.line.color = lv.color_hex3( 0xF00) # Line color after the critical value # Describe the color for the needles needle_colors = [ lv.color_make(0x00, 0x00, 0xFF), lv.color_make(0xFF, 0xA5, 0x00), lv.color_make(0x80, 0x00, 0x80) ] # Create a gauge gauge1 = lv.gauge(scr) gauge1.set_style(lv.gauge.STYLE.MAIN, style) gauge1.set_needle_count(len(needle_colors), needle_colors) gauge1.set_size(200, 200) gauge1.align(None, lv.ALIGN.CENTER, 0, -50) # Set the values gauge1.set_value(0, 10) gauge1.set_value(1, 20) gauge1.set_value(2, 30) #################################explanation of needle############################ # Create a style for the LED #color for LED 1 style_led1 = lv.style_t() lv.style_copy(style_led1, lv.style_pretty_color) style_led1.body.radius = 800 # large enough to draw a circle style_led1.body.main_color = lv.color_make(0x00, 0x00, 0xFF) style_led1.body.border.width = 3 style_led1.body.border.opa = lv.OPA._30 style_led1.body.shadow.width = 5 # Create a LED 1 led1 = lv.led(scr) led1.set_style(lv.led.STYLE.MAIN, style_led1) led1.align(None, lv.ALIGN.CENTER, -40, 40) led1.on() btnLED1 = lv.btn(scr) btnLED1.align(lv.scr_act(), lv.ALIGN.CENTER, 30, 60) btnLED1.set_size(70, 30) labelLED1 = lv.label(btnLED1) labelLED1.set_text("Battery") #color for LED 2 style_led2 = lv.style_t() lv.style_copy(style_led2, lv.style_pretty_color) style_led2.body.radius = 800 # large enough to draw a circle style_led2.body.main_color = lv.color_make(0xFF, 0xA5, 0x00) style_led2.body.border.width = 3 style_led2.body.border.opa = lv.OPA._30 style_led2.body.shadow.width = 5 # Create a LED 2 led2 = lv.led(scr) led2.set_style(lv.led.STYLE.MAIN, style_led2) led2.align(None, lv.ALIGN.CENTER, -40, 85) led2.on() def event_handler(obj, event): lv.obj_del(scr) from thirdScreen import thirdScreen btnLED2 = lv.btn(scr) btnLED2.align(lv.scr_act(), lv.ALIGN.CENTER, 30, 105) btnLED2.set_size(70, 30) labelLED2 = lv.label(btnLED2) labelLED2.set_text("Memory") btnLED2.set_event_cb(event_handler) #color for LED 3 style_led3 = lv.style_t() lv.style_copy(style_led3, lv.style_pretty_color) style_led3.body.radius = 800 # large enough to draw a circle style_led3.body.main_color = lv.color_make(0x80, 0x00, 0x80) style_led3.body.border.width = 3 style_led3.body.border.opa = lv.OPA._30 style_led3.body.shadow.width = 5 # Create a LED 3 led3 = lv.led(scr) led3.set_style(lv.led.STYLE.MAIN, style_led3) led3.align(None, lv.ALIGN.CENTER, -40, 130) led3.on() btnLED3 = lv.btn(scr) btnLED3.align(lv.scr_act(), lv.ALIGN.CENTER, 30, 150) btnLED3.set_size(70, 30) labelLED3 = lv.label(btnLED3) labelLED3.set_text("RAM") lv.scr_load(scr)
def __init__(self, color): super().__init__() self.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.set_bg_color(lv.STATE.DEFAULT, lv.color_hex3(color))