Example #1
0
def interface():
    def event_handler(source, evt):
        if evt == lv.EVENT.VALUE_CHANGED:
            date = lv.calendar.get_pressed_date(source)
            if date:
                print("Clicked date: %02d.%02d.%02d" %
                      (date.day, date.month, date.year))

    # Create a screen and load it
    scr = lv.obj()
    lv.scr_load(scr)

    # create a calendar
    calendar = lv.calendar(lv.scr_act(), None)
    calendar.set_size(235, 235)
    calendar.align(None, lv.ALIGN.CENTER, 0, 0)
    calendar.set_event_cb(event_handler)

    # Make the date number smaller to be sure they fit into their area
    calendar.set_style_local_text_font(lv.calendar.PART.DATE, lv.STATE.DEFAULT,
                                       lv.theme_get_font_small())
    today = lv.calendar_date_t()
    date = cetTime()
    today.year = date[0]
    today.month = date[1]
    today.day = date[2]

    calendar.set_today_date(today)
    calendar.set_showed_date(today)

    watch.tft.backlight_fade(100)
    def main_page(self, tile_num):
        self.calendar_tile = self.mainbar.get_tile_obj(tile_num)
        self.calendar_style = lv.style_t()
        self.calendar_style.copy(self.mainbar.get_style())

        # create a calendar
        calendar = lv.calendar(self.calendar_tile, None)
        calendar.set_size(200, 200)
        calendar.align(self.calendar_tile, lv.ALIGN.CENTER, 0, -15)
        calendar.set_event_cb(self.event_handler)

        # Make the date number smaller to be sure they fit into their area
        calendar.set_style_local_text_font(lv.calendar.PART.DATE,
                                           lv.STATE.DEFAULT,
                                           lv.theme_get_font_small())

        exit_btn = lv.imgbtn(self.calendar_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.calendar_style)
        exit_btn.align(self.calendar_tile, lv.ALIGN.IN_BOTTOM_LEFT, 10, 0)
        self.log.debug("setting up exit callback")
        exit_btn.set_event_cb(self.exit_calendar_app_event_cb)

        self.calendar_style.set_text_opa(lv.obj.PART.MAIN, lv.OPA.COVER)
        # get current date and time
        today = lv.calendar_date_t()
        if self.mainbar.pcf8563:
            # read time from pcf8563
            localTime = self.mainbar.pcf8563.datetime()
            today.year = localTime[0] + 2000
        else:
            now = time.time()
            localTime = time.localtime(now)
            today.year = localTime[0]

        today.month = localTime[1]
        today.day = localTime[2]

        calendar.set_today_date(today)
        calendar.set_showed_date(today)
Example #3
0
    def main_page(self,tile_num):
        self.calendar_tile = self.mainbar.get_tile_obj(tile_num);
        self.calendar_style = lv.style_t()
        self.calendar_style.copy(self.mainbar.get_style())
        
        # create a calendar
        calendar = lv.calendar(self.calendar_tile,None)
        calendar.set_size(200,200)
        calendar.align(self.calendar_tile,lv.ALIGN.CENTER,0,-15)
        calendar.set_event_cb(self.event_handler)
        
        # Make the date number smaller to be sure they fit into their area
        calendar.set_style_local_text_font(lv.calendar.PART.DATE,
                                           lv.STATE.DEFAULT,lv.theme_get_font_small())

        exit_btn = lv.imgbtn(self.calendar_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.calendar_style)
        exit_btn.align(self.calendar_tile,lv.ALIGN.IN_BOTTOM_LEFT, 10, 0 )
        self.log.debug("setting up exit callback")
        exit_btn.set_event_cb(self.exit_calendar_app_event_cb)
        
        self.calendar_style.set_text_opa(lv.obj.PART.MAIN, lv.OPA.COVER)
