def __init__(self, page, screen): self.page = page self.screen = screen self.win = None # for fake run #self.fake_cmd = None #self.fake_task = lv.task_create(self.fake, 5000, lv.TASK_PRIO.MID, None); # create a task to check for commands from http_server self.http_task = lv.task_create(self.http_server_poll, 100, lv.TASK_PRIO.MID, None) # create a checkbox self.button = lv.checkbox(page) self.button.set_text("SD Card") self.button.align(page, lv.ALIGN.IN_TOP_LEFT, 16, 10) self.button.set_event_cb(self.event_handler) if not hasattr(machine, "SDCard"): self.button.set_disabled() # reload button self.reload_btn = lv.btn(page) self.reload_btn.set_size(32, 32) self.reload_btn.align(page, lv.ALIGN.IN_TOP_RIGHT, -12, 4) self.reload_btn.set_event_cb(self.on_reload_btn) lv.label(self.reload_btn).set_text(lv.SYMBOL.REFRESH) # List of Apps self.list = lv.list(page) self.list.set_size(216, 216) self.list.align(page, lv.ALIGN.IN_TOP_MID, 0, 38) self.reload()
def widget_new(type, parm = None): config = sys.modules['llvgl'].config content = config["win"].get_content() lv_obj = None if type == TYPE.LABEL: lv_obj = lv.label(content) elif type == TYPE.BUTTON: lv_obj = lv.btn(content) # buttons don't scale with the content by default lv_obj.set_fit(lv.FIT.TIGHT) # MAX, NONE, PARENT, TIGHT elif type == TYPE.SWITCH: lv_obj = lv.switch(content) elif type == TYPE.SLIDER: lv_obj = lv.slider(content) # sliders default width is too wide for the 240x320 screen lv_obj.set_width(180) elif type == TYPE.CHECKBOX: lv_obj = lv.checkbox(content) elif type == TYPE.LED: lv_obj = lv.led(content) # leds default size is a little big for the 240x320 screen lv_obj.set_size(30,30) elif type == TYPE.GAUGE: lv_obj = lv.gauge(content) elif type == TYPE.CHART: lv_obj = lv.chart(content) # leds default size is a little big for the 240x320 screen lv_obj.set_size(180,180) elif type == TYPE.DROPDOWN: lv_obj = lv.dropdown(content) else: print("Unknown type:", type); return None # add new object to internal list obj = { "lv_obj": lv_obj, "type": type } config["objects"].append(obj) # set optional parameter if widget support if type == TYPE.LABEL or type == TYPE.BUTTON or type == TYPE.CHECKBOX: widget_set_text(obj, parm) elif type == TYPE.SWITCH or type == TYPE.LED or type == TYPE.SLIDER: widget_set_value(obj, parm) # install default event handler lv_obj.set_event_cb(lambda o, e: on_event(obj, e)) return obj
def controls_create(parent): lv.page.set_scrl_layout(lv.page.__cast__(parent), lv.LAYOUT.PRETTY_TOP) if LV_DEMO_WIDGETS_SLIDESHOW == 0: btns = ["Cancel", "Ok", ""] m = lv.msgbox(lv.scr_act(), None) m.add_btns(btns) btnm = lv.btnmatrix.__cast__(m.get_btnmatrix()) # print("type(btnm): ",type(btnm)) btnm.set_btn_ctrl(1, lv.btnmatrix.CTRL.CHECK_STATE) h = lv.cont(parent, None) h.set_layout(lv.LAYOUT.PRETTY_MID) h.add_style(lv.cont.PART.MAIN, style_box) h.set_drag_parent(True) h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Basics") disp_size = display.get_size_category() if disp_size <= lv.DISP_SIZE.SMALL: grid_w = lv.page.get_width_grid(lv.page.__cast__(parent), 1, 1) # print("grid_w: ",grid_w) else: grid_w = lv.page.get_width_grid(lv.page.__cast__(parent), 2, 1) # print("grid_w: ",grid_w) h.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT) h.set_width(grid_w) btn = lv.btn(h, None) btn.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT) if disp_size <= lv.DISP_SIZE.SMALL: button_width = h.get_width_grid(1, 1) else: button_width = h.get_width_grid(2, 1) # print("button_width: %d"%button_width) btn.set_width(button_width) label = lv.label(btn, None) label.set_text("Button") btn = lv.btn(h, btn) btn.toggle() label = lv.label(btn, None) label.set_text("Button") lv.switch(h, None) lv.checkbox(h, None) fit_w = h.get_width_fit() slider = lv.slider(h, None) slider.set_value(40, lv.ANIM.OFF) slider.set_event_cb(slider_event_cb) slider.set_width_margin(fit_w) # Use the knobs style value the display the current value in focused state slider.set_style_local_margin_top(lv.slider.PART.BG, lv.STATE.DEFAULT, LV_DPX(25)) slider.set_style_local_value_font(lv.slider.PART.KNOB, lv.STATE.DEFAULT, lv.theme_get_font_small()) slider.set_style_local_value_ofs_y(lv.slider.PART.KNOB, lv.STATE.FOCUSED, -LV_DPX(25)) slider.set_style_local_value_opa(lv.slider.PART.KNOB, lv.STATE.DEFAULT, lv.OPA.TRANSP) slider.set_style_local_value_opa(lv.slider.PART.KNOB, lv.STATE.FOCUSED, lv.OPA.COVER) slider.set_style_local_transition_time(lv.slider.PART.KNOB, lv.STATE.DEFAULT, 300) slider.set_style_local_transition_prop_5(lv.slider.PART.KNOB, lv.STATE.DEFAULT, lv.STYLE.VALUE_OFS_Y) slider.set_style_local_transition_prop_6(lv.slider.PART.KNOB, lv.STATE.DEFAULT, lv.STYLE.VALUE_OPA) slider = lv.slider(h, None) slider.set_type(lv.slider.TYPE.RANGE) slider.set_value(70, lv.ANIM.OFF) slider.set_left_value(30, lv.ANIM.OFF) slider.set_style_local_value_ofs_y(lv.slider.PART.INDIC, lv.STATE.DEFAULT, -LV_DPX(25)) slider.set_style_local_value_font(lv.slider.PART.INDIC, lv.STATE.DEFAULT, lv.theme_get_font_small()) slider.set_style_local_value_opa(lv.slider.PART.INDIC, lv.STATE.DEFAULT, lv.OPA.COVER) slider.set_event_cb(slider_event_cb) lv.event_send(slider, lv.EVENT.VALUE_CHANGED, None) # To refresh the text if slider.get_width() > fit_w: slider.set_width(fit_w) h = lv.cont(parent, h) h.set_fit(lv.FIT.NONE) h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Text input") ta = lv.textarea(h, None) lv.cont.set_fit2(h, lv.FIT.PARENT, lv.FIT.NONE) ta.set_text("") ta.set_placeholder_text("E-mail address") ta.set_one_line(True) ta.set_cursor_hidden(True) #lv_obj_set_event_cb(ta, ta_event_cb); ta = lv.textarea(h, ta) ta.set_pwd_mode(True) ta.set_placeholder_text("Password") ta = lv.textarea(h, None) lv.cont.set_fit2(h, lv.FIT.PARENT, lv.FIT.NONE) ta.set_text("") ta.set_placeholder_text("Message") ta.set_cursor_hidden(True) #lv_obj_set_event_cb(ta, ta_event_cb); lv.cont.set_fit4(h, lv.FIT.PARENT, lv.FIT.PARENT, lv.FIT.NONE, lv.FIT.PARENT)
def gui_edit_trigger(num, flag): #num is to call trigger[num] #flag is to check 'new' or 'edit' #changes are stored in temp_trigger_item print('Printing Num : {}'.format(num)) temp_trigger_item = trigger if flag == 'edit': temp_trigger_item = trigger[num] print('Btn Pressed : {}'.format(str(temp_trigger_item))) elif flag == 'new': print('Creating new Trigger') #template should match with INITIAL TIMERS temp_trigger_item = { 'name': 'New Trigger', 'hb': 0, 'mb': 0, 'sb': 5, 'dur': 5, 'pin': 5, 'timerno': 0, 'cardnum': 0, 'daysoweek': [0, 1, 2, 3, 4, 5, 6], 'sec_start': 0 } def check_daysoweek(checkbox_array): temp_daysoweek = [] for num, check in enumerate(checkbox_array, 0): if check.get_state() == True: temp_daysoweek.append(num) print(temp_daysoweek) return temp_daysoweek def btn_event(task, params): if params == 'cancel': lv.scr_load(scr) elif params['param'] == 'save' and params['flag'] == 'edit': print(params) temp_trigger_item['name'] = params['name'] temp_trigger_item['hb'] = params['hb'] temp_trigger_item['mb'] = params['mb'] temp_trigger_item['sb'] = params['sb'] temp_trigger_item['dur'] = params['dur'] temp_trigger_item['pin'] = params['pin'] temp_trigger_item['timerno'] = params['timerno'] temp_trigger_item['cardnum'] = params['cardnum'] temp_trigger_item['daysoweek'] = params['daysoweek'] temp_trigger_item['sec_start'] = params['sec_start'] print('Triger Edit : Settings saved') lv.scr_load(scr) elif params['param'] == 'save' and params['flag'] == 'new': del params['param'] del params['flag'] trigger.append(params) gui_main() print('new key added : {}'.format(params)) global scr3 scr3 = lv.obj() lv.scr_load(scr3) btn1 = lv.btn(scr3) btn1.set_size(150, 40) btn1.set_style_bg_color(primary, 0) btn1_label = lv.label(btn1) btn1_label.set_text('Cancel') btn1_label.center() btn1.align_to(scr3, lv.ALIGN.TOP_LEFT, 0, 0) btn1.add_event_cb(lambda task: btn_event(task, 'cancel'), lv.EVENT.CLICKED, None) btn2 = lv.btn(scr3) btn2.set_size(150, 40) btn2.set_style_bg_color(primary, 0) btn2_label = lv.label(btn2) btn2_label.set_text('Save') btn2_label.center() btn2.align_to(scr3, lv.ALIGN.TOP_RIGHT, 0, 0) pinname = {'0': 21, '1': 19, '2': 18, '3': 5} btn2.add_event_cb( lambda task: btn_event(task, params={ 'param': 'save', 'flag': flag, 'name': ta_name.get_text(), 'hb': r1.get_selected(), 'mb': r2.get_selected(), 'sb': r3.get_selected(), 'dur': ((r4.get_selected() * 60 * 60) + (r5.get_selected() * 60) + r6.get_selected( )), 'pin': pinname[str(drpdwn.get_selected())], 'timerno': 0, 'cardnum': 0, 'daysoweek': check_daysoweek(checkbox), 'sec_start': 0 }), lv.EVENT.CLICKED, None) def refresh_label(): #label for activation time label3.set_text( 'Set trigger activation time\n{:02} : {:02} : {:02}'.format( r1.get_selected(), r2.get_selected(), r3.get_selected())) #label for duration durations = (r4.get_selected() * 60 * 60) + (r5.get_selected() * 60) + r6.get_selected() label4.set_text( 'Set Duration for trigger\n{:,} in seconds'.format(durations)) label1 = lv.label(scr3) if flag == 'edit': label1.set_text('Edit Trigger Settings') elif flag == 'new': label1.set_text('New Trigger Settings') label1.align_to(btn1, lv.ALIGN.OUT_BOTTOM_LEFT, 10, 10) label2 = lv.label(scr3) label2.set_text('Trigger Name') label2.align_to(label1, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) def keyboard_event(task, kb, scr3): event = task.get_code() ta = task.get_target() #get ta object if event == lv.EVENT.FOCUSED: #enable keyboard kb.set_textarea(ta) kb.clear_flag(lv.obj.FLAG.HIDDEN) #hide others for i in range(6, scr3.get_child_cnt()): scr3.get_child(i).add_flag(lv.obj.FLAG.HIDDEN) if event == lv.EVENT.DEFOCUSED: #disable keyboard and hide kb.set_textarea(None) kb.add_flag(lv.obj.FLAG.HIDDEN) #show others for i in range(6, scr3.get_child_cnt()): scr3.get_child(i).clear_flag(lv.obj.FLAG.HIDDEN) ta_name = lv.textarea(scr3) ta_name.align_to(label2, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) ta_name.add_text(temp_trigger_item['name']) ta_name.set_size(205, 40) ta_name.add_state(lv.STATE.FOCUSED) ta_name.add_event_cb(lambda task: keyboard_event(task, kb, scr3), lv.EVENT.ALL, None) kb = lv.keyboard(scr3) kb.align_to(ta_name, lv.ALIGN.OUT_BOTTOM_LEFT, -10, 10) kb.set_textarea(ta_name) kb.add_flag(lv.obj.FLAG.HIDDEN) label3 = lv.label(scr3) label3.set_text('Set trigger activation time') label3.align_to(ta_name, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) dump = [] for i in range(0, 24): dump.append(str(i)) opts1 = "\n".join(dump) del dump dump = [] for i in range(0, 60): dump.append(str(i)) opts2 = "\n".join(dump) del dump #Hour, Minute and Seconds to begin set using rollers r1 = lv.roller(scr3) r1.set_width(80) r1.set_height(80) r1.set_options(opts1, lv.roller.MODE.NORMAL) r1.align_to(label3, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 35) r2 = lv.roller(scr3) r2.set_width(80) r2.set_height(80) r2.set_options(opts2, lv.roller.MODE.NORMAL) r2.align_to(r1, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) r3 = lv.roller(scr3) r3.set_width(80) r3.set_height(80) r3.set_options(opts2, lv.roller.MODE.NORMAL) r3.align_to(r2, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) if flag == 'edit': r1.set_selected(temp_trigger_item['hb'], lv.ANIM.ON) r2.set_selected(temp_trigger_item['mb'], lv.ANIM.ON) r3.set_selected(temp_trigger_item['sb'], lv.ANIM.ON) r1_lbl = lv.label(scr3) r1_lbl.set_text('Hour') r1_lbl.align_to(r1, lv.ALIGN.OUT_TOP_MID, 0, 0) r2_lbl = lv.label(scr3) r2_lbl.set_text('Minute') r2_lbl.align_to(r2, lv.ALIGN.OUT_TOP_MID, 0, 0) r3_lbl = lv.label(scr3) r3_lbl.set_text('Seconds') r3_lbl.align_to(r3, lv.ALIGN.OUT_TOP_MID, 0, 0) #Duration. Duration information is set in refresh_label() label4 = lv.label(scr3) label4.align_to(r1, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) r4 = lv.roller(scr3) r4.set_width(80) r4.set_height(80) r4.set_options(opts1, lv.roller.MODE.NORMAL) r4.align_to(label4, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 35) r5 = lv.roller(scr3) r5.set_width(80) r5.set_height(80) r5.set_options(opts2, lv.roller.MODE.NORMAL) r5.align_to(r4, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) r6 = lv.roller(scr3) r6.set_width(80) r6.set_height(80) r6.set_options(opts2, lv.roller.MODE.NORMAL) r6.align_to(r5, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) def convert(seconds): min, sec = divmod(seconds, 60) hour, min = divmod(min, 60) return [hour, min, sec] if flag == 'edit': convert(temp_trigger_item['dur']) r4.set_selected(convert(temp_trigger_item['dur'])[0], lv.ANIM.ON) r5.set_selected(convert(temp_trigger_item['dur'])[1], lv.ANIM.ON) r6.set_selected(convert(temp_trigger_item['dur'])[2], lv.ANIM.ON) r4_lbl = lv.label(scr3) r4_lbl.set_text('Hour') r4_lbl.align_to(r4, lv.ALIGN.OUT_TOP_MID, 0, 0) r5_lbl = lv.label(scr3) r5_lbl.set_text('Minute') r5_lbl.align_to(r5, lv.ALIGN.OUT_TOP_MID, 0, 0) r6_lbl = lv.label(scr3) r6_lbl.set_text('Seconds') r6_lbl.align_to(r6, lv.ALIGN.OUT_TOP_MID, 0, 0) #Relay Setup label5 = lv.label(scr3) label5.set_text('Assign Relay to Trigger') label5.align_to(r4, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) drpdwn = lv.dropdown(scr3) drpdwn.align_to(label5, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) drpdwn.set_options("\n".join(['Relay 1', 'Relay 2', 'Relay 3', 'Relay 4'])) relayname = {21: '0', 19: '1', 18: '2', 5: '3'} if flag == 'edit': drpdwn.set_selected(int(relayname[temp_trigger_item['pin']])) label6 = lv.label(scr3) label6.set_text('Set days of week to turn trigger :') label6.align_to(drpdwn, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) checkbox = [] checkbox_lbl = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ] for i in range(0, 6): checkbox.append(lv.checkbox(scr3)) if i == 0: checkbox[i].align_to(label6, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) else: checkbox[i].align_to(checkbox[i - 1], lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) checkbox[i].set_text(checkbox_lbl[i]) if flag == 'edit': if i in temp_trigger_item['daysoweek']: checkbox[i].add_state(lv.STATE.CHECKED) elif flag == 'new': checkbox[i].add_state(lv.STATE.CHECKED) if flag == 'edit': del_btn = lv.btn(scr3) del_btn_lbl = lv.label(del_btn) del_btn_lbl.set_text('Delete This Trigger!') del_btn.set_style_bg_color(red, 0) del_btn.align_to(checkbox[5], lv.ALIGN.BOTTOM_MID, 80, 100) lv.timer_create(lambda task: refresh_label(), 900, None)
code = e.get_code() obj = lv.checkbox.__cast__(e.get_target()) if code == lv.EVENT.VALUE_CHANGED: txt = obj.get_text() if obj.get_state() & lv.STATE.CHECKED: state = "Checked" else: state = "Unchecked" print(txt + ":" + state) lv.scr_act().set_flex_flow(lv.FLEX_FLOW.COLUMN) lv.scr_act().set_flex_align(lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.START, lv.FLEX_ALIGN.CENTER) cb = lv.checkbox(lv.scr_act()) cb.set_text("Apple") cb.add_event_cb(event_handler, lv.EVENT.ALL, None) cb = lv.checkbox(lv.scr_act()) cb.set_text("Banana") cb.add_state(lv.STATE.CHECKED) cb.add_event_cb(event_handler, lv.EVENT.ALL, None) cb = lv.checkbox(lv.scr_act()) cb.set_text("Lemon") cb.add_state(lv.STATE.DISABLED) cb.add_event_cb(event_handler, lv.EVENT.ALL, None) cb = lv.checkbox(lv.scr_act()) cb.add_state(lv.STATE.CHECKED | lv.STATE.DISABLED)
#!/opt/bin/lv_micropython -i import time import lvgl as lv import display_driver def event_handler(source,evt): if evt == lv.EVENT.VALUE_CHANGED: if source.is_checked(): print("State: checked") else: print("State: unchecked") # create a checkbox cb = lv.checkbox(lv.scr_act(),None) cb.set_text("I agree to terms\nand conditions.") cb.align(None,lv.ALIGN.CENTER, 0, 0) # attach the callback cb.set_event_cb(event_handler)
def add_new(): '''button events''' def btn_event(obj, param): if param == "Cancel": lv.scr_act().clean() home() if param == "Reset 1": roller1.set_selected(0, lv.ANIM.ON) roller2.set_selected(0, lv.ANIM.ON) roller3.set_selected(0, lv.ANIM.ON) if param == "Set AM 1": roller1.set_selected(6, lv.ANIM.ON) roller2.set_selected(0, lv.ANIM.ON) roller3.set_selected(0, lv.ANIM.ON) if param == "Set PM 1": roller1.set_selected(13, lv.ANIM.ON) roller2.set_selected(0, lv.ANIM.ON) roller3.set_selected(0, lv.ANIM.ON) if param == "Reset 2": roller4.set_selected(0, lv.ANIM.ON) roller5.set_selected(0, lv.ANIM.ON) roller6.set_selected(0, lv.ANIM.ON) if param == "Reset hour": roller4.set_selected(0, lv.ANIM.ON) if param == "Reset minute": roller5.set_selected(0, lv.ANIM.ON) if param == "Save": '''storing settings in DB routine''' print('Debug val') #textarea cannot be empty key = text_area.get_text() if key == "": print('Key cannot be empty') lv.msgbox(lv.scr_act(), "Error", "Tigger name cannot be empty", [], True) #textare cannot be more than 8 char if len(key) >= 8: print('Trigger name too long') lv.msgbox(lv.scr_act(), "Error", "Tigger name too long", [], True) print(text_area.get_text()) #beginhour bhour = roller1.get_selected() bminute = roller2.get_selected() bsecs = roller3.get_selected() begin_time = "{:02}{:02}{:02}".format(bhour, bminute, bsecs) print(begin_time) #duration hdur = int(roller4.get_selected()) * 60 * 60 mdur = int(roller5.get_selected()) * 60 sdur = int(roller6.get_selected()) duration = str(hdur + mdur + sdur) print(str(duration)) #enable flow sensor? flow_enable_state = flow_sensor_switch.has_state(lv.STATE.CHECKED) print(flow_enable_state) #check flow sensor for 5 sec flow_debounce_state = flow_debounce_checkbox.has_state( lv.STATE.CHECKED) print(flow_debounce_state) #check min reading flow_max_state = flow_debounce_checkbox.has_state(lv.STATE.CHECKED) print(flow_max_state) #max flow limit flow_max_val = flow_max_spinbox.get_value() flow_max_val = flow_max_spinbox.get_value() print(flow_max_val) #enable rain sensor rain_sensor_enable_state = rain_sensor_switch.has_state( lv.STATE.CHECKED) print(rain_sensor_enable_state) rain_debounce_state = rain_sensor_debounce.has_state( lv.STATE.CHECKED) print(rain_debounce_state) #Generate keys to store in DB '''create unique id''' def new_id(): return random.randint(0, 9999) temp_db_keys = [] for key in db: temp_db_keys.append(eval(key)) temp_key = new_id() if temp_key in temp_db_keys: temp_key = new_id() return temp_key create_trigger(unique_id=temp_key, name=key, begin=begin_time, duration=duration, flow_enable_state=flow_enable_state, flow_debounce_state=flow_debounce_state, flow_max_state=flow_max_state, flow_max_val=flow_max_val, rain_enable_state=rain_sensor_enable_state, rain_debounce_state=rain_debounce_state) def ta_event_cb(e, keyboard): code = e.get_code() text_area = e.get_target() if code == lv.EVENT.FOCUSED: keyboard.set_textarea(text_area) keyboard.clear_flag(lv.obj.FLAG.HIDDEN) keyboard.move_foreground() cont.add_flag(lv.obj.FLAG.HIDDEN) if code == lv.EVENT.DEFOCUSED: keyboard.set_textarea(None) keyboard.add_flag(lv.obj.FLAG.HIDDEN) cont.clear_flag(lv.obj.FLAG.HIDDEN) '''main scr''' scr = lv.obj() scr.clean() lv.scr_load(scr) btn_cancel = lv.btn(scr) btn_cancel.add_event_cb(lambda e: btn_event(e, "Cancel"), lv.EVENT.CLICKED, None) btn_cancel_text = lv.label(btn_cancel) btn_cancel_text.set_text('Cancel') btn_save = lv.btn(scr) btn_save.align_to(btn_cancel, lv.ALIGN.OUT_RIGHT_TOP, 185, 0) btn_save.add_event_cb(lambda e: btn_event(e, "Save"), lv.EVENT.CLICKED, None) btn_save_text = lv.label(btn_save) btn_save_text.set_text('Save') label = lv.label(scr) label.set_text('Add New Trigger') label.align_to(btn_cancel, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) label2 = lv.label(scr) label2.set_text('Trigger Name (Max: 8 char)') label2.align_to(label, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) text_area = lv.textarea(scr) text_area.set_height(40) text_area.align_to(label2, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) text_area.add_event_cb(lambda e: ta_event_cb(e, keyboard), lv.EVENT.ALL, None) keyboard = lv.keyboard(scr) keyboard.align_to(scr, lv.ALIGN.BOTTOM_MID, 0, 0) keyboard.set_textarea(text_area) keyboard.add_flag(lv.obj.FLAG.HIDDEN) label3 = lv.label(lv.scr_act()) label3.set_text("Set Time to begin Trigger") label3.align_to(text_area, lv.ALIGN.OUT_BOTTOM_LEFT, 5, 10) '''cont width''' cont_width = 280 '''cont : Roller Time ''' cont = lv.obj(lv.scr_act()) cont.align_to(label3, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) cont.set_height(150) cont.set_width(cont_width) '''roller options''' dump = [] for i in range(0, 24): dump.append(str(i)) opts1 = "\n".join(dump) del dump dump = [] for i in range(0, 60): dump.append(str(i)) opts2 = "\n".join(dump) '''roller trigger time''' roller1 = lv.roller(cont) roller1.align_to(cont, lv.ALIGN.LEFT_MID, 0, 20) roller1.set_width(50) roller1.set_options(opts1, lv.roller.MODE.NORMAL) roller1.set_visible_row_count(3) roller1.set_selected(8, lv.ANIM.ON) roller2 = lv.roller(cont) roller2.align_to(roller1, lv.ALIGN.OUT_RIGHT_TOP, 5, 0) roller2.set_width(50) roller2.set_options(opts2, lv.roller.MODE.NORMAL) roller2.set_visible_row_count(3) roller2.set_selected(30, lv.ANIM.ON) roller3 = lv.roller(cont) roller3.align_to(roller2, lv.ALIGN.OUT_RIGHT_TOP, 5, 0) roller3.set_width(50) roller3.set_options(opts2, lv.roller.MODE.NORMAL) roller3.set_visible_row_count(3) roller3.set_selected(0, lv.ANIM.ON) label4 = lv.label(cont) label4.align_to(roller1, lv.ALIGN.OUT_TOP_MID, 0, 0) label4.set_text('hour') label5 = lv.label(cont) label5.align_to(roller2, lv.ALIGN.OUT_TOP_MID, 0, 0) label5.set_text('min') label6 = lv.label(cont) label6.align_to(roller3, lv.ALIGN.OUT_TOP_MID, 0, 0) label6.set_text('sec') '''reset button trigger''' btn_reset = lv.btn(cont) btn_reset.align_to(roller3, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) btn_reset.add_event_cb(lambda e: btn_event(e, "Reset 1"), lv.EVENT.CLICKED, None) btn_reset_lbl = lv.label(btn_reset) btn_reset_lbl.set_text("RESET") btn_am = lv.btn(cont) btn_am.align_to(btn_reset, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) btn_am.add_event_cb(lambda e: btn_event(e, "Set AM 1"), lv.EVENT.CLICKED, None) btn_am_lbl = lv.label(btn_am) btn_am_lbl.set_text('am') btn_pm = lv.btn(cont) btn_pm.align_to(btn_am, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) btn_pm.add_event_cb(lambda e: btn_event(e, "Set PM 1"), lv.EVENT.CLICKED, None) btn_pm_lbl = lv.label(btn_pm) btn_pm_lbl.set_text('pm') label7 = lv.label(scr) label7.align_to(cont, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) label7.set_text('Set Duration') '''cont 2 : Roller Duration''' cont2 = lv.obj(scr) cont2.align_to(label7, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) cont2.set_height(150) cont2.set_width(cont_width) '''roller duration''' roller4 = lv.roller(cont2) roller4.align_to(cont2, lv.ALIGN.LEFT_MID, 0, 20) roller4.set_width(50) roller4.set_options(opts1, lv.roller.MODE.NORMAL) roller4.set_visible_row_count(3) roller4.set_selected(0, lv.ANIM.ON) roller5 = lv.roller(cont2) roller5.align_to(roller4, lv.ALIGN.OUT_RIGHT_TOP, 5, 0) roller5.set_width(50) roller5.set_options(opts2, lv.roller.MODE.NORMAL) roller5.set_visible_row_count(3) roller5.set_selected(0, lv.ANIM.ON) roller6 = lv.roller(cont2) roller6.align_to(roller5, lv.ALIGN.OUT_RIGHT_TOP, 5, 0) roller6.set_width(50) roller6.set_options(opts2, lv.roller.MODE.NORMAL) roller6.set_visible_row_count(3) roller6.set_selected(30, lv.ANIM.ON) label8 = lv.label(cont2) label8.align_to(roller4, lv.ALIGN.OUT_TOP_MID, 0, 0) label8.set_text('hour') label9 = lv.label(cont2) label9.align_to(roller5, lv.ALIGN.OUT_TOP_MID, 0, 0) label9.set_text('min') label10 = lv.label(cont2) label10.align_to(roller6, lv.ALIGN.OUT_TOP_MID, 0, 0) label10.set_text('sec') '''reset button duration''' btn_reset2 = lv.btn(cont2) btn_reset2.align_to(roller6, lv.ALIGN.OUT_RIGHT_TOP, 10, 0) btn_reset2.add_event_cb(lambda e: btn_event(e, "Reset 2"), lv.EVENT.CLICKED, None) btn_reset_lbl2 = lv.label(btn_reset2) btn_reset_lbl2.set_text("RESET") btn_am2 = lv.btn(cont2) btn_am2.align_to(btn_reset2, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) btn_am2.add_event_cb(lambda e: btn_event(e, "Reset hour"), lv.EVENT.CLICKED, None) btn_am_lbl2 = lv.label(btn_am2) btn_am_lbl2.set_text('hour') btn_pm2 = lv.btn(cont2) btn_pm2.align_to(btn_am2, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) btn_pm2.add_event_cb(lambda e: btn_event(e, "Reset minute"), lv.EVENT.CLICKED, None) btn_pm_lbl2 = lv.label(btn_pm2) btn_pm_lbl2.set_text('minute') label10 = lv.label(scr) label10.align_to(cont2, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) label10.set_text('Set Automatic disable trigger settings') '''cont 3 : Flow sensor''' cont3 = lv.obj(scr) cont3.align_to(label10, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) cont3.set_height(150) cont3.set_width(cont_width) flow_sensor_lbl = lv.label(cont3) flow_sensor_lbl.align_to(cont3, lv.ALIGN.TOP_LEFT, 0, 5) flow_sensor_lbl.set_text("Enable Flow Sensor") flow_sensor_switch = lv.switch(cont3) flow_sensor_switch.align_to(cont3, lv.ALIGN.TOP_RIGHT, 0, -5) #label12 = lv.label(cont3) #label12.align_to(label11, lv.ALIGN.OUT_BOTTOM_LEFT,0,0) #label12.set_text('5 sec threshold') flow_debounce_checkbox = lv.checkbox(cont3) flow_debounce_checkbox.align_to(flow_sensor_lbl, lv.ALIGN.OUT_BOTTOM_LEFT, 5, 10) flow_debounce_checkbox.set_text("Debounce protection") flow_max_checkbox = lv.checkbox(cont3) flow_max_checkbox.align_to(flow_debounce_checkbox, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 5) flow_max_checkbox.set_text('Max flow protection') flow_max_spinbox = lv.spinbox(cont3) flow_max_spinbox.align_to(flow_max_checkbox, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0) flow_max_spinbox.set_range(0, 9999) h = flow_max_spinbox.get_height() flow_max_spinbox_btn1 = lv.btn(cont3) flow_max_spinbox_btn1.align_to(flow_max_spinbox, lv.ALIGN.OUT_RIGHT_TOP, 0, 0) flow_max_spinbox_btn1.set_style_bg_img_src(lv.SYMBOL.PLUS, 0) flow_max_spinbox_btn1.set_size(h, h) flow_max_spinbox_btn2 = lv.btn(cont3) flow_max_spinbox_btn2.align_to(flow_max_spinbox_btn1, lv.ALIGN.OUT_RIGHT_TOP, 0, 0) flow_max_spinbox_btn2.set_style_bg_img_src(lv.SYMBOL.MINUS, 0) flow_max_spinbox_btn2.set_size(h, h) '''Cont 4: Rain sensor''' cont4 = lv.obj(scr) cont4.align_to(cont3, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) cont4.set_height(90) cont4.set_width(cont_width) rain_sensor_lbl = lv.label(cont4) rain_sensor_lbl.align_to(cont4, lv.ALIGN.TOP_LEFT, 0, 5) rain_sensor_lbl.set_text("Enable Rain Sensor") rain_sensor_switch = lv.switch(cont4) rain_sensor_switch.align_to(cont4, lv.ALIGN.TOP_RIGHT, 0, -5) rain_sensor_debounce = lv.checkbox(cont4) rain_sensor_debounce.align_to(rain_sensor_lbl, lv.ALIGN.OUT_BOTTOM_LEFT, 5, 10) rain_sensor_debounce.set_text("Debounce protection") '''Calender''' cont5 = lv.obj(scr) cont5.align_to(cont4, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) cont5.set_height(290) cont5.set_width(cont_width) label14 = lv.label(cont5) label14.align_to(cont5, lv.ALIGN.TOP_LEFT, 0, 5) label14.set_text("Enable days") calendar_switch = lv.switch(cont5) calendar_switch.align_to(cont5, lv.ALIGN.TOP_RIGHT, 0, -5) cal_1_checkbox = lv.checkbox(cont5) cal_1_checkbox.align_to(label14, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) cal_1_checkbox.set_text("Monday") cal_2_checkbox = lv.checkbox(cont5) cal_2_checkbox.align_to(cal_1_checkbox, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) cal_2_checkbox.set_text("Tuesday") cal_3_checkbox = lv.checkbox(cont5) cal_3_checkbox.align_to(cal_2_checkbox, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) cal_3_checkbox.set_text("Wednesday") cal_4_checkbox = lv.checkbox(cont5) cal_4_checkbox.align_to(cal_3_checkbox, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) cal_4_checkbox.set_text("Thursday") cal_5_checkbox = lv.checkbox(cont5) cal_5_checkbox.align_to(cal_4_checkbox, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) cal_5_checkbox.set_text("Friday") cal_6_checkbox = lv.checkbox(cont5) cal_6_checkbox.align_to(cal_5_checkbox, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) cal_6_checkbox.set_text("Saturday") cal_7_checkbox = lv.checkbox(cont5) cal_7_checkbox.align_to(cal_6_checkbox, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10) cal_7_checkbox.set_text("Sunday")