def main_page(self,tile_num): self.calculator_tile = self.mainbar.get_tile_obj(tile_num); self.calculator_style = lv.style_t() self.calculator_style.copy(self.mainbar.get_style()) # create the number textarea self.ta = lv.textarea(self.calculator_tile,None) self.ta.set_size(200,40) self.ta.align(None,lv.ALIGN.IN_TOP_MID,0,10) self.ta.set_text("0") # create a button matrix self.btnm = lv.btnmatrix(self.calculator_tile,None) self.btnm.set_map(self.btnm_map) self.btnm.set_ctrl_map(self.btnm_ctlr_map) self.btnm.set_width(226) self.btnm.align(self.ta,lv.ALIGN.OUT_BOTTOM_MID,0,10) # attach the callback self.btnm.set_event_cb(self.event_handler) # create the exit button exit_btn = lv.imgbtn(self.calculator_tile,None) exit_btn.set_src(lv.btn.STATE.RELEASED,self.mainbar.get_exit_btn_dsc()) exit_btn.add_style(lv.imgbtn.PART.MAIN,self.calculator_style) exit_btn.align(self.calculator_tile,lv.ALIGN.IN_BOTTOM_LEFT, 10, -10 ) self.log.debug("setting up exit callback") exit_btn.set_event_cb(self.exit_calculator_app_event_cb) self.calculator_style.set_text_opa(lv.obj.PART.MAIN, lv.OPA.COVER)
def lv_btnmatrix(screen): # Button matrix map btnm_map = ["1", "2", "3", "\n", "4", "5", "6", ""] # Create button matrix btnmatrix = lv.btnmatrix(screen) # Set the map (map must end with empty element of core dump!) btnmatrix.set_map(btnm_map)
def __init__(self, parent): # create the number textarea self.ta = lv.textarea(parent, None) self.ta.set_size(200, 40) self.ta.align(None, lv.ALIGN.IN_TOP_MID, 0, 10) self.ta.set_text("0") # create a button matrix self.btnm = lv.btnmatrix(parent, None) self.btnm.set_map(self.btnm_map) self.btnm.set_ctrl_map(self.btnm_ctlr_map) self.btnm.set_width(226) self.btnm.align(self.ta, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) # attach the callback self.btnm.set_event_cb(self.event_handler)
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)
style_bg.set_clip_corner(True) style_bg.set_radius(lv.RADIUS.CIRCLE) style_bg.set_border_width(0) style_btn = lv.style_t() style_btn.init() style_btn.set_radius(0) style_btn.set_border_width(1) style_btn.set_border_opa(lv.OPA._50) style_btn.set_border_color(lv.palette_main(lv.PALETTE.GREY)) style_btn.set_border_side(lv.BORDER_SIDE.INTERNAL) style_btn.set_radius(0) map = [lv.SYMBOL.LEFT, "1", "2", "3", "4", "5", lv.SYMBOL.RIGHT, ""] btnm = lv.btnmatrix(lv.scr_act()) btnm.set_map(map) btnm.add_style(style_bg, 0) btnm.add_style(style_btn, lv.PART.ITEMS) btnm.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None) btnm.set_size(225, 35) # Allow selecting on one number at time btnm.set_btn_ctrl_all(lv.btnmatrix.CTRL.CHECKABLE) btnm.clear_btn_ctrl(0, lv.btnmatrix.CTRL.CHECKABLE) btnm.clear_btn_ctrl(6, lv.btnmatrix.CTRL.CHECKABLE) btnm.set_one_checked(True) btnm.set_btn_ctrl(1, lv.btnmatrix.CTRL.CHECKED) btnm.center()
def m4(): position = 0 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) cont.set_style_local_radius(0, 0, 0) #dropdown - event def drop_event(obj, event): if event == lv.EVENT.VALUE_CHANGED: position = drop.get_selected() print("changing trigger position to {}".format(str(position))) m4_1(position) #call to refresh roller position #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" ) drop.set_event_cb(drop_event) #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") tab4 = tab.add_tab("Desc") ####Tab 1 #label lbl1 = lv.label(cont) lbl1.set_text("Arm?") #switch switch = lv.switch(cont) lbl2 = lv.label(tab1) lbl2.set_text("Set time to begin trigger :") lbl2.align(tab1, lv.ALIGN.IN_TOP_MID, 0, 10) #contain - sort vert cont2 = lv.cont(tab1) cont2.align(lbl2, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) cont2.set_auto_realign(True) cont2.set_layout(lv.LAYOUT.ROW_MID) cont2.set_fit(lv.FIT.TIGHT) roller_hour = lv.roller(cont2) roller_hour.set_options( "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23", lv.roller.MODE.NORMAL) roller_minute = lv.roller(cont2) roller_minute.set_options( "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59", lv.roller.MODE.NORMAL) roller_sec = lv.roller(cont2) roller_sec.set_options( "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59", lv.roller.MODE.NORMAL) btn = lv.btn(cont2) lbl_btn = lv.label(btn) lbl_btn.set_text("SET") #duration lbl3 = lv.label(tab1) lbl3.set_text("Set duration for trigger : ") lbl3.align(cont2, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) cont3 = lv.cont(tab1) cont3.align(lbl3, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) cont3.set_auto_realign(True) cont3.set_layout(lv.LAYOUT.ROW_MID) cont3.set_fit(lv.FIT.TIGHT) roller_hour_dur = lv.roller(cont3) roller_hour_dur.set_options( "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23", lv.roller.MODE.NORMAL) roller_minute_dur = lv.roller(cont3) roller_minute_dur.set_options( "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59", lv.roller.MODE.NORMAL) roller_sec_dur = lv.roller(cont3) roller_sec_dur.set_options( "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59", lv.roller.MODE.NORMAL) #button (set timer) - event def btn_event(obj, event): if obj == btn and event == lv.EVENT.CLICKED: position = drop.get_selected() trigger[position].bhour = roller_hour.get_selected() trigger[position].bminute = roller_minute.get_selected() trigger[position].bsecond = roller_sec.get_selected() print("btn - event : position {}, bhour {}, bminute {}, bsec{}". format(str(position), str(roller_hour.get_selected()), str(roller_minute.get_selected()), str(roller_sec.get_selected()))) if obj == btn2 and event == lv.EVENT.CLICKED: position = drop.get_selected() trigger[position].hourdur = roller_hour_dur.get_selected() trigger[position].minutedur = roller_minute_dur.get_selected() trigger[position].seconddur = roller_sec_dur.get_selected() print("btn2 - event") if obj == switch and event == lv.EVENT.VALUE_CHANGED: position = drop.get_selected() trigger[position].isArmed = switch.get_state() print("Arming trigger {}".format(switch.get_state())) if obj == btn_t4_1 and event == lv.EVENT.CLICKED: m5() btn2 = lv.btn(cont3) lbl_btn2 = lv.label(btn2) lbl_btn2.set_text("SET") #button event call btn.set_event_cb(btn_event) btn2.set_event_cb(btn_event) switch.set_event_cb(btn_event) def m4_1(_position): #run after dropdown selected or pos 0 default position = _position print("M4_1() calling position {}".format(position)) roller_hour.set_selected(trigger[position].bhour, lv.ANIM.ON) roller_minute.set_selected(trigger[position].bminute, lv.ANIM.ON) roller_sec.set_selected(trigger[position].bsecond, lv.ANIM.ON) roller_hour_dur.set_selected(trigger[position].hourdur, lv.ANIM.ON) roller_minute_dur.set_selected(trigger[position].minutedur, lv.ANIM.ON) roller_sec_dur.set_selected(trigger[position].seconddur, lv.ANIM.ON) #set proper state of switch if switch.get_state() != trigger[position].isArmed: switch.toggle(lv.ANIM.ON) m4_1(position) #####Tab 2 - Automation tab2.set_height(320) lbl_t2 = lv.label(tab2) lbl_t2.align(tab1, lv.ALIGN.IN_TOP_MID, 210, 10) lbl_t2.set_text("Automatic trigger disable settings") cont3 = lv.cont(tab2) cont3.set_auto_realign(True) cont3.set_layout(lv.LAYOUT.PRETTY_MID) cont3.align(lbl_t2, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) cont3.set_fit2(lv.FIT.TIGHT, lv.FIT.TIGHT) lbl_t2_2 = lv.label(cont3) lbl_t2_2.set_text("Enable Flow Sensor") switch_t2_1 = lv.switch(cont3) lbl_t2_3 = lv.label(cont3) lbl_t2_3.set_text("Enable Rain Sensor") switch_t2_2 = lv.switch(cont3) lbl_t2_4 = lv.label(cont3) lbl_t2_4.set_text("Enable MET weather API") switch_t2_3 = lv.switch(cont3) lbl_t2_5 = lv.label(cont3) lbl_t2_5.set_text("Enable Soil Sensor") switch_t2_4 = lv.switch(cont3) gauge_t2 = lv.gauge(tab2) gauge_t2.align(cont3, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) ####Tab 3 - Switches tab3.set_height(320) lbl_t3 = lv.label(tab3) lbl_t3.align(tab3, lv.ALIGN.IN_TOP_MID, -80, 10) lbl_t3.set_text("Assign Pin to be triggered") #page4 = lv.page(tab3) #page4.set_auto_realign(True) #page4.align(lbl_t3, lv.ALIGN.OUT_BOTTOM_MID,0,10) #page4.set_size(290,800) btnmtx_t3 = lv.btnmatrix(tab3) btnmtx_t3.align(lbl_t3, lv.ALIGN.OUT_BOTTOM_MID, 0, 0) btnmtx_t3.set_width(250) btnmtx_t3.set_height(600) btn_map_t3 = [ "3.3v", "GND", "\n", "EN", "23", "\n", "36", "22", "\n", "39", "01", "\n", "34", "03", "\n", "35", "21", "\n", "32", "GND", "\n", "33", "19", "\n", "25", "18", "\n", "26", "05", "\n", "27", "17", "\n", "14", "16", "\n", "12", "04", "\n", "GND", "00", "\n", "13", "02", "\n", "09", "15", "\n", "10", "08", "\n", "11", "07", "\n", "VIN", "06", "" ] btnmtx_t3.set_map(btn_map_t3) btnmtx_t3.set_btn_ctrl_all(btnmtx_t3.CTRL.CHECKABLE) btn_t3_save = lv.btn(tab3) btn_t3_save.align(btnmtx_t3, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) lbl_btn_t3_save = lv.label(btn_t3_save) lbl_btn_t3_save.set_text("Save Toggles") #### Tab 4 Description btn_t4_1 = lv.btn(tab4) btn_t4_1.align(tab4, lv.ALIGN.CENTER, 0, 0) btn_t4_1.set_event_cb(btn_event) lbl_btn_t4_1 = lv.label(btn_t4_1) lbl_btn_t4_1.set_text(lv.SYMBOL.HOME)