Skip to content

Commit 68dd24d

Browse files
adapt apps to new "back button" paradigm
1 parent d891eda commit 68dd24d

File tree

9 files changed

+230
-103
lines changed

9 files changed

+230
-103
lines changed

internal_filesystem/apps/com.example.camtest/assets/camtest.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
import time
99

10+
import mpos.apps
11+
import mpos.ui
12+
13+
# screens:
14+
main_screen = None
15+
1016
keepliveqrdecoding = False
1117
width = 240
1218
height = 240
@@ -72,7 +78,7 @@ def qrdecode_one():
7278

7379
def close_button_click(e):
7480
print("Close button clicked")
75-
show_launcher()
81+
mpos.ui.back_screen()
7682

7783

7884
def snap_button_click(e):
@@ -142,28 +148,28 @@ def try_capture(event):
142148

143149

144150
def build_ui():
145-
global image, image_dsc,qr_label, status_label, cam, use_webcam, qr_button, snap_button, status_label_cont
146-
cont = lv.obj(appscreen)
147-
cont.set_style_pad_all(0, 0)
148-
cont.set_style_border_width(0, 0)
149-
cont.set_size(lv.pct(100), lv.pct(100))
150-
cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
151-
close_button = lv.button(cont)
151+
global image, image_dsc,qr_label, status_label, cam, use_webcam, qr_button, snap_button, status_label_cont, main_screen
152+
main_screen = lv.obj()
153+
main_screen.set_style_pad_all(0, 0)
154+
main_screen.set_style_border_width(0, 0)
155+
main_screen.set_size(lv.pct(100), lv.pct(100))
156+
main_screen.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
157+
close_button = lv.button(main_screen)
152158
close_button.set_size(60,60)
153159
close_button.align(lv.ALIGN.TOP_RIGHT, 0, 0)
154160
close_label = lv.label(close_button)
155161
close_label.set_text(lv.SYMBOL.CLOSE)
156162
close_label.center()
157163
close_button.add_event_cb(close_button_click,lv.EVENT.CLICKED,None)
158-
snap_button = lv.button(cont)
164+
snap_button = lv.button(main_screen)
159165
snap_button.set_size(60, 60)
160166
snap_button.align(lv.ALIGN.RIGHT_MID, 0, 0)
161167
snap_button.add_flag(lv.obj.FLAG.HIDDEN)
162168
snap_label = lv.label(snap_button)
163169
snap_label.set_text(lv.SYMBOL.OK)
164170
snap_label.center()
165171
snap_button.add_event_cb(snap_button_click,lv.EVENT.CLICKED,None)
166-
qr_button = lv.button(cont)
172+
qr_button = lv.button(main_screen)
167173
qr_button.set_size(60, 60)
168174
qr_button.add_flag(lv.obj.FLAG.HIDDEN)
169175
qr_button.align(lv.ALIGN.BOTTOM_RIGHT, 0, 0)
@@ -172,7 +178,7 @@ def build_ui():
172178
qr_label.center()
173179
qr_button.add_event_cb(qr_button_click,lv.EVENT.CLICKED,None)
174180
# Initialize LVGL image widget
175-
image = lv.image(cont)
181+
image = lv.image(main_screen)
176182
image.align(lv.ALIGN.LEFT_MID, 0, 0)
177183
# Create image descriptor once
178184
image_dsc = lv.image_dsc_t({
@@ -188,7 +194,7 @@ def build_ui():
188194
'data': None # Will be updated per frame
189195
})
190196
image.set_src(image_dsc)
191-
status_label_cont = lv.obj(appscreen)
197+
status_label_cont = lv.obj(main_screen)
192198
status_label_cont.set_size(lv.pct(66),lv.pct(60))
193199
status_label_cont.align(lv.ALIGN.LEFT_MID, lv.pct(5), 0)
194200
status_label_cont.set_style_bg_color(lv.color_white(), 0)
@@ -200,6 +206,7 @@ def build_ui():
200206
status_label.set_style_text_color(lv.color_white(), 0)
201207
status_label.set_width(lv.pct(100))
202208
status_label.center()
209+
mpos.ui.load_screen(main_screen)
203210

