def add_mnemonic_table(mnemonic, y=PADDING, scr=None): if scr is None: scr = lv.scr_act() cell_style = lv.style_t() lv.style_copy(cell_style, styles["theme"].style.label.prim) cell_style.body.opa = 0 cell_style.text.font = lv.font_roboto_22 num_style = lv.style_t() lv.style_copy(num_style, cell_style) num_style.text.opa = lv.OPA._40 table = lv.table(scr) table.set_col_cnt(4) table.set_row_cnt(12) table.set_col_width(0, 50) table.set_col_width(2, 50) table.set_col_width(1, 150) table.set_col_width(3, 150) table.set_style(lv.page.STYLE.BG, cell_style) table.set_style(lv.table.STYLE.CELL1, cell_style) table.set_style(lv.table.STYLE.CELL2, num_style) for i in range(12): table.set_cell_value(i, 0, "%d" % (i + 1)) table.set_cell_value(i, 2, "%d" % (i + 13)) table.set_cell_type(i, 0, lv.table.STYLE.CELL2) table.set_cell_type(i, 2, lv.table.STYLE.CELL2) table.align(scr, lv.ALIGN.IN_TOP_MID, 0, y) table_set_mnemonic(table, mnemonic) return table
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)
# Create a normal cell style style_cell1 = lv.style_t() style_cell1.init() style_cell1.set_border_width(lv.STATE.DEFAULT, 1) style_cell1.set_border_color(lv.STATE.DEFAULT, lv.color_make(0, 0, 0)) # Create a header cell style style_cell2 = lv.style_t() style_cell2.init() style_cell2.set_border_width(lv.STATE.DEFAULT, 1) style_cell2.set_border_color(lv.STATE.DEFAULT, lv.color_make(0, 0, 0)) style_cell2.set_bg_color(lv.STATE.DEFAULT, lv.color_make(0xC0, 0xC0, 0xC0)) style_cell2.set_bg_grad_color(lv.STATE.DEFAULT, lv.color_make(0xC0, 0xC0, 0xC0)) table = lv.table(lv.scr_act()) table.add_style(lv.table.PART.CELL1, style_cell1) table.add_style(lv.table.PART.CELL2, style_cell2) #table.add_style(lv.table.PART.BG, lv.style.transp_tight) table.set_col_cnt(2) table.set_row_cnt(4) table.align(None, lv.ALIGN.CENTER, 0, 0) # Make the cells of the first row center aligned table.set_cell_align(0, 0, lv.label.ALIGN.CENTER) table.set_cell_align(0, 1, lv.label.ALIGN.CENTER) # Make the cells of the first row TYPE = 2 (use `style_cell2`) table.set_cell_type(0, 0, 2) table.set_cell_type(0, 1, 2)
def home(): def btn_event(obj, info): print(obj) print(info) if info == 'add new': lv.scr_act().clean() add_new() def table_event_cb(e): row = lv.point_t() col = lv.point_t() lv.table.get_selected_cell(table, row, col) print("row :" + str(row.x)) print("col :" + str(col.x)) print("value :" + table.get_cell_value(row.x, col.x)) key = str(table.get_cell_value(row.x, col.x)) '''only show msgbox when column 0 is selected''' if col.x == 0: msb_edit_table(key) global tabledata tabledata = e return tabledata scr = lv.obj() scr.clean() lv.scr_load(scr) label = lv.label(scr) label.set_text("List of Triggers and Keys") label.align_to(scr, lv.ALIGN.TOP_LEFT, 10, 25) '''create table''' table = lv.table(scr) table.align_to(label, lv.ALIGN.OUT_BOTTOM_LEFT, 5, 5) table.set_col_cnt(4) table.set_col_width(0, 60) table.set_col_width(1, 80) table.set_col_width(2, 80) table.set_col_width(3, 70) table.set_cell_value(0, 0, "Keys") table.set_cell_value(0, 1, "Begin") table.set_cell_value(0, 2, "Dur(s)") table.set_cell_value(0, 3, "Arm") counter = 1 for key in db: '''fill table keys''' '''key''' table.set_cell_value(counter, 0, str(eval(key))) '''begin''' table.set_cell_value(counter, 1, (eval(db[str(eval(key))])['begin'])) '''duration''' table.set_cell_value(counter, 2, (eval(db[str(eval(key))])['duration'])) '''arm''' table.set_cell_value(counter, 3, str( (eval(db[str(eval(key))])['arm']))) counter += 1 '''Table event : get row and column''' table.add_event_cb(lambda e: table_event_cb(e), lv.EVENT.PRESSING, None) btn = lv.btn(scr) btn.align_to(table, lv.ALIGN.OUT_BOTTOM_LEFT, 5, 5) btn_lbl = lv.label(btn) btn_lbl.set_text('Add New') btn.add_event_cb(lambda e: btn_event(e, "add new"), lv.EVENT.CLICKED, None) btn2 = lv.btn(scr) btn2.align_to(btn, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) btn2_lbl = lv.label(btn2) btn2_lbl.set_text('Write to Btree DB') btn2.add_event_cb(lambda e: btn_event(e, "Save DB"), lv.EVENT.CLICKED, None) label2 = lv.label(scr) label2.align_to(btn, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) label2.set_text('Operation Log') textarea = lv.textarea(scr) textarea.align_to(label2, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) textarea.set_width(290) textarea.set_height(180) '''
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 table = lv.table(scr) table.set_size(300, 250) table.set_cell_value(0, 0, "Name") table.set_cell_value(0, 1, "Begin Time") table.set_cell_value(0, 2, "Dur") #table column width table.set_col_width(0, 110) table.set_col_width(1, 100) table.set_col_width(2, 90) table.align_to(header, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) table.add_event_cb(draw_part_event_cb, lv.EVENT.ALL, None) #populate the table from db_table for i in range(1, db_table.current_row): data = db_table.find_row(i)['d'] table.set_cell_value(i, 0, data["name"])
async def show_measurement_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 = ? measurement_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 measurement_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(measurement_screen) mtable.set_row_cnt(6) mtable.set_col_cnt(3) mtable.set_col_width(0, 120) mtable.set_col_width(1, 90) 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, "Noise") mtable.set_cell_value(1,0, "PM1.0") mtable.set_cell_value(2,0, "PM2.5") mtable.set_cell_value(3,0, "PM10.0") mtable.set_cell_value(4,0, "NO2") mtable.set_cell_value(5,0, "O3") mtable.set_cell_value(0,1, '{:.1f}'.format(repo.get('dba').current)) mtable.set_cell_value(1,1, '{}'.format(repo.get('pm10').current)) mtable.set_cell_value(2,1, '{}'.format(repo.get('pm25').current)) mtable.set_cell_value(3,1, '{}'.format(repo.get('pm100').current)) mtable.set_cell_value(4,1, '{:.1f}'.format(repo.get('no2').current)) mtable.set_cell_value(5,1, '{:.1f}'.format(repo.get('o3').current)) mtable.set_cell_value(0,2, "dB(A)") mtable.set_cell_value(1,2, "ug/m3") mtable.set_cell_value(2,2, "ug/m3") mtable.set_cell_value(3,2, "ug/m3") mtable.set_cell_value(4,2, "ppb") mtable.set_cell_value(5,2, "ppb") lv.scr_load(measurement_screen) self.backlight_ctrl.value(1)
#!/opt/bin/lv_micropython -i import lvgl as lv import display_driver import time table = lv.table(lv.scr_act(), None) table.set_col_cnt(2) table.set_row_cnt(4) table.set_size(200, 200) table.align(lv.scr_act(), lv.ALIGN.CENTER, -15, 0) # Make the cells of the first row center aligned table.set_col_width(0, 100) table.set_cell_align(0, 0, lv.label.ALIGN.CENTER) table.set_cell_align(0, 1, lv.label.ALIGN.CENTER) # Align the price values to the right in the 2nd column table.set_col_width(1, 100) table.set_cell_align(1, 1, lv.label.ALIGN.RIGHT) table.set_cell_align(2, 1, lv.label.ALIGN.RIGHT) table.set_cell_align(3, 1, lv.label.ALIGN.RIGHT) table.set_cell_type(0, 0, 2) table.set_cell_type(0, 1, 2) # Fill the first column table.set_cell_value(0, 0, "Name") table.set_cell_value(1, 0, "Apple") table.set_cell_value(2, 0, "Banana") table.set_cell_value(3, 0, "Citron")