You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Simplify
This commit is contained in:
@@ -2,29 +2,41 @@ appscreen = lv.screen_active()
|
||||
|
||||
import lvgl as lv
|
||||
|
||||
class DrawApp:
|
||||
def __init__(self):
|
||||
self.canvas = None
|
||||
self.init_gui()
|
||||
def init_gui(self):
|
||||
self.canvas = lv.canvas(lv.screen_active())
|
||||
disp = lv.display_get_default()
|
||||
self.canvas.set_size(disp.get_hor_res(), disp.get_ver_res())
|
||||
self.canvas.set_style_bg_color(lv.color_white(), 0)
|
||||
buffer = bytearray(disp.get_hor_res() * disp.get_ver_res() * 4)
|
||||
self.canvas.set_buffer(buffer, disp.get_hor_res(), disp.get_ver_res(), lv.COLOR_FORMAT.NATIVE)
|
||||
self.canvas.fill_bg(lv.color_white(), lv.OPA.COVER)
|
||||
self.canvas.add_event_cb(self.touch_cb, lv.EVENT.PRESSING, None)
|
||||
def touch_cb(self, obj, event, user_data):
|
||||
if event == lv.EVENT.PRESSING:
|
||||
def touch_cb(event):
|
||||
global canvas
|
||||
event_code=event.get_code()
|
||||
if event_code not in [23,25,26,27,28,29,30,49]:
|
||||
#print(f"got event: {event}")
|
||||
print(f"lv_event_t: code={event_code}, target={event.get_target()}, user_data={event.get_user_data()}, param={event.get_param()}")
|
||||
if event_code == lv.EVENT.PRESSING:
|
||||
print("lv.EVENT.PRESSING")
|
||||
indev = lv.indev_active()
|
||||
if indev:
|
||||
point = indev.get_point()
|
||||
x, y = point.x, point.y
|
||||
self.canvas.draw_arc(x, y, 5, 0, 360, lv.color_black())
|
||||
#point = indev.get_point()
|
||||
#x, y = point.x, point.y
|
||||
import random
|
||||
x = random.randrange(1,200)
|
||||
y = random.randrange(1,200)
|
||||
#print(f"got indev {x} {y} {point}")
|
||||
#canvas.draw_arc(x, y, 5, 0, 360, lv.color_black())
|
||||
canvas.set_px(x,y,lv.color_black(),lv.OPA.COVER)
|
||||
else:
|
||||
print("no indev!")
|
||||
|
||||
|
||||
canvas = lv.canvas(appscreen)
|
||||
disp = lv.display_get_default()
|
||||
hor_res = disp.get_horizontal_resolution()
|
||||
ver_res = disp.get_vertical_resolution()
|
||||
canvas.set_size(hor_res, ver_res)
|
||||
canvas.set_style_bg_color(lv.color_white(), 0)
|
||||
buffer = bytearray(hor_res * ver_res * 4)
|
||||
canvas.set_buffer(buffer, hor_res, ver_res, lv.COLOR_FORMAT.NATIVE)
|
||||
canvas.fill_bg(lv.color_white(), lv.OPA.COVER)
|
||||
canvas.add_flag(lv.obj.FLAG.CLICKABLE)
|
||||
canvas.add_event_cb(touch_cb, lv.EVENT.ALL, None)
|
||||
|
||||
draw_app = DrawApp()
|
||||
|
||||
# Wait until the user closes the app
|
||||
while appscreen == lv.screen_active():
|
||||
time.sleep_ms(1000)
|
||||
#while appscreen == lv.screen_active():
|
||||
# time.sleep_ms(1000)
|
||||
|
||||
Reference in New Issue
Block a user