204211

205212
def init_cam():
@@ -235,7 +242,7 @@ def init_cam():
235242

236243

237244
def check_running(timer):
238-
if lv.screen_active() != appscreen:
245+
if lv.screen_active() != main_screen:
239246
print("camtest.py backgrounded, cleaning up...")
240247
check_running_timer.delete()
241248
if capture_timer:
@@ -248,7 +255,6 @@ def check_running(timer):
248255

249256

250257

251-
appscreen = lv.screen_active()
252258
build_ui()
253259

254260
cam = init_cam()

internal_filesystem/boot_unix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def swipe_read_cb(indev_drv, data):
6161
# Mouse/touch pressed (start of potential swipe)
6262
start_y = y # Store Y for vertical swipe detection
6363
start_x = x # Store X for horizontal swipe detection
64-
print(f"Mouse press at X={start_x}, Y={start_y}")
64+
#print(f"Mouse press at X={start_x}, Y={start_y}")
6565

6666
# Check if press is in notification bar (for swipe down)
6767
if y <= mpos.ui.NOTIFICATION_BAR_HEIGHT:

internal_filesystem/builtin/apps/com.example.appstore/assets/appstore.py

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import _thread
88

99
import mpos.apps
10+
import mpos.ui
1011

1112
# Screens:
1213
app_detail_screen = None
13-
appscreen = lv.screen_active()
14+
main_screen = None
1415

1516
apps = []
1617
update_button = None
@@ -58,10 +59,10 @@ def is_update_available(app_fullname, new_version):
5859
installed_app=None
5960
if is_installed_by_path(appdir):
6061
print(f"{appdir} found, getting version...")
61-
installed_app = parse_manifest(f"{appdir}/META-INF/MANIFEST.JSON")
62+
installed_app = mpos.apps.parse_manifest(f"{appdir}/META-INF/MANIFEST.JSON")
6263
elif is_installed_by_path(builtinappdir):
6364
print(f"{builtinappdir} found, getting version...")
64-
installed_app = parse_manifest(f"{builtinappdir}/META-INF/MANIFEST.JSON")
65+
installed_app = mpos.apps.parse_manifest(f"{builtinappdir}/META-INF/MANIFEST.JSON")
6566
if not installed_app or installed_app.version == "0.0.0": # special case, if the installed app doesn't have a version number then there's no update
6667
return False
6768
return compare_versions(new_version, installed_app.version)
@@ -264,10 +265,14 @@ def load_icon(icon_path):
264265
return image_dsc
265266

266267
def create_apps_list():
267-
global apps
268+
global apps, main_screen
269+
main_screen = lv.obj()
270+
please_wait_label = lv.label(main_screen)
271+
please_wait_label.set_text("Downloading app index...")
272+
please_wait_label.center()
268273
default_icon_dsc = load_icon("builtin/res/mipmap-mdpi/default_icon_64x64.png")
269274
print("create_apps_list")
270-
apps_list = lv.list(appscreen)
275+
apps_list = lv.list(main_screen)
271276
apps_list.set_style_pad_all(0, 0)
272277
apps_list.set_size(lv.pct(100), lv.pct(100))
273278
print("create_apps_list iterating")
@@ -300,6 +305,7 @@ def create_apps_list():
300305
desc_label.set_style_text_font(lv.font_montserrat_12, 0)
301306
desc_label.add_event_cb(lambda e, a=app: show_app_detail(a), lv.EVENT.CLICKED, None)
302307
print("create_apps_list app done")
308+
mpos.ui.load_screen(main_screen)
303309
try:
304310
_thread.stack_size(16*1024)
305311
_thread.start_new_thread(download_icons,())
@@ -309,21 +315,21 @@ def create_apps_list():
309315

