示例#1
0
def anim(obj, val1, val2, style):

    global a1

    def anim_style(obj, val, style):

        if style == 'position_x':
            obj.set_x(val)

        if style == 'position_y':
            obj.set_y(val)

    a1 = lv.anim_t()
    a1.init()
    a1.set_var(obj)
    a1.set_values(val1, val2)
    a1.set_time(1000)
    a1.set_playback_delay(100)
    #a1.set_playback_time(300)
    #a1.set_repeat_delay(500)
    #a1.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
    a1.set_path_cb(lv.anim_t.path_overshoot)
    a1.set_custom_exec_cb(lambda a1, val: anim_style(obj, val, style))

    return a1
示例#2
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)
示例#3
0
def reset_button_event_handler(e):
    global isStarted
    global isAnimationComplete
    global currentValue
    global timeCount
    global arc
    global anim
    global anim_timeline
    global startLabel

    if (isStarted):
        return

    isAnimationComplete = False
    currentValue = timeCount[currentSelect] * 60 * 50
    arc[currentSelect].set_value(currentValue)

    anim[currentSelect] = lv.anim_t()
    anim[currentSelect].init()
    anim[currentSelect].set_var(arc[currentSelect])
    anim[currentSelect].set_time(currentValue * 20)
    anim[currentSelect].set_values(currentValue, 0)
    anim[currentSelect].set_custom_exec_cb(
        lambda a1, val: set_time_value(arc[currentSelect], val))

    anim_timeline = lv.anim_timeline_create()
    lv.anim_timeline_add(anim_timeline, 0, anim[currentSelect])

    startLabel.set_text("START")

    setLabelValue(currentValue)
示例#4
0
    def __init__(self):
        # Create a container with grid
        col_dsc = [LV_GRID_FR(1), 200, LV_GRID_FR(1), lv.GRID_TEMPLATE.LAST]
        row_dsc = [30, 10, 10, LV_GRID_FR(1), lv.GRID_TEMPLATE.LAST]

        self.p1 = 0
        self.p2 = 0
        self.cont = lv.obj(lv.scr_act())
        self.cont.set_style_pad_all(2, lv.PART.MAIN)
        self.cont.set_style_pad_column(10, lv.PART.MAIN)
        self.cont.set_style_pad_row(10, lv.PART.MAIN)
        self.cont.set_grid_dsc_array(col_dsc, row_dsc)
        self.cont.set_size(320, 240)
        self.cont.center()
        self.page_obj_init(self.cont)

        self.a = lv.anim_t()
        self.a.init()
        self.a.set_var(self.anim_obj)
        end = self.cont.get_style_width(
            lv.PART.MAIN) - self.anim_obj.get_style_width(lv.PART.MAIN) - 10
        self.a.set_values(5, end)
        self.a.set_time(2000)
        self.a.set_custom_exec_cb(
            lambda a, val: self.anim_x_cb(self.anim_obj, val))
        self.a.set_path_cb(self.anim_path_bezier3_cb)
        self.refer_chart_cubic_bezier()
示例#5
0
def start_button_event_handler(e):
    global isStarted
    global isAnimationComplete
    global anim_timeline
    global startLabel
    global anim
    global currentSelect
    global currentValue

    if (isAnimationComplete):
        return

    if (isStarted):
        isStarted = False
        lv.anim_timeline_stop(anim_timeline)
        lv.anim_timeline_del(anim_timeline)
        anim_timeline = None
        startLabel.set_text("RESUME")

        anim[currentSelect] = lv.anim_t()
        anim[currentSelect].init()
        anim[currentSelect].set_var(arc[currentSelect])
        anim[currentSelect].set_time(currentValue * 20)
        anim[currentSelect].set_values(currentValue, 0)
        anim[currentSelect].set_custom_exec_cb(
            lambda a1, val: set_time_value(arc[currentSelect], val))

        anim_timeline = lv.anim_timeline_create()
        lv.anim_timeline_add(anim_timeline, 0, anim[currentSelect])
    else:
        isStarted = True
        lv.anim_timeline_start(anim_timeline)
        startLabel.set_text("PAUSE")
示例#6
0
    def __init__(self, img, w, h, speed):
        """Initialize sprite.

        Args:
            path (string): Path of sprite image.
            w, h (int): Width and height of image.
            screen_width (int): Width of screen.
            screen_height (int): Width of height.
            size (int): Square side length.
            speed(int): Initial XY-Speed of sprite.
            display (SSD1351): OLED display object.
            color (int): RGB565 color value.
        """

        self.img = img
        self.w = w
        self.h = h
        self.screen_width = lv.scr_act().get_disp().driver.hor_res
        self.screen_height = lv.scr_act().get_disp().driver.ver_res
        self.x_speed = speed
        self.y_speed = speed
        self.x = self.screen_width // 2
        self.y = self.screen_height // 2

        self.img_anim = lv.anim_t()
        self.img_anim.init()
        self.img_anim.set_custom_exec_cb(
            lambda a, val: self.img_anim_cb(a, img, val))
        # self.img_anim.set_time(4000)
        # self.img_anim.set_playback_time(1000)
        self.img_anim.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
        lv.anim_t.start(self.img_anim)
示例#7
0
    def icon_generic_event_cb(self, obj, evt):
        if evt == lv.EVENT.PRESSED:
            img = obj.get_child_back(None)
            txt = obj.get_child(None)
            self.log.debug("icon_generic_event")

            a = lv.anim_t()
            a.init()
            a.set_time(100)

            a.set_var(img)
            a.set_custom_exec_cb(lambda a, val: self.set_x(img, val))
            # a.set_custom_exec_cb(lv_obj_set_x)
            a.set_values(img.get_x(), obj.get_width() - img.get_width() - 35)
            lv.anim_t.start(a)

            # a.set_custom_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y);
            a.set_custom_exec_cb(lambda a, val: self.set_y(img, val))
            a.set_values(img.get_y(), 35)
            lv.anim_t.start(a)

            a.set_var(txt)
            a.set_custom_exec_cb(lambda a, val: self.set_x(txt, val))
            a.set_values(txt.get_x(), 35)
            lv.anim_t.start(a)

            a.set_custom_exec_cb(lambda a, val: self.set_y(txt, val))
            a.set_values(txt.get_y(), obj.get_height() - txt.get_height() - 35)
            lv.anim_t.start(a)
示例#8
0
def arc_phase2_ready_cb(a, arc):
    a_arc = lv.anim_t()
    a_arc.init()
    a_arc.set_custom_exec_cb(lambda a_arc, val: anim_phase1(a_arc, arc, val))
    a_arc.set_time(1000)
    a_arc.set_values(0, 360)
    a_arc.set_ready_cb(lambda a: arc_phase1_ready_cb(a, arc))
    lv.anim_t.start(a_arc)
示例#9
0
 def anim_in(self, obj, delay):
     a = lv.anim_t()
     a.init()
     a.set_var(obj)
     a.set_time(self.LV_DEMO_PRINTER_ANIM_TIME)
     a.set_delay(delay)
     # a.set_exec_cb(obj.set_y)
     # a.set_values(obj.get_y() -  self.LV_DEMO_PRINTER_ANIM_Y, obj.get_y())
     # a.start()
     obj.fade_in(self.LV_DEMO_PRINTER_ANIM_TIME - 50, delay)
