You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
camera: add explicit close button
This workaround the slow draw-from-top gesture.
This commit is contained in:
@@ -39,6 +39,7 @@ appscreen = lv.screen_active()
|
||||
#width = 120
|
||||
#height = 160
|
||||
|
||||
keepgoing = True
|
||||
width = 240
|
||||
height = 240
|
||||
|
||||
@@ -48,14 +49,31 @@ cont.set_style_border_width(0, 0)
|
||||
cont.set_size(lv.pct(100), lv.pct(100))
|
||||
cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
|
||||
|
||||
button = lv.button(cont)
|
||||
button.set_size(40, 40)
|
||||
button.align(lv.ALIGN.RIGHT_MID, 0, -20)
|
||||
def snap_button(e):
|
||||
snap_button = lv.button(cont)
|
||||
snap_button.set_size(60, 60)
|
||||
snap_button.align(lv.ALIGN.RIGHT_MID, 0, -20)
|
||||
snap_label = lv.label(snap_button)
|
||||
snap_label.set_text(lv.SYMBOL.OK)
|
||||
snap_label.center()
|
||||
def snap_button_click(e):
|
||||
print("Picture taken!")
|
||||
# TODO: keep it on-screen for a while, or save it to storage, or show it in miniature
|
||||
|
||||
button.add_event_cb(snap_button,lv.EVENT.CLICKED,None)
|
||||
snap_button.add_event_cb(snap_button_click,lv.EVENT.CLICKED,None)
|
||||
|
||||
|
||||
close_button = lv.button(cont)
|
||||
close_button.set_size(40,40)
|
||||
close_button.align(lv.ALIGN.TOP_RIGHT, 0, 0)
|
||||
close_label = lv.label(close_button)
|
||||
close_label.set_text(lv.SYMBOL.CLOSE)
|
||||
close_label.center()
|
||||
def close_button_click(e):
|
||||
global keepgoing
|
||||
print("Closing camera!")
|
||||
keepgoing = False
|
||||
|
||||
close_button.add_event_cb(close_button_click,lv.EVENT.CLICKED,None)
|
||||
|
||||
|
||||
from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling
|
||||
@@ -134,9 +152,11 @@ try_capture()
|
||||
|
||||
|
||||
import time
|
||||
while appscreen == lv.screen_active():
|
||||
while appscreen == lv.screen_active() and keepgoing:
|
||||
try_capture()
|
||||
time.sleep_ms(100) # Allow for the MicroPython REPL to still work. Reducing it doesn't seem to affect the on-display FPS.
|
||||
|
||||
print("App backgrounded, deinitializing camera...")
|
||||
cam.deinit()
|
||||
|
||||
show_launcher()
|
||||
|
||||
@@ -240,9 +240,9 @@ launcher_label.center()
|
||||
launcher_label.set_style_text_color(COLOR_DRAWER_BUTTONTEXT,0)
|
||||
def launcher_event(e):
|
||||
print("Launcher button pressed!")
|
||||
global drawer_open,rootscreen
|
||||
global drawer_open
|
||||
close_drawer(True)
|
||||
lv.screen_load(rootscreen)
|
||||
show_launcher()
|
||||
|
||||
launcher_btn.add_event_cb(launcher_event,lv.EVENT.CLICKED,None)
|
||||
#
|
||||
@@ -330,6 +330,7 @@ def execute_script(script_source, is_file, is_launcher, is_graphical):
|
||||
'start_app': start_app, # for launcher apps
|
||||
'parse_manifest': parse_manifest, # for launcher apps
|
||||
'restart_launcher': restart_launcher, # for appstore apps
|
||||
'show_launcher': show_launcher, # for apps that want to show the launcher
|
||||
'__name__': "__main__"
|
||||
}
|
||||
print(f"Thread {thread_id}: starting script")
|
||||
@@ -393,6 +394,11 @@ def start_app(app_dir, is_launcher=False):
|
||||
else:
|
||||
close_bar()
|
||||
|
||||
def show_launcher():
|
||||
global rootscreen
|
||||
open_bar()
|
||||
lv.screen_load(rootscreen)
|
||||
|
||||
def restart_launcher():
|
||||
# No need to stop the other launcher first, because it exits after building the screen
|
||||
start_app_by_name("com.example.launcher", True)
|
||||
|
||||
Reference in New Issue
Block a user