310316
def show_app_detail(app):
311317
global app_detail_screen, install_button, progress_bar, install_label
318+
#app_detail_screen = lv.obj()
319+
#app_detail_screen.set_size(lv.pct(100), lv.pct(100))
320+
#back_button = lv.button(app_detail_screen)
321+
#back_button.set_width(lv.pct(15))
322+
#back_button.add_flag(lv.obj.FLAG.CLICKABLE)
323+
#back_button.add_event_cb(back_to_main, lv.EVENT.CLICKED, None)
324+
#back_label = lv.label(back_button)
325+
#back_label.set_text(lv.SYMBOL.LEFT)
326+
#back_label.center()
312327
app_detail_screen = lv.obj()
313328
app_detail_screen.set_size(lv.pct(100), lv.pct(100))
314-
back_button = lv.button(app_detail_screen)
315-
back_button.set_width(lv.pct(15))
316-
back_button.add_flag(lv.obj.FLAG.CLICKABLE)
317-
back_button.add_event_cb(back_to_main, lv.EVENT.CLICKED, None)
318-
back_label = lv.label(back_button)
319-
back_label.set_text(lv.SYMBOL.LEFT)
320-
back_label.center()
321-
cont = lv.obj(app_detail_screen)
322-
cont.set_size(lv.pct(100), lv.pct(100))
323-
cont.set_pos(0, 40)
324-
cont.set_flex_flow(lv.FLEX_FLOW.COLUMN)
329+
app_detail_screen.set_pos(0, 40)
330+
app_detail_screen.set_flex_flow(lv.FLEX_FLOW.COLUMN)
325331
#
326-
headercont = lv.obj(cont)
332+
headercont = lv.obj(app_detail_screen)
327333
headercont.set_style_pad_all(0, 0)
328334
headercont.set_flex_flow(lv.FLEX_FLOW.ROW)
329335
headercont.set_size(lv.pct(100), lv.SIZE_CONTENT)
@@ -344,12 +350,12 @@ def show_app_detail(app):
344350
publisher_label.set_text(app.publisher)
345351
publisher_label.set_style_text_font(lv.font_montserrat_16, 0)
346352
#
347-
progress_bar = lv.bar(cont)
353+
progress_bar = lv.bar(app_detail_screen)
348354
progress_bar.set_width(lv.pct(100))
349355
progress_bar.set_range(0, 100)
350356
progress_bar.add_flag(lv.obj.FLAG.HIDDEN)
351357
# Always have this button:
352-
buttoncont = lv.obj(cont)
358+
buttoncont = lv.obj(app_detail_screen)
353359
buttoncont.set_style_pad_all(0, 0)
354360
buttoncont.set_flex_flow(lv.FLEX_FLOW.ROW)
355361
buttoncont.set_size(lv.pct(100), lv.SIZE_CONTENT)
@@ -373,17 +379,17 @@ def show_app_detail(app):
373379
update_label.set_text("Update")
374380
update_label.center()
375381
# version label:
376-
version_label = lv.label(cont)
382+
version_label = lv.label(app_detail_screen)
377383
version_label.set_width(lv.pct(100))
378384
version_label.set_text(f"Latest version: {app.version}") # make this bold if this is newer than the currently installed one
379385
version_label.set_style_text_font(lv.font_montserrat_12, 0)
380386
version_label.align_to(install_button, lv.ALIGN.OUT_BOTTOM_MID, 0, lv.pct(5))
381-
long_desc_label = lv.label(cont)
387+
long_desc_label = lv.label(app_detail_screen)
382388
long_desc_label.align_to(version_label, lv.ALIGN.OUT_BOTTOM_MID, 0, lv.pct(5))
383389
long_desc_label.set_text(app.long_description)
384390
long_desc_label.set_style_text_font(lv.font_montserrat_12, 0)
385391
long_desc_label.set_width(lv.pct(100))
386-
lv.screen_load(app_detail_screen)
392+
mpos.ui.load_screen(app_detail_screen)
387393