示例#10
0
    def anim_bg(self, delay, color, y_new):
        self.log.debug("anim_bg: new y: %d" % y_new)
        y_act = self.bg_top.get_y()
        act_color = self.bg_top.get_style_bg_color(lv.obj.PART.MAIN)
        self.log.debug("current y: %d" % y_act)
        if y_new != self.LV_DEMO_PRINTER_BG_NORMAL and y_new == y_act and act_color.full == color.full:
            return

        if (y_new == self.LV_DEMO_PRINTER_BG_NORMAL and y_new == y_act) or \
           (y_new == self.LV_DEMO_PRINTER_BG_NORMAL and y_act == self.LV_DEMO_PRINTER_BG_FULL):
            path = lv.anim_path_t()
            path.init()
            path.set_cb(self.triangle_path_cb)

            a = lv.anim_t()
            a.set_var(self.bg_top)
            a.set_time(self.LV_DEMO_PRINTER_ANIM_TIME_BG + 200)
            a.set_delay(delay)
            a.set_custom_exec_cb(lambda a, val: self.set_y(self.bg_top, val))
            a.set_values(y_act, y_new)
            a.set_path(path)
            lv.anim_t.start(a)
        else:
            a = lv.anim_t()
            a.set_var(self.bg_top)
            a.set_time(self.LV_DEMO_PRINTER_ANIM_TIME_BG)
            a.set_delay(delay)
            a.set_custom_exec_cb(lambda a, val: self.set_y(self.bg_top, val))
            a.set_values(self.bg_top.get_y(), y_new)
            lv.anim_t.start(a)

        color_anim = lv.anim_t()
        self.bg_color_prev = self.bg_color_act
        self.bg_color_act = color
        color_anim.set_custom_exec_cb(
            lambda color_anim, val: self.anim_bg_color_cb(val))
        color_anim.set_values(0, 255)
        color_anim.set_time(self.LV_DEMO_PRINTER_ANIM_TIME_BG)
        path = lv.anim_path_t()
        path.init()
        path.set_cb(lv.anim_path_t.linear)
        # a.set_path(lv.anim_t.path_def)
        lv.anim_t.start(color_anim)
def sw_event_cb(e,label):
    sw = e.get_target()

    if sw.has_state(lv.STATE.CHECKED): 
        a = lv.anim_t()
        a.init()
        a.set_var(label)
        a.set_values(label.get_x(), 100)
        a.set_time(500)
        a.set_path_cb(lv.anim_t.path_overshoot)
        a.set_custom_exec_cb(lambda a,val: anim_x_cb(label,val))
        lv.anim_t.start(a)
    else:
        a = lv.anim_t()
        a.init()
        a.set_var(label)
        a.set_values(label.get_x(), -label.get_width())
        a.set_time(500)
        a.set_path_cb(lv.anim_t.path_ease_in)
        a.set_custom_exec_cb(lambda a,val: anim_x_cb(label,val))
        lv.anim_t.start(a)
 def close_msg_box(self):
     if self.is_open():
         self.anim = lv.anim_t()
         self.anim.init()
         self.anim.set_var(self)
         self.anim.set_time(500)
         self.anim.set_values(lv.OPA.COVER, lv.OPA.TRANSP)
         self.anim.set_custom_exec_cb(
             lambda obj, val: self.set_style_opa(val, lv.PART.MAIN))
         self.anim.set_path_cb(lv.anim_t.path_ease_in)
         self.anim.set_ready_cb(lambda a: self.del_async())
         lv.anim_t.start(self.anim)
         self.opened = False
示例#13
0
 def close_msg_box(self):
     if self.is_open():
         self.anim = lv.anim_t()
         self.anim.init()
         self.anim.set_var(self)
         self.anim.set_time(500)
         self.anim.set_values(lv.OPA.COVER, lv.OPA.TRANSP)
         self.anim.set_custom_exec_cb(
             lambda obj, val: self.set_style_local_opa_scale(
                 self.PART.BG, lv.STATE.DEFAULT, val))
         self.anim.set_path(lv.anim_path_t({'cb': lv.anim_path_t.ease_in}))
         self.anim.set_ready_cb(lambda a: self.del_async())
         lv.anim_t.start(self.anim)
         self.opened = False
示例#14
0
    def add_loader(self, end_cb):
        arc = lv.arc(lv.scr_act(), None)
        arc.set_bg_angles(0, 0)
        arc.set_start_angle(270)
        arc.set_size(220, 220)
        self.theme.apply(arc, lv.THEME.ARC)
        self.log.debug("Starting loader anim")
        a = lv.anim_t()
        a.init()
        a.set_custom_exec_cb(lambda a, val: self.loader_anim_cb(a, arc, val))
        a.set_values(0, 110)
        a.set_time(2000)
        a.set_ready_cb(end_cb)
        lv.anim_t.start(a)

        return arc
示例#15
0
def animation(obj, value1, value2, anim_time, pb_delay, pb_time, path, cb,
              **kwargs):

    global animate

    animate = lv.anim_t()
    animate.init()
    animate.set_var(obj)
    animate.set_values(value1, value2)
    animate.set_time(anim_time)
    animate.set_playback_delay(pb_delay)
    animate.set_playback_time(pb_time)
    animate.set_path_cb(path)
    animate.set_custom_exec_cb(lambda animate, val: cb(obj, val, 2))

    return animate
示例#16
0
 def anim_out_all(self, obj, delay):
     self.log.debug("anim_out_all")
     child = obj.get_child_back(None)
     while child:
         if child != self.scan_img and child != self.bg_top and child != self.bg_bottom and child != lv.scr_act(
         ):
             a = lv.anim_t()
             a.init()
             a.set_var(child)
             a.set_time(self.LV_DEMO_PRINTER_ANIM_TIME)
             # a.set_exec_cb(lambda y: lv.obj.set_y(y))
             if child.get_y() < 80:
                 a.set_values(child.get_y(),
                              child.get_y() - self.LV_DEMO_PRINTER_ANIM_Y)
             else:
                 a.set_values(child.get_y(),
                              child.get_y() + self.LV_DEMO_PRINTER_ANIM_Y)
                 delay += self.LV_DEMO_PRINTER_ANIM_DELAY
             a.set_ready_cb(lv.obj.del_anim_ready_cb)
             lv.anim_t.start(a)
         child = obj.get_child_back(child)
示例#17
0
    def __init__(self):
        self.game_over = False
        # Draw background image
        draw_background()

        # create the brick images
        create_brick_img_dscs()

        # Generate bricks
        self.MAX_LEVEL = const(9)
        self.level = 1
        self.bricks = load_level(self.level)

        self.paddle = Paddle(lv.scr_act())
        # print('paddle x: %d, y: %d'%(self.paddle.x,self.paddle.y))
        self.balls = []

        # Initialze the score
        self.score = Score()

        # Initialize balls
        # print("ball position: %d.%d"%(120-9,300-self.paddle.height))
        self.balls.append(
            Ball(120 - 9, 300 - self.paddle.height, -3, -2, frozen=True))

        # Initialize lives
        self.lives = []
        for i in range(1, 3):
            self.lives.append(Life(i))

        # Initialize power-ups
        self.powerups = []

        anim = lv.anim_t()
        anim.init()
        anim.set_custom_exec_cb(lambda a, obj: self.anim_cb())
        anim.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
        lv.anim_t.start(anim)
示例#18
0
    else:
        txt_area.x1 = dsc.draw_area.x2 + 5
        txt_area.x2 = txt_area.x1 + txt_size.x - 1
        label_dsc.color = lv.color_black()

    txt_area.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() -
                                      txt_size.y) // 2
    txt_area.y2 = txt_area.y1 + txt_size.y - 1

    lv.draw_label(txt_area, dsc.clip_area, label_dsc, value_txt, None)