Example #4
0
def selectors_create(parent):
    page = lv.page.__cast__(parent)
    lv.page.set_scrl_layout(page, lv.LAYOUT.PRETTY_MID)

    grid_h = page.get_height_grid(1, 1)

    if disp_size <= lv.DISP_SIZE.SMALL:
        grid_w = page.get_width_grid(1, 1)
    else:
        grid_w = page.get_width_grid(2, 1)

    cal = lv.calendar(parent, None)
    cal.set_drag_parent(True)
    if disp_size > lv.DISP_SIZE.MEDIUM:
        cal.set_size(min(grid_h, grid_w), min(grid_h, grid_w))
    else:
        cal.set_size(grid_w, grid_w)
        if disp_size <= lv.DISP_SIZE.SMALL:
            cal.set_style_local_text_font(lv.calendat.PART.BG,
                                          lv.STATE.DEFAULT,
                                          lv.theme_get_font_small())

    hl = [{
        "year": 2020,
        "month": 1,
        "day": 5
    }, {
        "year": 2020,
        "month": 1,
        "day": 9
    }]

    h = lv.cont(parent, None)
    h.set_drag_parent(True)
    if disp_size <= lv.DISP_SIZE.SMALL:
        h.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
        h.set_width(lv.page.get_width_fit(page))
        h.set_layout(lv.LAYOUT.COLUMN_MID)
    elif disp_size <= lv.DISP_SIZE.MEDIUM:
        h.set_size(lv.obj.get_width(lv.obj.__cast__(cal)),
                   lv.obj.get_height(lv.obj.__cast__(cal)))
        h.set_layout(lv.LAYOUT.PRETTY_TOP)
    else:
        h.set_click(False)
        h.set_style_local_bg_opa(lv.PART.MAIN, lv.STATE.DEFAULT, lv.OPA.TRANSP)
        h.set_style_local_border_opa(lv.PART.MAIN, lv.STATE.DEFAULT,
                                     lv.OPA.TRANSP)
        h.set_style_local_pad_left(lv.cont.PART.MAIN, lv.STATE.DEFAULT, 0)
        h.set_style_local_pad_right(lv.cont.PART.MAIN, lv.STATE.DEFAULT, 0)
        h.set_style_local_pad_top(lv.cont.PART_MAIN, LV_STATE_DEFAULT, 0)
        h.set_size(min(grid_h, grid_w), min(grid_h, grid_w))
        h.set_layout(lv.LAYOUT.PRETTY_TOP)

    roller = lv.roller(h, None)
    roller.add_style(lv.cont.PART.MAIN, style_box)
    roller.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT,
                                     "Roller")
    roller.set_auto_fit(False)
    roller.set_align(lv.label.ALIGN.CENTER)
    roller.set_visible_row_count(4)
    if disp_size <= lv.DISP_SIZE.SMALL:
        roller.set_width(lv.cont.get_width_grid(h, 1, 1))
    else:
        roller.set_width(lv.cont.get_width_grid(h, 2, 1))

    dd = lv.dropdown(h, None)
    dd.add_style(lv.cont.PART.MAIN, style_box)
    dd.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT,
                                 "Dropdown")
    if disp_size <= lv.DISP_SIZE.SMALL:
        dd.set_width(lv.cont.get_width_grid(h, 1, 1))
    else:
        dd.set_width(lv.cont.get_width_grid(h, 2, 1))

    dd.set_options(
        "Alpha\nBravo\nCharlie\nDelta\nEcho\nFoxtrot\nGolf\nHotel\nIndia\nJuliette\nKilo\nLima\nMike\nNovember\n"
        "Oscar\nPapa\nQuebec\nRomeo\nSierra\nTango\nUniform\nVictor\nWhiskey\nXray\nYankee\nZulu"
    )

    list = lv.list(parent, None)
    list.set_scroll_propagation(True)
    list.set_size(grid_w, grid_h)

    txts = [
        lv.SYMBOL.SAVE, "Save", lv.SYMBOL.CUT, "Cut", lv.SYMBOL.COPY, "Copy",
        lv.SYMBOL.OK, "This is a quite long text to scroll on the list",
        lv.SYMBOL.EDIT, "Edit", lv.SYMBOL.WIFI, "Wifi", lv.SYMBOL.BLUETOOTH,
        "Bluetooth", lv.SYMBOL.GPS, "GPS", lv.SYMBOL.USB, "USB",
        lv.SYMBOL.SD_CARD, "SD card", lv.SYMBOL.CLOSE, "Close"
    ]

    for i in range(0, len(txts) // 2, 2):
        btn = list.add_btn(txts[i], txts[i + 1])
        lv.btn.set_checkable(lv.btn.__cast__(btn), True)

        # Make a button disabled
        if i == 4:
            btn.set_state(lv.btn.STATE.DISABLED)

    cal.set_highlighted_dates(hl, 2)
def gui_time():

    global scr2, calendar

    selected_date_day = 0
    selected_date_month = 0
    selected_date_year = 0

    def btn_event(event, params):
        if params == 'cancel':
            lv.scr_load(scr)

        elif params['name'] == 'save':
            set_time(params['year'], params['month'], params['day'], 0,
                     params['hour'], params['minute'], params['seconds'])
            lv.scr_load(scr)
            #implements set time

        elif params['name'] == 'NTP':
            if sta_if.isconnected():
                ntptime.settime()
            else:
                print('Connect to WIFI')

    def event_handler(task, params):

        code = task.get_code()

        if code == lv.EVENT.VALUE_CHANGED:
            source = task.get_current_target()
            date = lv.calendar_date_t()

            if source.get_pressed_date(date) == lv.RES.OK:

                calendar.set_today_date(date.year, date.month, date.day)
                print("Clicked date: %02d.%02d.%02d" %
                      (date.day, date.month, date.year))
                label1.set_text('Set Date : {} - {} - {}'.format(
                    date.year, date.month, date.day))

                params['year'] = date.year
                params['month'] = date.month
                params['day'] = date.day

    scr2 = lv.obj()
    lv.scr_load(scr2)

    #CANCEL
    btn1 = lv.btn(scr2)
    btn1.set_size(120, 40)
    btn1.set_style_bg_color(primary, 0)
    btn1_label = lv.label(btn1)
    btn1_label.set_text('Cancel')
    #btn1_label.set_style_text_font(lv.font_montserrat_28, 0)
    btn1_label.center()
    btn1.align_to(scr2, lv.ALIGN.TOP_LEFT, 0, 0)
    btn1.add_event_cb(lambda task: btn_event(task, 'cancel'), lv.EVENT.CLICKED,
                      None)

    #SAVE
    btn2 = lv.btn(scr2)
    btn2.set_size(120, 40)
    btn2.set_style_bg_color(primary, 0)
    btn2_label = lv.label(btn2)
    btn2_label.set_text('Save')
    #btn2_label.set_style_text_font(lv.font_montserrat_28, 0)
    btn2_label.center()
    btn2.align_to(scr2, lv.ALIGN.TOP_RIGHT, 0, 0)
    btn2.add_event_cb(
        lambda task: btn_event(
            task, {
                'name': 'save',
                'hour': r1.get_selected(),
                'minute': r2.get_selected(),
                'seconds': r3.get_selected(),
                'year': selected_date_year,
                'month': selected_date_month,
                'day': selected_date_day
            }), lv.EVENT.CLICKED, None)

    label1 = lv.label(scr2)
    label1.set_text('Set Date : {} - {} - {}'.format(current_time()[0],
                                                     current_time()[1],
                                                     current_time()[2]))

    def refresh_label():
        label2.set_text('Set Time : {:02} : {:02} : {:02}'.format(
            r1.get_selected(), r2.get_selected(), r3.get_selected()))

    label1.align_to(btn1, lv.ALIGN.OUT_BOTTOM_LEFT, 10, 10)

    calendar = lv.calendar(scr2)
    calendar.set_size(240, 180)
    calendar.align_to(label1, lv.ALIGN.OUT_BOTTOM_LEFT,
                      int((320 - 250) / 2) - 10, 60)

    calendar.add_event_cb(
        lambda task: event_handler(
            task, {
                'year': selected_date_year,
                'month': selected_date_month,
                'day': selected_date_day
            }), lv.EVENT.ALL, None)

    calendar.set_today_date(current_time()[0],
                            current_time()[1],
                            current_time()[2])
    calendar.set_showed_date(current_time()[0], current_time()[1])
    lv.calendar_header_dropdown(scr2, calendar)

    label2 = lv.label(scr2)

    label2.align_to(calendar, lv.ALIGN.OUT_BOTTOM_LEFT, -20, 10)

    #generate values for rollers
    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

    r1 = lv.roller(scr2)
    r1.set_width(80)
    r1.set_height(60)
    r1.align_to(label2, lv.ALIGN.OUT_BOTTOM_LEFT, 15, 20)
    r1.set_options(opts1, lv.roller.MODE.NORMAL)
    r1.set_selected(current_time()[4], lv.ANIM.ON)

    r2 = lv.roller(scr2)
    r2.set_width(80)
    r2.set_height(60)
    r2.align_to(r1, lv.ALIGN.OUT_RIGHT_TOP, 10, 0)
    r2.set_options(opts2, lv.roller.MODE.NORMAL)
    r2.set_selected(current_time()[5], lv.ANIM.ON)

    r3 = lv.roller(scr2)
    r3.set_width(80)
    r3.set_height(60)
    r3.align_to(r2, lv.ALIGN.OUT_RIGHT_TOP, 10, 0)
    r3.set_options(opts2, lv.roller.MODE.NORMAL)
    r3.set_selected(current_time()[6], lv.ANIM.ON)

    r1_lbl = lv.label(scr2)
    r1_lbl.set_text('Hour')
    r1_lbl.align_to(r1, lv.ALIGN.OUT_TOP_MID, 0, 0)

    r2_lbl = lv.label(scr2)
    r2_lbl.set_text('Minute')
    r2_lbl.align_to(r2, lv.ALIGN.OUT_TOP_MID, 0, 0)

    r3_lbl = lv.label(scr2)
    r3_lbl.set_text('Seconds')
    r3_lbl.align_to(r3, lv.ALIGN.OUT_TOP_MID, 0, 0)

    label3 = lv.label(scr2)
    label3.set_text('Sync with online NTP Time Server')
    label3.align_to(r1, lv.ALIGN.OUT_BOTTOM_LEFT, -20, 10)

    btn3 = lv.btn(scr2)
    btn3_lbl = lv.label(btn3)
    btn3_lbl.set_text('Sync to NTP server')
    btn3.align_to(label3, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 10)
    btn3.add_event_cb(lambda event: btn_event(event, {'name': 'NTP'}),
                      lv.EVENT.CLICKED, None)

    #call refresh label
    lv.timer_create(lambda task: refresh_label(), 900, None)
    def __init__(self, parent, x_pos, y_pos, gui_ctrl):
        super().__init__(parent)
        self._gui_ctrl = gui_ctrl

        btn_style = self.get_style(lv.tabview.STYLE.BTN_REL)
        btn_style_or = lv.style_t()
        lv.style_copy(btn_style_or, btn_style)
        btn_style.body.padding.left = (parent.get_width() - x_pos) // 5 // 2
        btn_style.body.padding.right = (parent.get_width() - x_pos) // 5 // 2
        self.set_style(lv.tabview.STYLE.BTN_REL, btn_style)

        self.set_size(parent.get_width() - x_pos, parent.get_height() - y_pos)
        self.set_pos(x_pos, y_pos)

        self.set_anim_time(0)
        self.set_sliding(False)
        self.set_btns_pos(lv.tabview.BTNS_POS.LEFT)

        self.set_event_cb(self._tab_change_handler)

        self._t_start = self.add_tab("New Session")
        self._t_cal = self.add_tab("Calibration")
        self._t_other = self.add_tab("Other")
        self._t_done = self.add_tab("Done")

        self.set_tab_act(3, lv.ANIM.OFF)

        # Session screen
        # Stat new session
        self._new_sess = lv.cont(self._t_start)
        self._new_sess.set_fit(lv.FIT.FLOOD)
        self._new_sess.set_layout(lv.LAYOUT.PRETTY)

        self._new_session_label = RealignLabel(
            self._new_sess, "Set info, and start a new measuring session!",
            False)

        self._material_sel = lv.roller(self._new_sess)
        self._material_sel.set_options(
            "\n".join(material for material in MATERIAL_TYPE),
            lv.roller.MODE.INIFINITE)

        self._thickness_sel = lv.roller(self._new_sess)
        self._thickness_sel.set_options(
            "\n".join(thickness for thickness in THICKNESS_TYPE),
            lv.roller.MODE.INIFINITE)

        self._start_btn = TextBtn(self._new_sess, "Start", self._new_sess_cb)
        self._start_btn.set_style(lv.btn.STYLE.REL, btn_style_or)

        # Measuring Screen
        self._session = lv.cont(self._t_start)
        self._session.set_fit(lv.FIT.FLOOD)
        self._session.set_layout(lv.LAYOUT.PRETTY)

        self._session_label = RealignLabel(self._session, "\n\n\n", True)

        self._start_measure_btn = TextBtn(self._session, "New Panel",
                                          self._start_measure_cb)
        self._start_measure_btn.set_style(lv.btn.STYLE.REL, btn_style_or)

        self._done_measure_btn = TextBtn(self._session, "Finish",
                                         self._done_measure_cb)
        self._done_measure_btn.set_style(lv.btn.STYLE.REL, btn_style_or)

        self._re_measure_btn = TextBtn(self._session, "Re-measure",
                                       self._re_measure_cb)
        self._re_measure_btn.set_style(lv.btn.STYLE.REL, btn_style_or)

        self._chart = lv.chart(self._session)
        self._chart.set_height(90)
        self._chart.set_point_count(700)
        self._chart.set_range(11000, 13000)
        self._ser1 = self._chart.add_series(lv.color_hex(0x0000b3))
        self._ser2 = self._chart.add_series(lv.color_hex(0xe60000))
        self._ser3 = self._chart.add_series(lv.color_hex(0x00e600))
        self._ser4 = self._chart.add_series(lv.color_hex(0xffffff))

        self._session.set_hidden(True)

        lv.page.glue_obj(self._new_sess, True)
        lv.page.glue_obj(self._session, True)

        self._preload_cont = lv.cont(self._t_start)
        self._preload_cont.set_fit(lv.FIT.FLOOD)
        self._preload_cont.set_layout(lv.LAYOUT.CENTER)
        self._preload = lv.preload(self._preload_cont)

        self._preload_cont.set_hidden(True)

        # Calibration Screen
        self._cal_label = RealignLabel(self._t_cal, "Output: \n", False)

        self._cal_num_input = NumTextArea(self._t_cal, self.ta_test)
        self._cal_num_input.set_auto_realign(True)
        self._cal_num_input.align(self._cal_label, lv.ALIGN.OUT_BOTTOM_LEFT, 0,
                                  0)

        self._set_cal_1 = TextBtn(self._t_cal, "Set Amp 1", self._set_amp_1_cb)
        self._set_cal_1.set_style(lv.btn.STYLE.REL, btn_style_or)
        self._set_cal_1.align(self._cal_num_input, lv.ALIGN.OUT_RIGHT_MID, 0,
                              0)

        self._set_cal_2 = TextBtn(self._t_cal, "Set Amp 2", self._set_amp_2_cb)
        self._set_cal_2.set_style(lv.btn.STYLE.REL, btn_style_or)
        self._set_cal_2.align(self._set_cal_1, lv.ALIGN.OUT_RIGHT_MID, 0, 0)

        self._kb = lv.kb(self._t_cal)
        self._kb.set_map(["1", "2", "3","\n","4","5", "6",\
                          "\n","7", "8", "9","\n","0",".","Bksp",""])

        self._kb.set_height(180)
        self._kb.set_y(85)
        self._kb.set_ta(self._cal_num_input)

        # Laser Off Screen
        self._text = RealignLabel(self._t_done, "Laser Off", False)

        # Other Screen
        self._cal = lv.calendar(self._t_other)
        return
Example #7
0
#!/opt/bin/lv_micropython -i
import lvgl as lv
import display_driver
import os


def event_handler(source, evt):
    if evt == lv.EVENT.VALUE_CHANGED:
        date = lv.calendar.get_pressed_date(source)
        if date:
            print("Clicked date: %02d.%02d.%02d" %
                  (date.day, date.month, date.year))


# create a calendar
calendar = lv.calendar(lv.scr_act(), None)
calendar.set_size(235, 235)
calendar.align(None, lv.ALIGN.CENTER, 0, 0)
calendar.set_event_cb(event_handler)

# Make the date number smaller to be sure they fit into their area
calendar.set_style_local_text_font(lv.calendar.PART.DATE, lv.STATE.DEFAULT,
                                   lv.theme_get_font_small())

try:
    osVersion = os.uname()
    print("Running: ", osVersion)
    from wifi_connect import *
    # connect to the Internet and get the current time
    connect()
    now = cetTime()
Example #8
0

#############################################
############### Calendar(日历) ##############
#############################################
#日历触摸回调函数
def event_handler(obj, event):
    if event == lv.EVENT.CLICKED:
        date = obj.get_pressed_date()
        if date is not None:
            obj.set_today_date(date)  #显示按下选中的日期


if TOUCH_READY:

    calendar = lv.calendar(lv.scr_act())
    calendar.set_size(230, 230)
    calendar.align(None, lv.ALIGN.CENTER, 0, 0)
    calendar.set_event_cb(event_handler)

    #设置当前日期
    today = lv.calendar_date_t()  #构建日期对象
    today.year = 2020
    today.month = 7
    today.day = 1

    calendar.set_today_date(today)
    calendar.set_showed_date(today)  #设置当前显示日期

    #设置显示3个高亮日期
    highlihted_days = [