388394

389395
def toggle_install(download_url, fullname):
@@ -416,28 +422,17 @@ def update_button_click(download_url, fullname):
416422
print("Could not start download_and_unzip thread: ", e)
417423

418424

419-
def back_to_main(event):
420-
global app_detail_screen
421-
if app_detail_screen:
422-
app_detail_screen.delete()
423-
app_detail_screen = None
424-
lv.screen_load(appscreen)
425-
426425

427426
def janitor_cb(timer):
428-
global appscreen, app_detail_screen
429-
if lv.screen_active() != appscreen and lv.screen_active() != app_detail_screen:
427+
global main_screen, app_detail_screen
428+
if lv.screen_active() != main_screen and lv.screen_active() != app_detail_screen:
430429
print("appstore.py backgrounded, cleaning up...")
431430
janitor.delete()
432-
restart_launcher() # refresh the launcher
431+
mpos.apps.restart_launcher() # refresh the launcher
433432
print("appstore.py ending")
434433

435434
janitor = lv.timer_create(janitor_cb, 400, None)
436435

437-
please_wait_label = lv.label(appscreen)
438-
please_wait_label.set_text("Downloading app index...")
439-
please_wait_label.center()
440-
441436
can_check_network = True
442437
try:
443438
import network

internal_filesystem/builtin/apps/com.example.launcher/assets/launcher.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99
# All icons took: 1250ms
1010
# Most of this time is actually spent reading and parsing manifests.
1111

12-
appscreen = lv.screen_active()
13-
1412
import uos
1513
import lvgl as lv
14+
import mpos.apps
15+
import mpos.ui
1616

1717
# Create a container for the grid
18-
cont = lv.obj(appscreen)
19-
cont.set_pos(0, NOTIFICATION_BAR_HEIGHT) # leave some margin for the notification bar
18+
main_screen = lv.obj()
19+
cont = lv.obj(main_screen)
20+
cont.set_pos(0, mpos.ui.NOTIFICATION_BAR_HEIGHT) # leave some margin for the notification bar
2021
cont.set_size(lv.pct(100), lv.pct(100))
2122
cont.set_style_pad_all(10, 0)
2223
cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
24+
mpos.ui.load_screen(main_screen)
2325

2426
# Grid parameters
2527
icon_size = 64 # Adjust based on your display
@@ -56,7 +58,7 @@ def load_icon(icon_path):
5658
base_name = d
5759
if base_name not in seen_base_names: # Avoid duplicates
5860
seen_base_names.add(base_name)
59-
app = parse_manifest(f"{full_path}/META-INF/MANIFEST.JSON")
61+
app = mpos.apps.parse_manifest(f"{full_path}/META-INF/MANIFEST.JSON")
6062
if app.category != "launcher": # Skip launchers
6163
app_list.append((app.name, full_path))
6264
except OSError:
@@ -94,7 +96,7 @@ def load_icon(icon_path):
9496
label.set_width(iconcont_width)
9597
label.align(lv.ALIGN.BOTTOM_MID, 0, 0)
9698
label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
97-
app_cont.add_event_cb(lambda e, path=app_dir_fullpath: start_app(path), lv.EVENT.CLICKED, None)
99+
app_cont.add_event_cb(lambda e, path=app_dir_fullpath: mpos.apps.start_app(path), lv.EVENT.CLICKED, None)
98100

99101
end = time.ticks_ms()
100102
print(f"Displaying all icons took: {end-start}ms")

internal_filesystem/builtin/apps/com.example.osupdate/assets/osupdate.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
appscreen = lv.screen_active()
2-
appscreen.clean()
3-
41
import lvgl as lv
52
import requests
63
import ujson
74
import time
85
import _thread
96

