example(micropython): updated MicroPython examples according to LVGL changes (#4031)
This commit is contained in:
@@ -1,30 +1,20 @@
|
||||
#
|
||||
# get an icon
|
||||
#
|
||||
def get_icon(filename,xres,yres):
|
||||
try:
|
||||
sdl_filename = "../../assets/" + filename + "_" + str(xres) + "x" + str(yres) + "_argb8888.fnt"
|
||||
print("file name: ", sdl_filename)
|
||||
with open(sdl_filename,'rb') as f:
|
||||
icon_data = f.read()
|
||||
except:
|
||||
print("Could not find image file: " + filename)
|
||||
return None
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_strip.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find img_strip.png")
|
||||
sys.exit()
|
||||
|
||||
icon_dsc = lv.img_dsc_t(
|
||||
{
|
||||
"header": {"always_zero": 0, "w": xres, "h": yres, "cf": lv.COLOR_FORMAT.NATIVE_ALPHA},
|
||||
"data": icon_data,
|
||||
"data_size": len(icon_data),
|
||||
}
|
||||
)
|
||||
return icon_dsc
|
||||
img_skew_strip_dsc = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
#
|
||||
# Bar with stripe pattern and ranged value
|
||||
#
|
||||
|
||||
img_skew_strip_dsc = get_icon("img_skew_strip",80,20)
|
||||
style_indic = lv.style_t()
|
||||
|
||||
style_indic.init()
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import lvgl as lv
|
||||
|
||||
default_group = lv.group_create()
|
||||
default_group.set_default()
|
||||
|
||||
lv.sdl_window_create(480, 320)
|
||||
sdl_indev = lv.sdl_mouse_create()
|
||||
sdl_indev.set_group(default_group)
|
||||
|
||||
def set_value(bar, v):
|
||||
bar.set_value(v, lv.ANIM.OFF)
|
||||
|
||||
def event_cb(e):
|
||||
dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param())
|
||||
if dsc.part != lv.PART.INDICATOR:
|
||||
return
|
||||
|
||||
obj= e.get_target_obj()
|
||||
|
||||
label_dsc = lv.draw_label_dsc_t()
|
||||
label_dsc.init()
|
||||
# label_dsc.font = LV_FONT_DEFAULT;
|
||||
|
||||
value_txt = str(obj.get_value())
|
||||
txt_size = lv.point_t()
|
||||
lv.txt_get_size(txt_size, value_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, lv.COORD.MAX, label_dsc.flag)
|
||||
|
||||
txt_area = lv.area_t()
|
||||
# If the indicator is long enough put the text inside on the right
|
||||
if dsc.draw_area.get_width() > txt_size.x + 20:
|
||||
txt_area.x2 = dsc.draw_area.x2 - 5
|
||||
txt_area.x1 = txt_area.x2 - txt_size.x + 1
|
||||
label_dsc.color = lv.color_white()
|
||||
# If the indicator is still short put the text out of it on the right*/
|
||||
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
|
||||
|
||||
dsc.draw_ctx.label(label_dsc, txt_area, value_txt, None)
|
||||
|
||||
#
|
||||
# Custom drawer on the bar to display the current value
|
||||
#
|
||||
|
||||
bar = lv.bar(lv.scr_act())
|
||||
bar.add_event(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)
|
||||
|
||||
Reference in New Issue
Block a user