def button_event(obj, question, answer): #check answer print("real answer : " + str(question.answer_real)) print("given answer :" + str(answer.get_text())) #if correct -> animate -> wait answer_int = int(answer.get_text()) if answer_int == question.answer_real: answer.set_text(lv.SYMBOL.RIGHT) obj.set_style_bg_color(lv.color_hex(0x0ed145), 0) print('Correct Answer') def gui_refresh_color(): obj.set_style_bg_color(lv.color_hex(0x0d47a1), 0) lv.timer_create(lambda task: gui_refresh_color(), 10, None) print(answer) if answer_int != question.answer_real: answer.set_text(lv.SYMBOL.CLOSE) obj.set_style_bg_color(lv.color_hex(0xfa3636), 0) def gui_refresh_color(): obj.set_style_bg_color(lv.color_hex(0x0d47a1), 0) lv.timer_create(lambda task: gui_refresh_color(), 10, None) print('Incorrect Answer') #if wrong -> animate -> wait #reset question reset_question()
def draw_part_event_cb(e): objc = e.get_code() objt = e.get_target() dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) s_row = lv.point_t() s_col = lv.point_t() if objc == lv.EVENT.PRESSING: '''only in effect if cell is pressed''' objt.get_selected_cell(s_row, s_col) print("selected row:{}, col:{}".format(s_row.x, s_col.x)) if objc == lv.EVENT.DRAW_PART_BEGIN: '''only change when draw part begins''' if dsc.part == lv.PART.ITEMS: #print('true!') row = dsc.id // objt.get_col_cnt() col = dsc.id - row * objt.get_col_cnt() #print("row : {}, column : {} ".format(row,col)) if row == 0: #change header style dsc.label_dsc.align = lv.TEXT_ALIGN.CENTER dsc.label_dsc.color = lv.color_hex(0xffffff) dsc.rect_dsc.bg_color = lv.color_hex(0x6b765b) if row > 0 and col > 0: #center colum 1 and 2 dsc.label_dsc.align = lv.TEXT_ALIGN.CENTER
def __init__(self, title, meta): send_amount = sum( [out["value"] for out in meta["outputs"] if not out["change"]]) super().__init__(title, "verify transaction and confirm") style = lv.style_t() lv.style_copy(style, self.message.get_style(0)) style.text.font = lv.font_roboto_mono_28 style_secondary = lv.style_t() lv.style_copy(style_secondary, self.message.get_style(0)) style_secondary.text.color = lv.color_hex(0x999999) style_secondary.text.font = lv.font_roboto_mono_22 style_warning = lv.style_t() lv.style_copy(style_warning, self.message.get_style(0)) style_warning.text.color = lv.color_hex(0xFF9A00) self.style = style self.style_secondary = style_secondary self.style_warning = style_warning obj = self.message num_change_outputs = 0 for out in meta["outputs"]: # first only show destination addresses if out["change"]: num_change_outputs += 1 continue obj = self.show_output(out, obj) if send_amount > 0: fee_percent = meta["fee"] * 100 / send_amount fee = add_label("Fee: %d satoshi (%.2f%%)" % (meta["fee"], fee_percent), scr=self.page) # back to wallet else: fee = add_label("Fee: %d satoshi" % (meta["fee"]), scr=self.page) fee.align(obj, lv.ALIGN.OUT_BOTTOM_MID, 0, 30) obj = fee if num_change_outputs > 0: obj = add_label("Change outputs:", scr=self.page, style="title") obj.align(fee, lv.ALIGN.OUT_BOTTOM_MID, 0, 30) for out in meta["outputs"]: # now show change if not out["change"]: continue obj = self.show_output(out, obj) # warning label for address gap limit if "warnings" in meta and len(meta["warnings"]) > 0: text = "WARNING!\n" + "\n".join(meta["warnings"]) self.warning = add_label(text, scr=self.page) self.warning.set_style(0, style_warning) self.warning.align(obj, lv.ALIGN.OUT_BOTTOM_MID, 0, 30)
def __init__(self, parent, width, height, x, y): self.x = x self.board = Button(parent, x=x, y=y, width=width, height=height) self.board_style = lv.style_t() lv.style_copy(self.board_style, self.board.lv_obj.get_style(lv.label.STYLE.MAIN)) self.board_style.body.main_color = lv.color_hex(0x000000) self.board_style.body.grad_color = lv.color_hex(0x000000) self.board_style.body.shadow.width = 0 self.board.lv_obj.set_style(lv.label.STYLE.MAIN, self.board_style)
def __init__(self, dev=False, usb=False, note=None): super().__init__("Device settings", "") if note is not None: self.note = add_label(note, style="hint", scr=self) self.note.align(self.title, lv.ALIGN.OUT_BOTTOM_MID, 0, 5) y = 70 usb_label = add_label("USB communication", y, scr=self.page) usb_hint = add_label( "If USB is enabled the device will be able " "to talk to your computer. This increases " "attack surface but sometimes makes it " "more convenient to use.", y + 40, scr=self.page, style="hint", ) self.usb_switch = lv.sw(self.page) self.usb_switch.align(usb_hint, lv.ALIGN.OUT_BOTTOM_MID, 0, 20) lbl = add_label(" OFF ON ", scr=self.page) lbl.align(self.usb_switch, lv.ALIGN.CENTER, 0, 0) if usb: self.usb_switch.on(lv.ANIM.OFF) # y += 200 # dev_label = add_label("Developer mode", y, scr=self.page) # dev_hint = add_label( # "In developer mode internal flash will " # "be mounted to your computer so you could " # "edit files, but your secrets will be visible as well. " # "Also enables interactive shell through miniUSB port.", # y + 40, # scr=self.page, # style="hint", # ) # self.dev_switch = lv.sw(self.page) # self.dev_switch.align(dev_hint, lv.ALIGN.OUT_BOTTOM_MID, 0, 20) # lbl = add_label(" OFF ON ", scr=self.page) # lbl.align(self.dev_switch, lv.ALIGN.CENTER, 0, 0) # if dev: # self.dev_switch.on(lv.ANIM.OFF) self.confirm_button.set_event_cb(on_release(self.update)) self.cancel_button.set_event_cb( on_release(lambda: self.set_value(None))) self.wipebtn = add_button(lv.SYMBOL.TRASH + " Wipe device", on_release(self.wipe), scr=self) self.wipebtn.align(self, lv.ALIGN.IN_BOTTOM_MID, 0, -140) style = lv.style_t() lv.style_copy(style, self.wipebtn.get_style(lv.btn.STYLE.REL)) style.body.main_color = lv.color_hex(0x951E2D) style.body.grad_color = lv.color_hex(0x951E2D) self.wipebtn.set_style(lv.btn.STYLE.REL, style)
def __init__(self, parent, width, height, x, y): super().__init__(parent, width, height, x, y) lv.style_copy(self.circle_style, lv.style_plain) self.circle_style.body.radius = lv.RADIUS.CIRCLE # self.circle_style.body.grad_color = lv.color_hex(0xff0000) # self.circle_style.body.main_color = lv.color_hex(0xff0000) # self.circle_style.body.border.color = lv.color_hex(0x0000ff) self.circle_style.body.main_color = lv.color_hex(0xffffff) self.circle_style.body.grad_color = lv.color_hex(0xc0c0c0) self.circle_style.body.border.color = lv.color_hex(0x000000) self.circle_style.body.border.width = 2 self.set_style(self.circle_style)
def __init__(self, buttons=[], title="What do you want to do?", note=None, y0=60, last=None): super().__init__() y = y0 self.title = add_label(title, style="title", scr=self) if note is not None: self.note = add_label(note, style="hint", scr=self) self.note.align(self.title, lv.ALIGN.OUT_BOTTOM_MID, 0, 5) y += self.note.get_height() self.page = lv.page(self) h = 800 - y - 20 self.page.set_size(480, h) self.page.set_y(y) y = 0 self.buttons = [] # value, text, enable, color for value, text, *args in buttons: if text is not None: if value is not None: enable = len(args) == 0 or args[0] if enable: cb = on_release(cb_with_args(self.set_value, value)) else: cb = None btn = add_button(text, cb, y=y, scr=self.page) if not enable: btn.set_state(lv.btn.STATE.INA) # color if len(args) > 1: color = args[1] style = lv.style_t() lv.style_copy(style, btn.get_style(lv.btn.STYLE.REL)) style.body.main_color = lv.color_hex(color) style.body.grad_color = lv.color_hex(color) btn.set_style(lv.btn.STYLE.REL, style) self.buttons.append(btn) y += 85 else: add_label(text.upper(), y=y + 10, style="hint", scr=self.page) y += 50 else: y += 40 if last is not None: self.add_back_button(*last) self.page.set_height(h - 100)
def __init__(self, app, page): self.app = app self.page = page self.chart = AnimatedChart(page, 100, 1000) self.chart.set_width(page.get_width() - 100) self.chart.align(page, lv.ALIGN.CENTER, 0, 0) self.series1 = self.chart.add_series(lv.color_hex(0xFF0000)) self.chart.set_type(self.chart.TYPE.POINT | self.chart.TYPE.LINE) self.chart.set_series_width(3) self.chart.set_range(0, 100) self.chart.init_points(self.series1, 10) self.chart.set_points(self.series1, [10, 20, 30, 20, 10, 40, 50, 90, 95, 90]) self.chart.set_x_tick_texts("a\nb\nc\nd\ne", 2, lv.chart.AXIS.DRAW_LAST_TICK) self.chart.set_x_tick_length(10, 5) self.chart.set_y_tick_texts("1\n2\n3\n4\n5", 2, lv.chart.AXIS.DRAW_LAST_TICK) self.chart.set_y_tick_length(10, 5) self.chart.set_div_line_count(3, 3) self.chart.set_margin(30) # Create a slider that controls the chart animation speed def on_slider_changed(obj=None, event=-1): self.chart.factor = self.slider.get_value() self.slider = lv.slider(page) self.slider.align(self.chart, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) self.slider.set_width(30) self.slider.set_height(self.chart.get_height()) self.slider.set_range(10, 200) self.slider.set_value(self.chart.factor, 0) self.slider.set_event_cb(on_slider_changed)
def __init__(self, wallet, network, idx=None, branch_index=0): self.wallet = wallet self.network = network self.idx = wallet.unused_recv addr, gap = wallet.get_address(self.idx, network=network, branch_index=branch_index) super().__init__( " " + wallet.name + " #708092 " + lv.SYMBOL.EDIT, format_addr(addr, words=4), "bitcoin:" + addr, qr_width=350, ) self.title.set_recolor(True) self.title.set_click(True) self.title.set_event_cb(on_release(self.rename)) self.policy = add_label(wallet.policy, y=55, style="hint", scr=self) style = lv.style_t() lv.style_copy(style, self.message.get_style(0)) style.text.font = lv.font_roboto_mono_22 self.message.set_style(0, style) # index self.branch_index = branch_index self.note = add_label("%s address #%d" % (self.prefix, self.idx), y=80, style="hint", scr=self) self.qr.align(self.note, lv.ALIGN.OUT_BOTTOM_MID, 0, 15) self.message.align(self.qr, lv.ALIGN.OUT_BOTTOM_MID, 0, 15) # warning label for address gap limit self.warning = add_label("", scr=self) self.warning.align(self.message, lv.ALIGN.OUT_BOTTOM_MID, 0, 15) style = lv.style_t() lv.style_copy(style, self.note.get_style(0)) style.text.color = lv.color_hex(0xFF9A00) self.warning.set_style(0, style) # delbtn = add_button("Delete wallet", on_release(cb_del), y=610) self.prv = add_button(lv.SYMBOL.LEFT, on_release(self.prev), scr=self) self.nxt = add_button(lv.SYMBOL.RIGHT, on_release(self.next), scr=self) if self.idx <= 0: self.prv.set_state(lv.btn.STATE.INA) self.prv.set_width(70) self.prv.align(self.qr, lv.ALIGN.OUT_LEFT_MID, -20, 0) self.prv.set_x(0) self.nxt.set_width(70) self.nxt.align(self.qr, lv.ALIGN.OUT_RIGHT_MID, 20, 0) self.nxt.set_x(HOR_RES - 70) self.menubtn = add_button(lv.SYMBOL.SETTINGS + " Settings", on_release(self.show_menu), scr=self) self.menubtn.align(self.close_button, lv.ALIGN.OUT_TOP_MID, 0, -20) if idx is not None: self.idx = idx self.update_address()
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 __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) 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._autoplay = True self.qr = lvqr.QRCode(self) self._text = "Text" self.version = self.QR_VERSION self._original_size = None self._press_start = None self.create_density_controls(style) self.create_playback_controls(style) self.note = lv.label(self) 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)
class Screen(lv.obj): network = 'test' COLORS = { 'main': lv.color_hex(0xFF9A00), 'test': lv.color_hex(0x00F100), 'regtest': lv.color_hex(0x00CAF1), 'signet': lv.color_hex(0xBD10E0), } def __init__(self): super().__init__() self.waiting = True self._value = None if type(self).network in type(self).COLORS: self.topbar = lv.obj(self) s = lv.style_t() lv.style_copy(s, styles["theme"].style.btn.rel) s.body.main_color = type(self).COLORS[type(self).network] s.body.grad_color = type(self).COLORS[type(self).network] s.body.opa = 200 s.body.radius = 0 s.body.border.width = 0 self.topbar.set_style(s) self.topbar.set_size(HOR_RES, 5) self.topbar.set_pos(0, 0) def release(self): self.waiting = False def get_value(self): """ Redefine this function to get value entered by the user """ return self._value def set_value(self, value): self._value = value self.release() async def result(self): self.waiting = True while self.waiting: await asyncio.sleep_ms(10) return self.get_value()
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)
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)
def __init__(self, lv_cont=None, size_x=0, size_y=0, digit_margin=10): self.cont_main = lv_cont self.size_x = size_x self.pos_x = 0 self.size_y = size_y self.pos_y = 0 self.digit_margin = digit_margin self.digit_width = int((size_x - (digit_margin * 9)) / 8) self.digit_height = int(size_y - (digit_margin * 2)) self.time = time.time() (self.year, self.month, self.mday, self.hour, self.minute, self.second, self.weekday, self.yearday) = time.localtime() # Line Style self.line_style = lv.style_t() self.line_style.init() self.line_style.set_line_width(lv.STATE.DEFAULT, 2) self.line_style.set_line_color(lv.STATE.DEFAULT, lv.color_hex(0x0000ff)) self.line_style.set_line_rounded(lv.STATE.DEFAULT, True) self.line_style.set_pad_all(lv.STATE.DEFAULT, 0) self.line_style.set_margin_all(lv.STATE.DEFAULT, 0) # Container Style self.cont_style = lv.style_t() self.cont_style.init() self.cont_style.set_pad_all(lv.STATE.DEFAULT, 1) self.cont_style.set_margin_all(lv.STATE.DEFAULT, 1) # self.cont_style.set_border_opa(lv.STATE.DEFAULT, lv.OPA.TRANSP) # self.cont_style.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.TRANSP) # dont nedd -> cont_style.set_bg_color(lv.STATE.DEFAULT, styles.LV_COLOR_WATCH) # Digit Container Style self.cont_dstyle = lv.style_t() self.cont_dstyle.init() self.cont_dstyle.set_pad_all(lv.STATE.DEFAULT, 5) self.cont_dstyle.set_margin_all(lv.STATE.DEFAULT, 5) # self.cont_style.set_border_opa(lv.STATE.DEFAULT, lv.OPA.TRANSP) # self.cont_style.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.TRANSP) # dont nedd -> cont_style.set_bg_color(lv.STATE.DEFAULT, styles.LV_COLOR_WATCH) # Setup Main Parent container if self.cont_main is not None: #self.cont_main = lv.cont(lv_scr) # self.cont_main.set_auto_realign(True) self.cont_main.set_size(size_x, size_y) self.cont_main.set_fit(lv.FIT.NONE) #self.cont_main.set_layout(lv.LAYOUT.PRETTY_MID) self.cont_main.set_layout(lv.LAYOUT.ROW_MID) self.cont_main.add_style(self.cont_main.PART.MAIN, self.cont_style) # 12:34:56 self.digit_pts = []
def get_style_text(size, color='000000'): if size not in gstyle_text_fonts: size = 14 style = lv.style_t() style.init() style.set_text_font(lv.STATE.DEFAULT, gstyle_text_fonts[size][1]) # style.set_text_font(lv.STATE.DEFAULT, myfont_cn) style.set_text_color(lv.STATE.DEFAULT, lv.color_hex(int('0x{}'.format(color)))) return style
def __init__(self, app, page): self.app = app self.page = page self.chart = lv.chart(page) self.chart.set_width(page.get_width() - 50) self.chart.align(page, lv.ALIGN.CENTER, 0, 0) self.series1 = self.chart.add_series(lv.color_hex(0xFF0000)) self.chart.set_type(self.chart.TYPE.POINT | self.chart.TYPE.LINE) self.chart.set_series_width(3) self.chart.set_range(0, 100) self.chart.init_points(self.series1, 10) self.chart.set_points(self.series1, [10, 20, 30, 20, 10, 40, 50, 90, 95, 90]) animate_chart(self.chart, 100, 1000)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.label = lv.label(self) self._text = "Text" self.label.set_long_mode(lv.label.LONG.BREAK) self.label.set_align(lv.label.ALIGN.CENTER) 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)
async def show_decibel_screen(self): # # Decibel screen # decibel_screen = lv.obj() dba = repo.get('dba').current screenstyle = lv.style_t(lv.style_plain) # 0xFF, 0x00, 0x00 Red # 0xC0, 0xC0, 0xC0 Silver # 0xFF, 0xA5, 0x00 Orange # set background color, with no gradient # set background and text color based on dBA reading if dba < 70: bg_color = lv.color_hex(0x00FF00) # green text_color = lv.color_hex(0x000000) # black elif dba < 85: bg_color = lv.color_hex(0xFFFF00) # yellow text_color = lv.color_hex(0x000000) # black else: bg_color = lv.color_hex(0xFF0000) # red text_color = lv.color_hex(0xFFFFFF) # white screenstyle.body.grad_color = bg_color screenstyle.body.main_color = bg_color #screenstyle.body.border.color = lv.color_hex(0xe32a19) #screenstyle.body.border.width = 5 screenstyle.text.color = text_color screenstyle.text.font = lv.font_roboto_120 decibel_screen.set_style(screenstyle) reading = lv.label(decibel_screen) reading.set_x(40) reading.set_y(70) reading.set_text('{:.1f}'.format(dba)) unit = lv.label(decibel_screen) unitstyle = lv.style_t(lv.style_plain) unitstyle.text.color = text_color unitstyle.text.font = lv.font_roboto_28 unit.set_style(lv.label.STYLE.MAIN, unitstyle) unit.set_x(215) unit.set_y(170) unit.set_text("dBA") lv.scr_load(decibel_screen) self.backlight_ctrl.value(1)
def __init__(self, manifest: DandelionAppManifest): super().__init__(manifest) self.container = super().get_container() self.container.set_style_local_bg_color(lv.cont.PART.MAIN, lv.STATE.DEFAULT, lv.color_hex(0x000000)) self.manifests = Dandelion.discoverApplicationManifests() # Count apps self.numberOfApps = 0 for m in self.manifests: if m.visibleInLauncher: self.numberOfApps += 1 self.numberOfColumns = self.container.get_width() // 100 # Scrollview self.scrollview = lv.page(self.container) self.scrollview.set_size(self.container.get_width(), self.container.get_height()) self.scrollview.align(self.container, lv.ALIGN.IN_TOP_LEFT, 0, 0) self.scrollview.set_style_local_bg_opa(lv.page.PART.BG, lv.STATE.DEFAULT, lv.OPA._0) # Group self.scrollgroup = lv.group_create() # Populate pages index = 0 for m in filter(lambda x: (x.visibleInLauncher), self.manifests): i = SpringboardIcon(self.scrollview, m) self.scrollgroup.add_obj(i) index += 1 super().start()
def __init__(self, page): self.cbuf = bytearray(CANVAS_WIDTH * CANVAS_HEIGHT * 4) # create a canvas self.canvas = lv.canvas(page, None) self.canvas.set_buffer(self.cbuf,CANVAS_WIDTH,CANVAS_HEIGHT,lv.img.CF.TRUE_COLOR) self.canvas.align(page,lv.ALIGN.CENTER,0,0) self.clear(); # prepare line self.line_dsc = lv.draw_line_dsc_t() self.line_dsc.init() self.line_dsc.color = lv.color_hex(0xff0000); self.line_dsc.opa = lv.OPA.COVER self.color_state = (0,0) self.x = 0 self.y = CANVAS_HEIGHT-1 self.state = 0 # the line drawing is done by a task so it doesn't interfere # with LVGL itself self.task = lv.task_create(self.line_task, 10, lv.TASK_PRIO.MID, None);
def __init__(self, app, page): self.app = app self.page = page self.page.set_flex_flow(lv.FLEX_FLOW.ROW) self.page.set_flex_align(lv.FLEX_ALIGN.SPACE_EVENLY, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER) self.page.set_style_pad_all(10, lv.PART.MAIN) self.page.set_style_pad_gap(10, lv.PART.MAIN) self.chart = AnimatedChart(page, 100, 1000) self.chart.set_flex_grow(1) self.chart.set_height(lv.pct(100)) self.series1 = self.chart.add_series(lv.color_hex(0xFF0000), self.chart.AXIS.PRIMARY_Y) self.chart.set_type(self.chart.TYPE.LINE) self.chart.set_style_line_width(3, lv.PART.ITEMS) self.chart.add_style(ColorStyle(0x055), lv.PART.ITEMS) self.chart.set_range(self.chart.AXIS.PRIMARY_Y, 0, 100) self.chart.set_point_count(10) self.chart.set_ext_y_array(self.series1, [10, 20, 30, 20, 10, 40, 50, 90, 95, 90]) # self.chart.set_x_tick_texts("a\nb\nc\nd\ne", 2, lv.chart.AXIS.DRAW_LAST_TICK) # self.chart.set_x_tick_length(10, 5) # self.chart.set_y_tick_texts("1\n2\n3\n4\n5", 2, lv.chart.AXIS.DRAW_LAST_TICK) # self.chart.set_y_tick_length(10, 5) self.chart.set_div_line_count(5, 5) # Create a slider that controls the chart animation speed def on_slider_changed(event): self.chart.factor = self.slider.get_value() self.slider = lv.slider(page) self.slider.set_size(10, lv.pct(100)) self.slider.set_range(10, 200) self.slider.set_value(self.chart.factor, 0) self.slider.add_event_cb(on_slider_changed, lv.EVENT.VALUE_CHANGED, None)
def __init__(self, page): self.page = page self.chart = AnimatedChart(page, 100, 1000) self.chart.set_width(page.get_width() - 80) self.series1 = self.chart.add_series(lv.color_hex(0xFF0000)) self.chart.set_type(self.chart.TYPE.LINE) self.chart.set_style_local_line_width(self.chart.PART.SERIES, lv.STATE.DEFAULT, 3) self.chart.add_style(self.chart.PART.SERIES, ColorStyle(0x055)) self.chart.add_style(self.chart.PART.BG, ChartPaddingStyle()) self.chart.set_y_range(self.chart.AXIS.PRIMARY_Y, 0, 100) self.chart.init_points(self.series1, 10) self.chart.set_points(self.series1, [10, 20, 30, 20, 10, 40, 50, 90, 95, 90]) self.chart.set_x_tick_texts("a\nb\nc\nd\ne", 2, lv.chart.AXIS.DRAW_LAST_TICK) self.chart.set_x_tick_length(10, 5) self.chart.set_y_tick_texts("1\n2\n3\n4\n5", 2, lv.chart.AXIS.DRAW_LAST_TICK) self.chart.set_y_tick_length(10, 5) self.chart.set_div_line_count(3, 3) self.chart.set_height(page.get_height() - 60) self.chart.align(page, lv.ALIGN.CENTER, 0, 0) # Create a slider that controls the chart animation speed def on_slider_changed(obj=None, event=-1): self.chart.factor = self.slider.get_value() self.slider = lv.slider(page) self.slider.align(self.chart, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) self.slider.set_width(10) self.slider.set_height(self.chart.get_height()) self.slider.set_range(10, 200) self.slider.set_value(self.chart.factor, 0) self.slider.set_event_cb(on_slider_changed)
self.val + self.size, -self.size, lambda a, val: self.set_range(0, val), lv.anim_path_ease_out, ready_cb=lambda a: self.anim_phase1(), time=(self.min * self.factor) // 100, ) # Create the chart scr = lv.obj() chart = AnimatedChart(scr, 100, 1000) chart.set_width(scr.get_width() - 100) chart.align(scr, lv.ALIGN.CENTER, 0, 0) series1 = chart.add_series(lv.color_hex(0xFF0000)) chart.set_type(chart.TYPE.POINT | chart.TYPE.LINE) chart.set_series_width(3) chart.set_range(0, 100) chart.init_points(series1, 10) chart.set_points(series1, [10, 20, 30, 20, 10, 40, 50, 90, 95, 90]) chart.set_x_tick_texts("a\nb\nc\nd\ne", 2, lv.chart.AXIS.DRAW_LAST_TICK) chart.set_x_tick_length(10, 5) chart.set_y_tick_texts("1\n2\n3\n4\n5", 2, lv.chart.AXIS.DRAW_LAST_TICK) chart.set_y_tick_length(10, 5) chart.set_div_line_count(3, 3) chart.set_margin(30) # Create a slider that controls the chart animation speed
import lvgl as lv import qrcode import math import gc qr_style = lv.style_t() qr_style.body.main_color = lv.color_hex(0xffffff) qr_style.body.grad_color = lv.color_hex(0xffffff) qr_style.body.opa = 255 qr_style.text.opa = 255 qr_style.text.color = lv.color_hex(0) qr_style.text.line_space = 0 qr_style.text.letter_space = 0 class QRCode(lv.label): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._text = "Text" self.set_long_mode(lv.label.LONG.BREAK) self.set_align(lv.label.ALIGN.CENTER) self.set_text(self._text) def set_text(self, text="Text"): if self._text != text: print("QR on screen:", text) self._text = text qr = qrcode.encode_to_string(text) size = int(math.sqrt(len(qr))) # + 4 clear space on every side width = self.get_width() scale = width//size sizes = range(1,10)
def __init__(self): self.rampath = mount_sdram() self.gui = SpecterGUI() Screen.COLORS["none"] = lv.color_hex(0xeeeeee) Screen.network = "none" self.qr = None
except: print("Can not get time!") ############################################# ################Basic Object################# ############################################# if TOUCH_READY: 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)
def blockly_to_lvgl_color(colour): return lv.color_hex(int(colour[1:], 16))
def widget_set_colour(obj, colour): if not obj in sys.modules['llvgl'].config["objects"]: return if colour == None: return; # colour may actually be an array of colours try: len(colour) # this triggers an exception for non-arrays color = [ ] for c in colour: color.append(blockly_to_lvgl_color(c)) except: color = [ blockly_to_lvgl_color(colour) ] if len(color) < 1: return # prepare some useful colors light = lv.color_t.color_lighten(color[0], lv.OPA._30) dark = lv.color_t.color_darken(color[0], lv.OPA._20) darker = lv.color_t.color_darken(color[0], lv.OPA._50) text = None if lv.color_t.color_brightness(color[0]) < 128: text = lv.color_hex(0xffffff) darktext = lv.color_hex(0xd0d0d0) # use color depending on object type. We have disabled focus highlighting, so # we don't care for focus colors lv_obj = obj["lv_obj"] if obj["type"] == TYPE.LABEL: lv_obj.set_style_local_text_color(lv.btn.PART.MAIN, lv.STATE.DEFAULT, color[0]) elif obj["type"] == TYPE.BUTTON: lv_obj.set_style_local_bg_color(lv.btn.PART.MAIN, lv.STATE.DEFAULT, color[0]) lv_obj.set_style_local_border_color(lv.btn.PART.MAIN, lv.STATE.DEFAULT, dark) lv_obj.set_style_local_bg_color(lv.btn.PART.MAIN, lv.STATE.PRESSED, dark) lv_obj.set_style_local_border_color(lv.btn.PART.MAIN, lv.STATE.PRESSED, darker) if text: lv_obj.set_style_local_text_color(lv.btn.PART.MAIN, lv.STATE.DEFAULT, text) lv_obj.set_style_local_text_color(lv.btn.PART.MAIN, lv.STATE.PRESSED, darktext) elif obj["type"] == TYPE.SWITCH: lv_obj.set_style_local_bg_color(lv.switch.PART.KNOB, lv.STATE.DEFAULT, color[0]) lv_obj.set_style_local_bg_color(lv.switch.PART.INDIC, lv.STATE.DEFAULT, dark) elif obj["type"] == TYPE.SLIDER: lv_obj.set_style_local_bg_color(lv.switch.PART.KNOB, lv.STATE.DEFAULT, color[0]) lv_obj.set_style_local_bg_color(lv.switch.PART.INDIC, lv.STATE.DEFAULT, dark) elif obj["type"] == TYPE.CHECKBOX: lv_obj.set_style_local_bg_color(lv.checkbox.PART.BULLET, lv.STATE.DEFAULT, color[0]) lv_obj.set_style_local_border_color(lv.checkbox.PART.BULLET, lv.STATE.DEFAULT, dark) lv_obj.set_style_local_bg_color(lv.checkbox.PART.BULLET, lv.STATE.CHECKED, dark) lv_obj.set_style_local_border_color(lv.checkbox.PART.BULLET, lv.STATE.CHECKED, darker) lv_obj.set_style_local_bg_color(lv.checkbox.PART.BULLET, lv.STATE.PRESSED, dark) lv_obj.set_style_local_border_color(lv.checkbox.PART.BULLET, lv.STATE.PRESSED, darker) lv_obj.set_style_local_bg_color(lv.checkbox.PART.BULLET, lv.STATE.CHECKED | lv.STATE.PRESSED, darker) lv_obj.set_style_local_border_color(lv.checkbox.PART.BULLET, lv.STATE.CHECKED | lv.STATE.PRESSED, darker) elif obj["type"] == TYPE.LED: lv_obj.set_style_local_bg_color(lv.led.PART.MAIN, lv.STATE.DEFAULT, color[0]) lv_obj.set_style_local_border_color(lv.led.PART.MAIN, lv.STATE.DEFAULT, light) lv_obj.set_style_local_shadow_color(lv.led.PART.MAIN, lv.STATE.DEFAULT, color[0]) elif obj["type"] == TYPE.CHART: # setting colors on a chart actually does quite some magic as this is what # creates the charts series obj["series"] = [ ] for c in color: obj["series"].append(lv_obj.add_series(c)) elif obj["type"] == TYPE.GAUGE: lv_obj.set_needle_count(len(color), color) elif obj["type"] == TYPE.DROPDOWN: lv_obj.set_style_local_bg_color(lv.dropdown.PART.MAIN, lv.STATE.DEFAULT, color[0]) lv_obj.set_style_local_border_color(lv.dropdown.PART.MAIN, lv.STATE.DEFAULT, dark) lv_obj.set_style_local_bg_color(lv.dropdown.PART.MAIN, lv.STATE.PRESSED, dark) lv_obj.set_style_local_border_color(lv.dropdown.PART.MAIN, lv.STATE.PRESSED, darker) lv_obj.set_style_local_border_color(lv.dropdown.PART.MAIN, lv.STATE.FOCUSED, darker) lv_obj.set_style_local_bg_color(lv.dropdown.PART.SELECTED, lv.STATE.DEFAULT, color[0]) # toggle between black and white color based on the darkness of the given color if text: lv_obj.set_style_local_text_color(lv.dropdown.PART.MAIN, lv.STATE.DEFAULT, text) lv_obj.set_style_local_text_color(lv.dropdown.PART.MAIN, lv.STATE.PRESSED, darktext) else: print("set color not supported");
#!/opt/bin/lv_micropython -i import lvgl as lv import display_driver display_driver.getdisplay_landscape() CANVAS_WIDTH = 50 CANVAS_HEIGHT = 50 LV_COLOR_CHROMA_KEY = lv.color_hex(0x00ff00) def LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h): return int(((w / 8) + 1) * h) def LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h): return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) + 4 * 2 def LV_CANVAS_BUF_SIZE_INDEXED_1BIT(w, h): return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h) # # Create a transparent canvas with Chroma keying and indexed color format (palette). # # Create a button to better see the transparency btn=lv.btn(lv.scr_act()) # Create a buffer for the canvas cbuf= bytearray(LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)) # Create a canvas and initialize its the palette