#
# Custom drawer on the bar to display the current value
#

bar = lv.bar(lv.scr_act())
bar.add_event_cb(event_cb, lv.EVENT.DRAW_PART_END, None)
bar.set_size(200, 20)
bar.center()

a = lv.anim_t()
a.init()
a.set_var(bar)
a.set_values(0, 100)
a.set_custom_exec_cb(lambda a, val: set_value(bar, val))
a.set_time(2000)
a.set_playback_time(2000)
a.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
lv.anim_t.start(a)
#

cont = lv.obj(lv.scr_act())
cont.set_size(300, 220)
cont.center()
cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)

for i in range(9):
    obj = lv.obj(cont)
    obj.set_size(70, lv.SIZE.CONTENT)

    label = lv.label(obj)
    label.set_text(str(i))
    label.center()

a_row = lv.anim_t()
a_row.init()
a_row.set_var(cont)
a_row.set_values(0, 10)
a_row.set_repeat_count(lv.ANIM_REPEAT.INFINITE)

a_row.set_time(500)
a_row.set_playback_time(500)
a_row.set_custom_exec_cb(lambda a,val: row_gap_anim(cont,val))
lv.anim_t.start(a_row)

a_col = lv.anim_t()
a_col.init()
a_col.set_var(cont)
a_col.set_values(0, 10)
a_col.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
示例#20
0
def visuals_create(parent):
    page = lv.page.__cast__(parent)
    lv.page.set_scrl_layout(page, lv.LAYOUT.PRETTY_TOP)

    disp_size = display.get_size_category()

    grid_h_chart = lv.page.get_height_grid(page, 1, 1)
    if disp_size <= lv.DISP_SIZE.LARGE:
        grid_w_chart = lv.page.get_width_grid(page, 1, 1)
    else:
        grid_w_chart = lv.page.get_width_grid(page, 1, 2)

    chart = lv.chart(parent, None)
    chart.add_style(lv.chart.PART.BG, style_box)
    if disp_size <= lv.DISP_SIZE.SMALL:
        chart.set_style_local_text_font(lv.chart.PART.SERIES_BG,
                                        lv.STATE.DEFAULT,
                                        lv.theme_get_font_small())

    chart.set_drag_parent(True)
    chart.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT,
                                    "Line chart")
    chart.set_width_margin(grid_w_chart)
    chart.set_height_margin(grid_h_chart)
    chart.set_div_line_count(3, 0)
    chart.set_point_count(8)
    chart.set_type(lv.chart.TYPE.LINE)

    if disp_size > lv.DISP_SIZE.SMALL:
        chart.set_style_local_pad_left(lv.chart.PART.BG, lv.STATE.DEFAULT,
                                       4 * (LV_DPI // 10))
        chart.set_style_local_pad_bottom(lv.chart.PART.BG, lv.STATE.DEFAULT,
                                         3 * (LV_DPI // 10))
        chart.set_style_local_pad_right(lv.chart.PART.BG, lv.STATE.DEFAULT,
                                        2 * (LV_DPI // 10))
        chart.set_style_local_pad_top(lv.chart.PART.BG, lv.STATE.DEFAULT,
                                      2 * (LV_DPI // 10))
        chart.set_y_tick_length(0, 0)
        chart.set_x_tick_length(0, 0)
        chart.set_y_tick_texts("600\n500\n400\n300\n200", 0,
                               lv.chart.AXIS.DRAW_LAST_TICK)
        chart.set_x_tick_texts("Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug", 0,
                               lv.chart.AXIS.DRAW_LAST_TICK)

    s1 = chart.add_series(LV_THEME_DEFAULT_COLOR_PRIMARY)
    s2 = chart.add_series(LV_THEME_DEFAULT_COLOR_SECONDARY)

    chart.set_next(s1, 10)
    chart.set_next(s1, 90)
    chart.set_next(s1, 30)
    chart.set_next(s1, 60)
    chart.set_next(s1, 10)
    chart.set_next(s1, 90)
    chart.set_next(s1, 30)
    chart.set_next(s1, 60)
    chart.set_next(s1, 10)
    chart.set_next(s1, 90)

    chart.set_next(s2, 32)
    chart.set_next(s2, 66)
    chart.set_next(s2, 5)
    chart.set_next(s2, 47)
    chart.set_next(s2, 32)
    chart.set_next(s2, 32)
    chart.set_next(s2, 66)
    chart.set_next(s2, 5)
    chart.set_next(s2, 47)
    chart.set_next(s2, 66)
    chart.set_next(s2, 5)
    chart.set_next(s2, 47)

    chart2 = lv.chart(parent, chart)
    chart2.set_type(lv.chart.TYPE.COLUMN)
    chart2.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT,
                                     "Column chart")

    s1 = chart2.add_series(LV_THEME_DEFAULT_COLOR_PRIMARY)
    s2 = chart2.add_series(LV_THEME_DEFAULT_COLOR_SECONDARY)

    chart2.set_next(s1, 10)
    chart2.set_next(s1, 90)
    chart2.set_next(s1, 30)
    chart2.set_next(s1, 60)
    chart2.set_next(s1, 10)
    chart2.set_next(s1, 90)
    chart2.set_next(s1, 30)
    chart2.set_next(s1, 60)
    chart2.set_next(s1, 10)
    chart2.set_next(s1, 90)

    chart2.set_next(s2, 32)
    chart2.set_next(s2, 66)
    chart2.set_next(s2, 5)
    chart2.set_next(s2, 47)
    chart2.set_next(s2, 32)
    chart2.set_next(s2, 32)
    chart2.set_next(s2, 66)
    chart2.set_next(s2, 5)
    chart2.set_next(s2, 47)
    chart2.set_next(s2, 66)
    chart2.set_next(s2, 5)
    chart2.set_next(s2, 47)

    if disp_size <= lv.DISP_SIZE.SMALL:
        grid_w_meter = lv.page.get_width_grid(page, 1, 1)
    elif disp_size <= lv.DISP_SIZE.MEDIUM:
        grid_w_meter = lv.page.get_width_grid(page, 2, 1)
    else:
        grid_w_meter = lv.page.get_width_grid(page, 3, 1)

    meter_h = lv.page.get_height_fit(page)
    if grid_w_meter < meter_h:
        meter_size = grid_w_meter
    else:
        meter_size = meter_h

    lmeter = lv.linemeter(parent, None)
    lmeter.set_drag_parent(True)
    lmeter.set_value(50)
    lmeter.set_size(meter_size, meter_size)
    lmeter.add_style(lv.linemeter.PART.MAIN, style_box)
    lmeter.set_style_local_value_str(lv.linemeter.PART.MAIN, lv.STATE.DEFAULT,
                                     "Line meter")

    label = lv.label(lmeter, None)
    label.align(lmeter, lv.ALIGN.CENTER, 0, 0)
    label.set_style_local_text_font(lv.label.PART.MAIN, lv.STATE.DEFAULT,
                                    lv.theme_get_font_title())

    a_lm = lv.anim_t()
    a_lm.init()
    a_lm.set_custom_exec_cb(lambda a, val: linemeter_anim(a, lmeter, val))
    a_lm.set_values(0, 100)
    a_lm.set_time(4000)
    a_lm.set_playback_time(1000)
    a_lm.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
    lv.anim_t.start(a_lm)

    gauge = lv.gauge(parent, None)
    gauge.set_drag_parent(True)
    gauge.set_size(meter_size, meter_size)
    gauge.add_style(lv.gauge.PART.MAIN, style_box)
    gauge.set_style_local_value_str(lv.gauge.PART.MAIN, lv.STATE.DEFAULT,
                                    "Gauge")

    label = lv.label(gauge, label)
    label.align(gauge, lv.ALIGN.CENTER, 0, grid_w_meter // 3)

    a_ga = lv.anim_t()
    a_ga.init()
    a_ga.set_custom_exec_cb(lambda a, val: linemeter_anim(a, lmeter, val))
    a_ga.set_values(0, 100)
    a_ga.set_time(4000)
    a_ga.set_playback_time(1000)
    a_ga.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
    a_ga.set_custom_exec_cb(lambda a, val: gauge_anim(a, gauge, val))
    lv.anim_t.start(a_ga)

    arc = lv.arc(parent, None)
    arc.set_drag_parent(True)
    arc.set_bg_angles(0, 360)
    arc.set_rotation(270)
    arc.set_angles(0, 0)
    arc.set_size(meter_size, meter_size)
    arc.add_style(lv.arc.PART.BG, style_box)
    arc.set_style_local_value_str(lv.arc.PART.BG, lv.STATE.DEFAULT, "Arc")

    label = lv.label(arc)
    label.align(arc, lv.ALIGN.CENTER, 0, 0)

    a_arc = lv.anim_t()
    a_arc.init()
    a_arc.set_custom_exec_cb(lambda a_arc, val: anim_phase1(a_arc, arc, val))
    a_arc.set_values(0, 360)
    a_arc.set_ready_cb(lambda a: arc_phase1_ready_cb(a, arc))
    # a_arc.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
    a_arc.set_time(1000)
    lv.anim_t.start(a_arc)

    # Create a bar and use the backgrounds value style property to display the current value
    bar_h = lv.cont(parent, None)
    bar_h.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
    bar_h.add_style(lv.cont.PART.MAIN, style_box)
    bar_h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Bar")

    if disp_size <= lv.DISP_SIZE.SMALL:
        bar_h.set_width(lv.page_get_width_grid(page, 1, 1))
    elif disp_size <= lv.DISP_SIZE.MEDIUM:
        bar_h.set_width(lv.page.get_width_grid(page, 2, 1))
    else:
        bar_h.set_width(lv.page.get_width_grid(parent, 3, 2))

    bar = lv.bar(bar_h, None)
    bar.set_width(lv.cont.get_width_fit(bar_h))
    bar.set_style_local_value_font(lv.bar.PART.BG, lv.STATE.DEFAULT,
                                   lv.theme_get_font_small())
    bar.set_style_local_value_align(lv.bar.PART.BG, lv.STATE.DEFAULT,
                                    lv.ALIGN.OUT_BOTTOM_MID)
    bar.set_style_local_value_ofs_y(lv.bar.PART.BG, lv.STATE.DEFAULT,
                                    LV_DPI // 20)
    bar.set_style_local_margin_bottom(lv.bar.PART.BG, lv.STATE.DEFAULT,
                                      LV_DPI // 7)
    bar.align(None, lv.ALIGN.CENTER, 0, 0)
    bar.set_value(30, lv.ANIM.OFF)

    led_h = lv.cont(parent, None)
    led_h.set_layout(lv.LAYOUT.PRETTY_MID)
    if disp_size <= lv.DISP_SIZE.SMALL:
        led_h.set_width(lv.page.get_width_grid(page, 1, 1))
    elif disp_size <= lv.DISP_SIZE.MEDIUM:
        led_h.set_width(lv.page.get_width_grid(page, 2, 1))
    else:
        led_h.set_width(lv.page.get_width_grid(page, 3, 1))

    led_h.set_height(lv.obj.get_height(lv.obj.__cast__(bar_h)))
    led_h.add_style(lv.cont.PART.MAIN, style_box)
    led_h.set_drag_parent(True)
    led_h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT,
                                    "LEDs")

    led = lv.led(led_h, None)
    led_size = lv.obj.get_height_fit(lv.obj.__cast__(led_h))
    led.set_size(led_size, led_size)
    led.off()

    led = lv.led(led_h, led)
    led.set_bright((LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN) // 2 +
                   LV_LED_BRIGHT_MIN)

    led = lv.led(led_h, led)
    led.on()

    if disp_size == lv.DISP_SIZE.MEDIUM:
        led_h.add_protect(lv.PROTECT.POS)
        led_h.align(
            bar_h, lv.ALIGN.OUT_BOTTOM_MID, 0,
            lv.obj.get_style_margin_top(lv.obj.__cast__(led_h),
                                        lv.obj.PART.MAIN) +
            lv.obj.get_style_pad_inner(parent, lv.page.PART.SCROLLABLE))

    task = lv.task_create_basic()
    task.set_cb(lambda task: bar_anim(task, bar))
    task.set_period(100)
    task.set_prio(lv.TASK_PRIO.LOWEST)
示例#21
0
    def createPage(self):
        global isStarted
        global isAnimationComplete
        global arc
        global anim
        global timeCount
        global currentSelect
        global minuteLabel
        global secondLabel
        global millionLabel
        global anim_timeline
        global startLabel
        global currentValue
        global timer_alive

        print("Enter Timer")

        # init scr
        scr = lv.obj()

        win = lv.obj(scr)
        win.set_size(scr.get_width(), scr.get_height())
        win.set_style_border_opa(0, 0)
        win.set_style_radius(0, 0)
        win.set_style_bg_color(lv.color_black(), 0)
        win.clear_flag(lv.obj.FLAG.SCROLLABLE)

        # back
        backImg = lv.img(win)
        backImg.set_src(RESOURCES_ROOT + "images/back.png")
        backImg.set_style_align(lv.ALIGN.LEFT_MID, 0)
        backImg.add_flag(lv.obj.FLAG.CLICKABLE)
        backImg.add_event_cb(lambda e: timer_back_click_callback(e, win),
                             lv.EVENT.CLICKED, None)
        backImg.add_event_cb(lambda e: timer_back_press_callback(e, backImg),
                             lv.EVENT.PRESSED, None)
        backImg.add_event_cb(lambda e: timer_back_release_callback(e, backImg),
                             lv.EVENT.RELEASED, None)
        backImg.set_ext_click_area(30)

        isStarted = False
        currentSelect = 0

        # count down
        func_col_dsc = [40, 5, 30, 5, 20, lv.GRID_TEMPLATE.LAST]
        func_row_dsc = [30, lv.GRID_TEMPLATE.LAST]

        timeContainer = lv.obj(win)
        timeContainer.set_style_bg_opa(0, 0)
        timeContainer.set_style_border_opa(0, 0)
        timeContainer.set_layout(lv.LAYOUT_GRID.value)
        timeContainer.set_style_grid_column_dsc_array(func_col_dsc, 0)
        timeContainer.set_style_grid_row_dsc_array(func_row_dsc, 0)
        timeContainer.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN,
                                     lv.GRID_ALIGN.SPACE_BETWEEN)
        timeContainer.set_style_pad_all(0, 0)
        timeContainer.set_size(240, 70)
        timeContainer.center()

        minuteLabel = lv.label(timeContainer)
        minuteLabel.set_style_text_font(lv.font_montserrat_48, 0)
        minuteLabel.set_style_text_color(lv.color_white(), 0)
        minuteLabel.set_grid_cell(lv.GRID_ALIGN.START, 0, 1,
                                  lv.GRID_ALIGN.CENTER, 0, 1)

        signLabel = lv.label(timeContainer)
        signLabel.set_style_text_font(lv.font_montserrat_48, 0)
        signLabel.set_style_text_color(lv.color_white(), 0)
        signLabel.set_text(":")
        signLabel.set_grid_cell(lv.GRID_ALIGN.CENTER, 1, 1,
                                lv.GRID_ALIGN.CENTER, 0, 1)

        secondLabel = lv.label(timeContainer)
        secondLabel.set_style_text_font(lv.font_montserrat_48, 0)
        secondLabel.set_style_text_color(lv.color_white(), 0)
        secondLabel.set_grid_cell(lv.GRID_ALIGN.CENTER, 2, 1,
                                  lv.GRID_ALIGN.CENTER, 0, 1)

        signLabel = lv.label(timeContainer)
        signLabel.set_style_text_font(lv.font_montserrat_48, 0)
        signLabel.set_style_text_color(lv.color_white(), 0)
        signLabel.set_text(":")
        signLabel.set_grid_cell(lv.GRID_ALIGN.CENTER, 3, 1,
                                lv.GRID_ALIGN.CENTER, 0, 1)

        millionLabel = lv.label(timeContainer)
        millionLabel.set_style_text_font(lv.font_montserrat_36, 0)
        millionLabel.set_style_text_color(lv.color_white(), 0)
        millionLabel.set_grid_cell(lv.GRID_ALIGN.END, 4, 1,
                                   lv.GRID_ALIGN.START, 0, 1)

        setLabelValue(timeCount[currentSelect] * 60 * 50)

        startButton = lv.btn(win)
        startButton.align(lv.ALIGN.CENTER, 0, 40)
        startButton.set_size(126, 54)
        startButton.set_style_radius(45, lv.PART.MAIN)
        startButton.set_style_shadow_opa(0, 0)
        startButton.set_style_bg_color(lv.color_make(0xFF, 0xA8, 0x48),
                                       lv.PART.MAIN)
        startButton.align(lv.ALIGN.BOTTOM_LEFT, 12, -12)
        startButton.add_event_cb(start_button_event_handler, lv.EVENT.CLICKED,
                                 None)

        startLabel = lv.label(startButton)
        startLabel.set_text("START")
        startLabel.set_style_text_color(lv.color_black(), 0)
        startLabel.set_style_text_font(lv.font_montserrat_20, 0)
        startLabel.center()

        resetButton = lv.btn(win)
        resetButton.align(lv.ALIGN.CENTER, 0, 40)
        resetButton.set_size(126, 54)
        resetButton.set_style_radius(45, lv.PART.MAIN)
        resetButton.set_style_shadow_opa(0, 0)
        resetButton.set_style_bg_color(lv.color_white(), lv.PART.MAIN)
        resetButton.align(lv.ALIGN.BOTTOM_RIGHT, -12, -12)
        resetButton.add_event_cb(reset_button_event_handler, lv.EVENT.CLICKED,
                                 None)

        resetLabel = lv.label(resetButton)
        resetLabel.set_text("REST")
        resetLabel.set_style_text_color(lv.color_black(), 0)
        resetLabel.set_style_text_font(lv.font_montserrat_20, 0)
        resetLabel.center()

        # select time
        col_dsc = [75, 75, 75, 75, lv.GRID_TEMPLATE.LAST]
        row_dsc = [60, 80, 60, lv.GRID_TEMPLATE.LAST]
        funcContainer = lv.obj(win)
        funcContainer.set_layout(lv.LAYOUT_GRID.value)
        funcContainer.set_style_bg_opa(0, 0)
        funcContainer.set_style_border_opa(0, 0)
        funcContainer.set_style_grid_column_dsc_array(col_dsc, 0)
        funcContainer.set_style_grid_row_dsc_array(row_dsc, 0)
        funcContainer.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN,
                                     lv.GRID_ALIGN.SPACE_BETWEEN)
        funcContainer.set_size(300, 90)
        funcContainer.set_style_align(lv.ALIGN.TOP_MID, 0)

        maxMillionSecond = timeCount[0] * 60 * 50
        arc[0] = lv.arc(funcContainer)
        arc[0].set_style_arc_color(lv.color_white(), lv.PART.INDICATOR)
        arc[0].set_style_arc_color(lv.color_make(0x33, 0x33, 0x33),
                                   lv.PART.MAIN)
        arc[0].set_range(0, maxMillionSecond)
        arc[0].set_size(55, 55)
        arc[0].set_rotation(90)
        arc[0].set_bg_angles(0, 360)
        arc[0].remove_style(None, lv.PART.KNOB)
        arc[0].set_value(maxMillionSecond)
        arc[0].set_style_arc_width(8, lv.PART.INDICATOR)
        arc[0].set_style_arc_width(8, lv.PART.MAIN)
        arc[0].set_grid_cell(lv.GRID_ALIGN.CENTER, 0, 1, lv.GRID_ALIGN.CENTER,
                             0, 1)
        arc[0].clear_flag(lv.obj.FLAG.CLICKABLE)
        totalTime = lv.label(funcContainer)
        totalTime.set_text(str(timeCount[0]))
        totalTime.set_style_text_font(lv.font_montserrat_18, 0)
        totalTime.set_style_text_color(lv.color_white(), 0)
        totalTime.set_grid_cell(lv.GRID_ALIGN.CENTER, 0, 1,
                                lv.GRID_ALIGN.CENTER, 0, 1)
        totalTime.add_flag(lv.obj.FLAG.CLICKABLE)
        totalTime.add_event_cb(lambda e: arc_event_handler(e, 0),
                               lv.EVENT.CLICKED, None)
        totalTime.set_ext_click_area(30)

        anim[0] = lv.anim_t()
        anim[0].init()
        anim[0].set_var(arc[0])
        anim[0].set_time(maxMillionSecond * 20)
        anim[0].set_values(maxMillionSecond, 0)
        anim[0].set_custom_exec_cb(lambda a1, val: set_time_value(arc[0], val))
        anim_timeline = lv.anim_timeline_create()
        lv.anim_timeline_add(anim_timeline, 0, anim[0])

        arc[1] = lv.arc(funcContainer)
        arc[1].set_style_arc_color(lv.color_white(), lv.PART.INDICATOR)
        arc[1].set_style_arc_color(lv.color_make(0x33, 0x33, 0x33),
                                   lv.PART.MAIN)
        arc[1].set_range(0, maxMillionSecond)
        arc[1].set_size(55, 55)
        arc[1].set_rotation(90)
        arc[1].set_bg_angles(0, 360)
        arc[1].remove_style(None, lv.PART.KNOB)
        arc[1].set_value(0)
        arc[1].set_style_arc_width(2, lv.PART.INDICATOR)
        arc[1].set_style_arc_width(2, lv.PART.MAIN)
        arc[1].set_grid_cell(lv.GRID_ALIGN.CENTER, 1, 1, lv.GRID_ALIGN.CENTER,
                             0, 1)
        arc[1].clear_flag(lv.obj.FLAG.CLICKABLE)
        totalTime = lv.label(funcContainer)
        totalTime.set_text(str(timeCount[1]))
        totalTime.set_style_text_font(lv.font_montserrat_18, 0)
        totalTime.set_style_text_color(lv.color_white(), 0)
        totalTime.set_grid_cell(lv.GRID_ALIGN.CENTER, 1, 1,
                                lv.GRID_ALIGN.CENTER, 0, 1)
        totalTime.add_flag(lv.obj.FLAG.CLICKABLE)
        totalTime.add_event_cb(lambda e: arc_event_handler(e, 1),
                               lv.EVENT.CLICKED, None)
        totalTime.set_ext_click_area(30)

        arc[2] = lv.arc(funcContainer)
        arc[2].set_style_arc_color(lv.color_white(), lv.PART.INDICATOR)
        arc[2].set_style_arc_color(lv.color_make(0x33, 0x33, 0x33),
                                   lv.PART.MAIN)
        arc[2].set_range(0, maxMillionSecond)
        arc[2].set_size(55, 55)
        arc[2].set_rotation(90)
        arc[2].set_bg_angles(0, 360)
        arc[2].remove_style(None, lv.PART.KNOB)
        arc[2].set_value(0)
        arc[2].set_style_arc_width(2, lv.PART.INDICATOR)
        arc[2].set_style_arc_width(2, lv.PART.MAIN)
        arc[2].set_grid_cell(lv.GRID_ALIGN.CENTER, 2, 1, lv.GRID_ALIGN.CENTER,
                             0, 1)
        arc[2].clear_flag(lv.obj.FLAG.CLICKABLE)
        totalTime = lv.label(funcContainer)
        totalTime.set_text(str(timeCount[2]))
        totalTime.set_style_text_font(lv.font_montserrat_18, 0)
        totalTime.set_style_text_color(lv.color_white(), 0)
        totalTime.set_grid_cell(lv.GRID_ALIGN.CENTER, 2, 1,
                                lv.GRID_ALIGN.CENTER, 0, 1)
        totalTime.add_flag(lv.obj.FLAG.CLICKABLE)
        totalTime.add_event_cb(lambda e: arc_event_handler(e, 2),
                               lv.EVENT.CLICKED, None)
        totalTime.set_ext_click_area(30)

        arc[3] = lv.arc(funcContainer)
        arc[3].set_style_arc_color(lv.color_white(), lv.PART.INDICATOR)
        arc[3].set_style_arc_color(lv.color_make(0x33, 0x33, 0x33),
                                   lv.PART.MAIN)
        arc[3].set_range(0, maxMillionSecond)
        arc[3].set_size(55, 55)
        arc[3].set_rotation(90)
        arc[3].set_bg_angles(0, 360)
        arc[3].remove_style(None, lv.PART.KNOB)
        arc[3].set_value(0)
        arc[3].set_style_arc_width(2, lv.PART.INDICATOR)
        arc[3].set_style_arc_width(2, lv.PART.MAIN)
        arc[3].set_grid_cell(lv.GRID_ALIGN.CENTER, 3, 1, lv.GRID_ALIGN.CENTER,
                             0, 1)
        arc[3].clear_flag(lv.obj.FLAG.CLICKABLE)
        totalTime = lv.label(funcContainer)
        totalTime.set_text(str(timeCount[3]))
        totalTime.set_style_text_font(lv.font_montserrat_18, 0)
        totalTime.set_style_text_color(lv.color_white(), 0)
        totalTime.set_grid_cell(lv.GRID_ALIGN.CENTER, 3, 1,
                                lv.GRID_ALIGN.CENTER, 0, 1)
        totalTime.add_flag(lv.obj.FLAG.CLICKABLE)
        totalTime.add_event_cb(lambda e: arc_event_handler(e, 3),
                               lv.EVENT.CLICKED, None)
        totalTime.set_ext_click_area(30)

        from smart_panel import needAnimation
        if (needAnimation):
            lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.MOVE_LEFT, 500, 0, True)
        else:
            lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.NONE, 0, 0, True)

        timer_alive = True
示例#22
0
#!//opt/bin/lv_micropython -i
import time
import lvgl as lv
import display_driver

#
# Show customizing the circular scrolling animation of a label with `LV_LABEL_LONG_SCROLL_CIRCULAR`
# long mode.
#

animation_template = lv.anim_t()
label_style = lv.style_t()

animation_template.init()
animation_template.set_delay(1000)           # Wait 1 second to start the first scroll
animation_template.set_repeat_delay(3000)    # Repeat the scroll 3 seconds after the label scrolls back to the initial position

# initialize the label style with the animation template

label_style.init()
label_style.set_anim(animation_template)

label1 = lv.label(lv.scr_act())
label1.set_long_mode(lv.label.LONG.SCROLL_CIRCULAR)       # Circular scroll
label1.set_width(150)
label1.set_text("It is a circularly scrolling text. ")
label1.align(lv.ALIGN.CENTER, 0, 40)
label1.add_style(label_style, lv.STATE.DEFAULT)           # Add the style to the label

示例#23
0
scale_hour = meter.add_scale()
meter.set_scale_ticks(scale_hour, 12, 0, 0,
                      lv.palette_main(lv.PALETTE.GREY))  # 12 ticks
meter.set_scale_major_ticks(scale_hour, 1, 2, 20, lv.color_black(),
                            10)  # Every tick is major
meter.set_scale_range(scale_hour, 1, 12, 330,
                      300)  # [1..12] values in an almost full circle

#    LV_IMG_DECLARE(img_hand)

# Add the hands from images
indic_min = meter.add_needle_img(scale_min, img_hand_min_dsc, 5, 5)
indic_hour = meter.add_needle_img(scale_min, img_hand_hour_dsc, 5, 5)

# Create an animation to set the value
a1 = lv.anim_t()
a1.init()
a1.set_values(0, 60)
a1.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
a1.set_time(2000)  # 2 sec for 1 turn of the minute hand (1 hour)
a1.set_var(indic_min)
a1.set_custom_exec_cb(lambda a1, val: set_value(indic_min, val))
lv.anim_t.start(a1)

a2 = lv.anim_t()
a2.init()
a2.set_var(indic_hour)
a2.set_time(24000)  # 24 sec for 1 turn of the hour hand
a2.set_values(0, 60)
a2.set_custom_exec_cb(lambda a2, val: set_value(indic_hour, val))
lv.anim_t.start(a2)
示例#24
0
    def anim_timeline_create(self):
        # obj1
        self.a1 = lv.anim_t()
        self.a1.init()
        self.a1.set_values(0, self.obj_width)
        self.a1.set_early_apply(False)
        self.a1.set_custom_exec_cb(lambda a, v: self.set_width(self.obj1, v))
        self.a1.set_path_cb(lv.anim_t.path_overshoot)
        self.a1.set_time(300)

        self.a2 = lv.anim_t()
        self.a2.init()
        self.a2.set_values(0, self.obj_height)
        self.a2.set_early_apply(False)
        self.a2.set_custom_exec_cb(lambda a, v: self.set_height(self.obj1, v))
        self.a2.set_path_cb(lv.anim_t.path_ease_out)
        self.a2.set_time(300)

        # obj2
        self.a3 = lv.anim_t()
        self.a3.init()
        self.a3.set_values(0, self.obj_width)
        self.a3.set_early_apply(False)
        self.a3.set_custom_exec_cb(lambda a, v: self.set_width(self.obj2, v))
        self.a3.set_path_cb(lv.anim_t.path_overshoot)
        self.a3.set_time(300)

        self.a4 = lv.anim_t()
        self.a4.init()
        self.a4.set_values(0, self.obj_height)
        self.a4.set_early_apply(False)
        self.a4.set_custom_exec_cb(lambda a, v: self.set_height(self.obj2, v))
        self.a4.set_path_cb(lv.anim_t.path_ease_out)
        self.a4.set_time(300)

        # obj3
        self.a5 = lv.anim_t()
        self.a5.init()
        self.a5.set_values(0, self.obj_width)
        self.a5.set_early_apply(False)
        self.a5.set_custom_exec_cb(lambda a, v: self.set_width(self.obj3, v))
        self.a5.set_path_cb(lv.anim_t.path_overshoot)
        self.a5.set_time(300)

        self.a6 = lv.anim_t()
        self.a6.init()
        self.a6.set_values(0, self.obj_height)
        self.a6.set_early_apply(False)
        self.a6.set_custom_exec_cb(lambda a, v: self.set_height(self.obj3, v))
        self.a6.set_path_cb(lv.anim_t.path_ease_out)
        self.a6.set_time(300)

        # Create anim timeline
        print("Create new anim_timeline")
        self.anim_timeline = lv.anim_timeline_create()
        lv.anim_timeline_add(self.anim_timeline, 0, self.a1)
        lv.anim_timeline_add(self.anim_timeline, 0, self.a2)
        lv.anim_timeline_add(self.anim_timeline, 200, self.a3)
        lv.anim_timeline_add(self.anim_timeline, 200, self.a4)
        lv.anim_timeline_add(self.anim_timeline, 400, self.a5)
        lv.anim_timeline_add(self.anim_timeline, 400, self.a6)
示例#25
0
    def scan_next_event_cb(self, obj, evt):
        LV_IMG_ZOOM_NONE = 250
        if evt == lv.EVENT.CLICKED:
            self.anim_out_all(lv.scr_act(), 0)

            delay = 400

            back = self.add_back(self.back_to_home_event_cb)
            self.anim_in(back, delay)

            title = self.add_title("ADJUST IMAGE")
            self.anim_in(title, delay)

            box_w = 400
            self.scan_img.set_pivot(0, 0)
            self.scan_img.set_antialias(False)

            a = lv.anim_t()
            a.init()
            a.set_var(self.scan_img)
            a.set_custom_exec_cb(
                lambda a, val: self.set_zoom(self.scan_img, val))
            a.set_values(LV_IMG_ZOOM_NONE, 190)
            a.set_time(200)
            a.set_delay(200)
            lv.anim_t.start(a)

            # self.scan_img = None    # To allow anim out

            dropdown_box = lv.obj(lv.scr_act(), None)
            dropdown_box.set_size(box_w, self.LV_VER_RES // 5)
            dropdown_box.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 40, -20)

            dropdown = lv.dropdown(dropdown_box, None)
            dropdown.align(None, lv.ALIGN.IN_LEFT_MID, self.LV_HOR_RES // 60,
                           0)
            dropdown.set_max_height(self.LV_VER_RES // 3)
            dropdown.set_options_static("Best\nNormal\nDraft")
            dropdown.set_width((box_w - 3 * self.LV_HOR_RES // 60) // 2)
            self.theme.apply(dropdown, lv.THEME.DROPDOWN)

            dropdown = lv.dropdown(dropdown_box, dropdown)
            dropdown.align(None, lv.ALIGN.IN_RIGHT_MID, -self.LV_HOR_RES // 60,
                           0)
            dropdown.set_options_static(
                "72 DPI\n96 DPI\n150 DPI\n300 DPI\n600 DPI\n900 DPI\n1200 DPI")
            self.theme.apply(dropdown, lv.THEME.DROPDOWN)

            box_w = 320 - 40
            settings_box = lv.obj(lv.scr_act(), None)
            settings_box.set_size(box_w, self.LV_VER_RES // 2)
            settings_box.align(None, lv.ALIGN.IN_TOP_RIGHT, -40, 100)

            numbox = lv.cont(settings_box, None)
            self.theme.apply(numbox, LV_DEMO_PRINTER_THEME_BOX_BORDER)
            numbox.set_size(self.LV_HOR_RES // 7, self.LV_HOR_RES // 13)
            numbox.align(settings_box, lv.ALIGN.IN_TOP_MID, 0,
                         self.LV_VER_RES // 10)
            numbox.set_style_local_value_str(lv.obj.PART.MAIN,
                                             lv.STATE.DEFAULT, "Copies")
            numbox.set_style_local_value_align(lv.obj.PART.MAIN,
                                               lv.STATE.DEFAULT,
                                               lv.ALIGN.OUT_TOP_MID)
            numbox.set_style_local_value_ofs_y(lv.obj.PART.MAIN,
                                               lv.STATE.DEFAULT,
                                               -self.LV_VER_RES // 50)
            numbox.set_style_local_value_font(lv.obj.PART.MAIN,
                                              lv.STATE.DEFAULT,
                                              self.theme.get_font_subtitle())
            numbox.set_layout(lv.LAYOUT.CENTER)

            self.print_cnt = 1
            self.print_cnt_label = lv.label(numbox, None)
            self.print_cnt_label.set_text("1")
            self.print_cnt_label.set_style_local_text_font(
                lv.label.PART.MAIN, lv.STATE.DEFAULT,
                self.theme.get_font_subtitle())

            btn = lv.btn(settings_box, None)
            btn.set_size(self.LV_HOR_RES // 13, self.LV_HOR_RES // 13)
            btn.align(numbox, lv.ALIGN.OUT_LEFT_MID, -self.LV_VER_RES // 60, 0)
            btn.set_style_local_value_str(lv.obj.PART.MAIN, lv.STATE.DEFAULT,
                                          lv.SYMBOL.DOWN)
            btn.set_style_local_value_font(lv.obj.PART.MAIN, lv.STATE.DEFAULT,
                                           self.theme.get_font_subtitle())
            btn.set_event_cb(self.print_cnt_btn_event_cb)
            btn.set_ext_click_area(10, 10, 10, 10)
            self.theme.apply(btn, lv.THEME.BTN)

            sw = lv.switch(settings_box, None)
            sw.set_size(self.LV_HOR_RES // 10, self.LV_VER_RES // 12)
            sw.align(btn, lv.ALIGN.OUT_BOTTOM_LEFT, self.LV_HOR_RES // 50,
                     self.LV_VER_RES // 7)
            sw.set_style_local_value_ofs_y(lv.obj.PART.MAIN, lv.STATE.DEFAULT,
                                           -self.LV_VER_RES // 50)
            sw.set_style_local_value_align(lv.obj.PART.MAIN, lv.STATE.DEFAULT,
                                           lv.ALIGN.OUT_TOP_MID)
            sw.set_style_local_value_str(lv.obj.PART.MAIN, lv.STATE.DEFAULT,
                                         "Color")
            sw.set_style_local_value_font(lv.obj.PART.MAIN, lv.STATE.DEFAULT,
                                          self.theme.get_font_subtitle())
            self.theme.apply(sw, lv.THEME.SWITCH)

            btn = lv.btn(settings_box, btn)
            btn.align(numbox, lv.ALIGN.OUT_RIGHT_MID, self.LV_VER_RES // 60, 0)
            btn.set_style_local_value_str(lv.obj.PART.MAIN, lv.STATE.DEFAULT,
                                          lv.SYMBOL.UP)
            btn.set_event_cb(self.print_cnt_btn_event_cb)
            self.theme.apply(btn, lv.THEME.BTN)

            sw = lv.switch(settings_box, sw)
            sw.align(btn, lv.ALIGN.OUT_BOTTOM_RIGHT, -self.LV_HOR_RES // 50,
                     self.LV_VER_RES // 7)
            sw.set_style_local_value_str(lv.obj.PART.MAIN, lv.STATE.DEFAULT,
                                         "Vertical")

            print_btn = lv.btn(lv.scr_act(), None)
            self.theme.apply(print_btn, LV_DEMO_PRINTER_THEME_BTN_CIRCLE)
            print_btn.set_size(box_w, 60)
            print_btn.set_event_cb(self.print_start_event_cb)

            btn_ofs_y = (dropdown_box.get_height() -
                         print_btn.get_height()) // 2
            print_btn.align(settings_box, lv.ALIGN.OUT_BOTTOM_MID, 0,
                            self.LV_HOR_RES // 30 + btn_ofs_y)
            print_btn.set_style_local_value_str(lv.obj.PART.MAIN,
                                                lv.STATE.DEFAULT, "PRINT")
            print_btn.set_style_local_value_font(
                lv.obj.PART.MAIN, lv.STATE.DEFAULT,
                self.theme.get_font_subtitle())
            print_btn.set_style_local_bg_color(lv.obj.PART.MAIN,
                                               lv.STATE.DEFAULT,
                                               LV_DEMO_PRINTER_GREEN)
            print_btn.set_style_local_bg_color(
                lv.obj.PART.MAIN, lv.STATE.PRESSED,
                LV_DEMO_PRINTER_GREEN.color_darken(lv.OPA._20))

            delay += self.LV_DEMO_PRINTER_ANIM_DELAY
            self.anim_in(settings_box, delay)

            delay += self.LV_DEMO_PRINTER_ANIM_DELAY
            self.anim_in(dropdown_box, delay)

            delay += self.LV_DEMO_PRINTER_ANIM_DELAY
            self.anim_in(print_btn, delay)

            self.anim_bg(0, LV_DEMO_PRINTER_BLUE,
                         self.LV_DEMO_PRINTER_BG_NORMAL)
示例#26
0
    def createPage(self):
        global anim
        global playedTime
        global durationTime
        global slider
        global audio_src
        global player
        global image
        global music_alive
        global currentMusic
        global albumCover
        global songTitle
        global albumTitle
        global totalTime
        global anim_timeline
        global scr

        print("Enter Music")

        # init scr
        scr = lv.obj()

        win = lv.obj(scr)
        win.set_size(scr.get_width(), scr.get_height())
        win.set_style_border_opa(0, 0)
        win.set_style_radius(0, 0)
        win.set_style_bg_color(lv.color_black(), 0)
        win.clear_flag(lv.obj.FLAG.SCROLLABLE)

        backImg = lv.img(win)
        backImg.set_src(RESOURCES_ROOT + "images/back.png")
        backImg.set_style_align(lv.ALIGN.LEFT_MID, 0)
        backImg.add_flag(lv.obj.FLAG.CLICKABLE)
        backImg.add_event_cb(lambda e: music_back_click_callback(e, win),
                             lv.EVENT.CLICKED, None)
        backImg.add_event_cb(lambda e: music_back_press_callback(e, backImg),
                             lv.EVENT.PRESSED, None)
        backImg.add_event_cb(lambda e: music_back_release_callback(e, backImg),
                             lv.EVENT.RELEASED, None)
        backImg.set_ext_click_area(30)

        albumCover = lv.img(win)
        albumCover.set_style_pad_left(12, 0)
        albumCover.set_style_pad_top(10, 0)

        songTitle = lv.label(win)
        songTitle.set_style_text_font(lv.font_montserrat_20, 0)
        songTitle.set_style_text_color(lv.color_white(), 0)
        songTitle.align_to(albumCover, lv.ALIGN.TOP_LEFT, 130, 3)

        albumTitle = lv.label(win)
        albumTitle.set_style_text_font(lv.font_montserrat_16, 0)
        albumTitle.set_style_text_color(lv.color_make(0xCC, 0xCC, 0xCC), 0)
        albumTitle.align_to(songTitle, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 12)

        props = [lv.STYLE.BG_COLOR, 0]
        transition_dsc = lv.style_transition_dsc_t()
        transition_dsc.init(props, lv.anim_t.path_linear, 300, 0, None)

        style_main = lv.style_t()
        style_indicator = lv.style_t()
        style_pressed_color = lv.style_t()
        style_main.init()
        style_main.set_bg_opa(lv.OPA.COVER)
        style_main.set_bg_color(lv.color_make(0x66, 0x66, 0x66))
        style_main.set_radius(lv.RADIUS.CIRCLE)
        style_main.set_line_dash_width(1)

        style_indicator.init()
        style_indicator.set_bg_opa(lv.OPA.COVER)
        style_indicator.set_bg_color(lv.color_white())
        style_indicator.set_radius(lv.RADIUS.CIRCLE)
        style_indicator.set_transition(transition_dsc)

        style_pressed_color.init()
        style_pressed_color.set_bg_color(lv.color_white())

        # Create a slider and add the style
        slider = lv.slider(win)
        slider.remove_style_all()  # Remove the styles coming from the theme

        slider.add_style(style_main, lv.PART.MAIN)
        slider.add_style(style_indicator, lv.PART.INDICATOR)
        slider.add_style(style_pressed_color,
                         lv.PART.INDICATOR | lv.STATE.PRESSED)
        slider.align_to(albumTitle, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 25)
        slider.set_size(140, 1)

        anim = lv.anim_t()
        anim.init()
        anim.set_var(slider)

        playedTime = lv.label(win)
        setLabelValue(playedTime, 0)
        playedTime.set_style_text_font(lv.font_montserrat_16, 0)
        playedTime.set_style_text_color(lv.color_white(), 0)
        playedTime.align_to(slider, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 15)

        totalTime = lv.label(win)
        totalTime.set_style_text_font(lv.font_montserrat_16, 0)
        totalTime.set_style_text_color(lv.color_white(), 0)
        totalTime.align_to(slider, lv.ALIGN.OUT_BOTTOM_RIGHT, 0, 15)

        func_col_dsc = [80, 80, 80, 80, lv.GRID_TEMPLATE.LAST]
        func_row_dsc = [40, lv.GRID_TEMPLATE.LAST]

        funcContainer = lv.obj(win)
        funcContainer.set_style_bg_opa(0x00, 0)
        funcContainer.set_style_border_opa(0x00, 0)
        funcContainer.set_layout(lv.LAYOUT_GRID.value)
        funcContainer.set_grid_dsc_array(func_col_dsc, func_row_dsc)
        funcContainer.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN,
                                     lv.GRID_ALIGN.SPACE_BETWEEN)
        funcContainer.set_align(lv.ALIGN.BOTTOM_MID)
        funcContainer.set_size(320, 70)

        for i in range(4):
            image[i] = lv.img(funcContainer)
            image[i].set_src(functionImage[i])
            image[i].add_flag(lv.obj.FLAG.CLICKABLE)
            image[i].set_ext_click_area(20)
            image[i].set_grid_cell(lv.GRID_ALIGN.CENTER, i, 1,
                                   lv.GRID_ALIGN.CENTER, 0, 1)

            if (i == 0):
                image[i].add_event_cb(lambda e: controller_click_cb(e, "prev"),
                                      lv.EVENT.CLICKED, None)
            elif (i == 1):
                image[i].add_event_cb(lambda e: controller_click_cb(e, "play"),
                                      lv.EVENT.CLICKED, None)
            elif (i == 2):
                image[i].add_event_cb(lambda e: controller_click_cb(e, "next"),
                                      lv.EVENT.CLICKED, None)
            elif (i == 3):
                image[i].add_event_cb(lambda e: controller_click_cb(e, "fav"),
                                      lv.EVENT.CLICKED, None)

        anim.set_custom_exec_cb(lambda a1, val: setSpentTime(slider, val))
        reset_music()

        from smart_panel import needAnimation
        if (needAnimation):
            lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.MOVE_LEFT, 500, 0, True)
        else:
            lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.NONE, 0, 0, True)

        music_alive = True