7+
import mpos.info
8+
import mpos.ui
9+
10+
main_screen = None
11+
1012
status_label=None
1113
install_button=None
1214

@@ -34,7 +36,7 @@ def compare_versions(ver1: str, ver2: str) -> bool:
3436

3537
# Custom OTA update with LVGL progress
3638
def update_with_lvgl(url):
37-
global install_button, status_label
39+
global install_button, status_label, main_screen
3840
install_button.add_flag(lv.obj.FLAG.HIDDEN) # or change to cancel button?
3941
status_label.set_text("Update in progress.\nNavigate away to cancel.")
4042
import ota.update
@@ -45,10 +47,10 @@ def update_with_lvgl(url):
4547
print(f"Current partition: {current_partition}")
4648
next_partition = current_partition.get_next_update()
4749
print(f"Next partition: {next_partition}")
48-
label = lv.label(appscreen)
50+
label = lv.label(main_screen)
4951
label.set_text("OS Update: 0.00%")
5052
label.align(lv.ALIGN.CENTER, 0, -30)
51-
progress_bar = lv.bar(appscreen)
53+
progress_bar = lv.bar(main_screen)
5254
progress_bar.set_size(200, 20)
5355
progress_bar.align(lv.ALIGN.BOTTOM_MID, 0, -50)
5456
progress_bar.set_range(0, 100)
@@ -65,7 +67,7 @@ def progress_callback(percent):
6567
chunk_size = 4096
6668
i = 0
6769
print(f"Starting OTA update of size: {total_size}")
68-
while appscreen == lv.screen_active(): # stop if the user navigates away
70+
while main_screen == lv.screen_active(): # stop if the user navigates away
6971
time.sleep_ms(100) # don't hog the CPU
7072
chunk = response.raw.read(chunk_size)
7173
if not chunk:
@@ -96,8 +98,8 @@ def install_button_click(download_url):
9698

9799
def handle_update_info(version, download_url, changelog):
98100
global install_button, status_label
99-
label = f"Installed OS version: {CURRENT_OS_VERSION}\n"
100-
if compare_versions(version, CURRENT_OS_VERSION):
101+
label = f"Installed OS version: {mpos.info.CURRENT_OS_VERSION}\n"
102+
if compare_versions(version, mpos.info.CURRENT_OS_VERSION):
101103
label += "Available new"
102104
install_button.remove_flag(lv.obj.FLAG.HIDDEN)
103105
install_button.add_event_cb(lambda e, u=download_url: install_button_click(u), lv.EVENT.CLICKED, None)
@@ -137,15 +139,17 @@ def show_update_info():
137139
print("Error:", str(e))
138140

139141

140-
install_button = lv.button(appscreen)
141-
install_button.align(lv.ALIGN.TOP_RIGHT, 0, NOTIFICATION_BAR_HEIGHT)
142+
main_screen = lv.obj()
143+
install_button = lv.button(main_screen)
144+
install_button.align(lv.ALIGN.TOP_RIGHT, 0, mpos.ui.NOTIFICATION_BAR_HEIGHT)
142145
install_button.add_flag(lv.obj.FLAG.HIDDEN) # button will be shown if there is an update available
143146
install_button.set_size(lv.SIZE_CONTENT, lv.pct(20))
144147
install_label = lv.label(install_button)
145148
install_label.set_text("Update OS")
146149
install_label.center()
147-
status_label = lv.label(appscreen)
148-
status_label.align(lv.ALIGN.TOP_LEFT,0,NOTIFICATION_BAR_HEIGHT)
150+
status_label = lv.label(main_screen)
151+
status_label.align(lv.ALIGN.TOP_LEFT,0,mpos.ui.NOTIFICATION_BAR_HEIGHT)
152+
mpos.ui.load_screen(main_screen)
149153

150154
network_connected = True
151155
try:

0 commit comments

Comments
 (0)