Ejemplo n.º 1
0
def btn_event_cb(btn, evt):
    if evt == lv.EVENT.CLICKED:
        # Create a full-screen background

        #Create a base object for the modal background
        obj = lv.obj(lv.scr_act(), None)
        obj.reset_style_list(lv.obj.PART.MAIN)
        obj.add_style(lv.obj.PART.MAIN, style_modal)
        obj.set_pos(0, 0)
        obj.set_size(LV_HOR_RES, LV_VER_RES)
        #obj.set_style_local_bg_opa(lv.obj.PART.MAIN, lv.STATE.DEFAULT, lv.OPA._80)
        btns2 = ["Ok", "Cancel", ""]

        # Create the message box as a child of the modal background
        mbox = lv.msgbox(obj, None)
        mbox.add_btns(btns2)
        mbox.set_text("Hello world!")
        mbox.align(None, lv.ALIGN.CENTER, 0, 0)
        mbox.set_event_cb(mbox_event_cb)

        # Fade the message box in with an animation
        a = lv.anim_t()
        a.init()
        a.set_var(obj)
        a.set_time(500)
        a.set_values(lv.OPA.TRANSP, lv.OPA._70)
        a.set_custom_exec_cb(lambda a, val: opa_anim(mbox, val))
        lv.anim_t.start(a)

        info.set_text(in_msg_info)
        info.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 5, -5)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
#!/opt/bin/lv_micropython -i
import time
import lvgl as lv
import display_driver

def event_cb(e):
    mbox = lv.msgbox.__cast__(e.get_current_target())
    print("Button " + mbox.get_active_btn_text() + " clicked")

btns = ["Apply", "Close", ""]

mbox1 = lv.msgbox(lv.scr_act(), "Hello", "This is a message box with two buttons.", btns, True)
mbox1.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None)
mbox1.center()

Ejemplo n.º 4
0
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 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 msb_save():
    msgbox = lv.msgbox(lv.scr_act(), "Attention!",
                       "Unsaved settings will be lost. Do you want to exit?",
                       ["Yes", "No"], True)
    msgbox.center()
def msb_edit_table(key):
    msgbox = lv.msgbox(lv.scr_act(), "Quick Edit",
                       "Do you want to change value : {} ?".format(key),
                       ["Yes", "No"], True)
    msgbox.center()
Ejemplo n.º 8
0
#!/opt/bin/lv_micropython -i
import lvgl as lv
import time
import display_driver


def event_handler(obj, event):
    if event == lv.EVENT.VALUE_CHANGED:
        print("Button: %s" % obj.get_active_btn_text())


btns = ["Apply", "Close", ""]

mbox1 = lv.msgbox(lv.scr_act())
mbox1.set_text("A message box with two buttons.")
mbox1.add_btns(btns)
mbox1.set_width(200)
mbox1.set_event_cb(event_handler)
mbox1.align(None, lv.ALIGN.CENTER, 0, 0)  # Align to the corner