example(micropython): updated MicroPython examples according to LVGL changes (#4031)

This commit is contained in:
Uli Raich
2023-03-10 21:44:12 +01:00
committed by GitHub
parent 55c9a9220b
commit d1c6c61780
24 changed files with 394 additions and 225 deletions

View File

@@ -1,8 +1,23 @@
def value_changed_event_cb(e,label):
arc = e.get_target_obj()
txt = "{:d}%".format(arc.get_value())
label.set_text(txt)
# Rotate the label to the current position of the arc
arc.rotate_obj_to_angle(label, 25)
label = lv.label(lv.scr_act())
# Create an Arc
arc = lv.arc(lv.scr_act())
arc.set_end_angle(200)
arc.set_size(150, 150)
arc.set_rotation(135)
arc.set_bg_angles(0, 270)
arc.set_value(10)
arc.center()
arc.add_event(lambda e: value_changed_event_cb(e,label),lv.EVENT.VALUE_CHANGED, None)
# Manually update the label for the first time
arc.send_event(lv.EVENT.VALUE_CHANGED, None)

View File

@@ -1,37 +1,24 @@
#
# An `lv_timer` to call periodically to set the angles of the arc
#
class ArcLoader():
def __init__(self):
self.a = 270
def arc_loader_cb(self,tim,arc):
# print(tim,arc)
self.a += 5
arc.set_end_angle(self.a)
if self.a >= 270 + 360:
tim._del()
def set_angle(obj, v):
obj.set_value(v)
#
# Create an arc which acts as a loader.
#
# Create an Arc
arc = lv.arc(lv.scr_act())
arc.set_rotation(270)
arc.set_bg_angles(0, 360)
arc.set_angles(270, 270)
arc.remove_style(None, lv.PART.KNOB) # Be sure the knob is not displayed
arc.clear_flag(lv.obj.FLAG.CLICKABLE) #To not allow adjusting by click
arc.center()
# create the loader
arc_loader = ArcLoader()
# Create an `lv_timer` to update the arc.
timer = lv.timer_create_basic()
timer.set_period(20)
timer.set_cb(lambda src: arc_loader.arc_loader_cb(timer,arc))
a = lv.anim_t()
a.init()
a.set_var(arc)
a.set_time(1000)
a.set_repeat_count(lv.ANIM_REPEAT_INFINITE) #Just for the demo
a.set_repeat_delay(500)
a.set_values(0, 100)
a.set_custom_exec_cb(lambda a,val: set_angle(arc,val))
lv.anim_t.start(a)