Skip to content

Commit 168f1ec

Browse files
Apply theme changes (dark mode, color) immediately after saving
Also: - API: change "display" to mpos.ui.main_display - API: change mpos.ui.th to mpos.ui.task_handler
1 parent 6f86f57 commit 168f1ec

File tree

14 files changed

+78
-65
lines changed

14 files changed

+78
-65
lines changed

CHANGELOG.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
0.3.4 (unreleased)
22
==================
3+
- Apply theme changes (dark mode, color) immediately after saving
34
OSUpdate app: Major rework with improved reliability and user experience
4-
- OSUpdate app: add WiFi monitoring - shows "Waiting for WiFi..." instead of error when no connection
5-
- OSUpdate app: add automatic pause/resume on WiFi loss during downloads using HTTP Range headers
6-
- OSUpdate app: add user-friendly error messages with specific guidance for each error type
7-
- OSUpdate app: add "Check Again" button for easy retry after errors
8-
- OSUpdate app: add state machine for better app state management
9-
- OSUpdate app: add comprehensive test coverage (42 tests: 31 unit tests + 11 graphical tests)
10-
- OSUpdate app: refactor code into testable components (NetworkMonitor, UpdateChecker, UpdateDownloader)
11-
- OSUpdate app: improve download error recovery with progress preservation
12-
- OSUpdate app: improve timeout handling (5-minute wait for WiFi with clear messaging)
5+
- OSUpdate app: add WiFi monitoring - shows "Waiting for WiFi..." instead of error when no connection
6+
- OSUpdate app: add automatic pause/resume on WiFi loss during downloads using HTTP Range headers
7+
- OSUpdate app: add user-friendly error messages with specific guidance for each error type
8+
- OSUpdate app: add "Check Again" button for easy retry after errors
9+
- OSUpdate app: add state machine for better app state management
10+
- OSUpdate app: add comprehensive test coverage (42 tests: 31 unit tests + 11 graphical tests)
11+
- OSUpdate app: refactor code into testable components (NetworkMonitor, UpdateChecker, UpdateDownloader)
12+
- OSUpdate app: improve download error recovery with progress preservation
13+
- OSUpdate app: improve timeout handling (5-minute wait for WiFi with clear messaging)
1314
- Tests: add test infrastructure with mock classes for network, HTTP, and partition operations
1415
- Tests: add graphical test helper utilities for UI verification and screenshot capture
16+
- API: change "display" to mpos.ui.main_display
17+
- API: change mpos.ui.th to mpos.ui.task_handler
1518

1619
0.3.3
1720
=====

CLAUDE.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,11 @@ class MyAnimatedApp(Activity):
534534
def onResume(self, screen):
535535
# Register the frame callback
536536
self.last_time = time.ticks_ms()
537-
mpos.ui.th.add_event_cb(self.update_frame, 1)
537+
mpos.ui.task_handler.add_event_cb(self.update_frame, 1)
538538

539539
def onPause(self, screen):
540540
# Unregister when app goes to background
541-
mpos.ui.th.remove_event_cb(self.update_frame)
541+
mpos.ui.task_handler.remove_event_cb(self.update_frame)
542542

543543
def update_frame(self, a, b):
544544
# Calculate delta time for framerate independence
@@ -670,7 +670,7 @@ def update_frame(self, a, b):
670670
def start_animation(self):
671671
self.spawn_timer = 0
672672
self.spawn_interval = 0.15 # seconds between spawns
673-
mpos.ui.th.add_event_cb(self.update_frame, 1)
673+
mpos.ui.task_handler.add_event_cb(self.update_frame, 1)
674674

675675
def update_frame(self, a, b):
676676
delta_time = time.ticks_diff(time.ticks_ms(), self.last_time) / 1000.0
@@ -803,7 +803,7 @@ def check_collision(self):
803803
def start_animation(self):
804804
self.animation_running = True
805805
self.last_time = time.ticks_ms()
806-
mpos.ui.th.add_event_cb(self.update_frame, 1)
806+
mpos.ui.task_handler.add_event_cb(self.update_frame, 1)
807807

808808
# Optional: auto-stop after duration
809809
lv.timer_create(self.stop_animation, 15000, None).set_repeat_count(1)
@@ -817,7 +817,7 @@ def update_frame(self, a, b):
817817

818818
# Stop when animation completes
819819
if not self.animation_running and len(self.particles) == 0:
820-
mpos.ui.th.remove_event_cb(self.update_frame)
820+
mpos.ui.task_handler.remove_event_cb(self.update_frame)
821821
print("Animation finished")
822822
```
823823

@@ -827,11 +827,11 @@ def onResume(self, screen):
827827
# Only start if needed (e.g., game in progress)
828828
if self.game_started and not self.game_over:
829829
self.last_time = time.ticks_ms()
830-
mpos.ui.th.add_event_cb(self.update_frame, 1)
830+
mpos.ui.task_handler.add_event_cb(self.update_frame, 1)
831831

832832
def onPause(self, screen):
833833
# Always stop when app goes to background
834-
mpos.ui.th.remove_event_cb(self.update_frame)
834+
mpos.ui.task_handler.remove_event_cb(self.update_frame)
835835
```
836836

837837
### Performance Tips

internal_filesystem/apps/com.micropythonos.confetti/assets/confetti.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def onCreate(self):
4545
self.setContentView(self.screen)
4646

4747
def onResume(self, screen):
48-
mpos.ui.th.add_event_cb(self.update_frame, 1)
48+
mpos.ui.task_handler.add_event_cb(self.update_frame, 1)
4949

5050
def onPause(self, screen):
51-
mpos.ui.th.remove_event_cb(self.update_frame)
51+
mpos.ui.task_handler.remove_event_cb(self.update_frame)
5252

5353
def spawn_confetti(self):
5454
"""Safely spawn a new confetti piece with unique img_idx"""

internal_filesystem/boot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
fb1 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)
6060
fb2 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)
6161

62-
display = st7789.ST7789(
62+
mpos.ui.main_display = st7789.ST7789(
6363
data_bus=display_bus,
6464
frame_buffer1=fb1,
6565
frame_buffer2=fb2,
@@ -71,17 +71,17 @@
7171
color_byte_order=st7789.BYTE_ORDER_BGR,
7272
rgb565_byte_swap=True,
7373
)
74-
display.init()
75-
display.set_power(True)
76-
display.set_backlight(100)
74+
mpos.ui.main_display.init()
75+
mpos.ui.main_display.set_power(True)
76+
mpos.ui.main_display.set_backlight(100)
7777

7878
# Touch handling:
7979
i2c_bus = i2c.I2C.Bus(host=I2C_BUS, scl=TP_SCL, sda=TP_SDA, freq=I2C_FREQ, use_locks=False)
8080
touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=TP_ADDR, reg_bits=TP_REGBITS)
8181
indev=cst816s.CST816S(touch_dev,startup_rotation=lv.DISPLAY_ROTATION._180) # button in top left, good
8282

8383
lv.init()
84-
display.set_rotation(lv.DISPLAY_ROTATION._90) # must be done after initializing display and creating the touch drivers, to ensure proper handling
84+
mpos.ui.main_display.set_rotation(lv.DISPLAY_ROTATION._90) # must be done after initializing display and creating the touch drivers, to ensure proper handling
8585

8686
# Battery voltage ADC measuring
8787
import mpos.battery_voltage

internal_filesystem/boot_fri3d-2024.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
STATE_LOW = 0
6464

6565
# see ./lvgl_micropython/api_drivers/py_api_drivers/frozen/display/display_driver_framework.py
66-
display = st7789.ST7789(
66+
mpos.ui.main_display = st7789.ST7789(
6767
data_bus=display_bus,
6868
frame_buffer1=fb1,
6969
frame_buffer2=fb2,
@@ -76,15 +76,15 @@
7676
reset_state=STATE_LOW
7777
)
7878

79-
display.init()
80-
display.set_power(True)
81-
display.set_backlight(100)
79+
mpos.ui.main_display.init()
80+
mpos.ui.main_display.set_power(True)
81+
mpos.ui.main_display.set_backlight(100)
8282

83-
display.set_color_inversion(False)
83+
mpos.ui.main_display.set_color_inversion(False)
8484

8585
lv.init()
86-
display.set_rotation(lv.DISPLAY_ROTATION._270) # must be done after initializing display and creating the touch drivers, to ensure proper handling
87-
display.set_params(0x36, bytearray([0x28]))
86+
mpos.ui.main_display.set_rotation(lv.DISPLAY_ROTATION._270) # must be done after initializing display and creating the touch drivers, to ensure proper handling
87+
mpos.ui.main_display.set_params(0x36, bytearray([0x28]))
8888

8989
# Button and joystick handling code:
9090
from machine import ADC, Pin

internal_filesystem/boot_unix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747

4848
buf1 = bus.allocate_framebuffer(TFT_HOR_RES * TFT_VER_RES * 2, 0)
4949

50-
display = sdl_display.SDLDisplay(data_bus=bus,display_width=TFT_HOR_RES,display_height=TFT_VER_RES,frame_buffer1=buf1,color_space=lv.COLOR_FORMAT.RGB565)
51-
# display.set_dpi(65) # doesn't seem to change the default 130...
52-
display.init()
50+
mpos.ui.main_display = sdl_display.SDLDisplay(data_bus=bus,display_width=TFT_HOR_RES,display_height=TFT_VER_RES,frame_buffer1=buf1,color_space=lv.COLOR_FORMAT.RGB565)
5351
# display.set_dpi(65) # doesn't seem to change the default 130...
52+
mpos.ui.main_display.init()
53+
# main_display.set_dpi(65) # doesn't seem to change the default 130...
5454

5555
import sdl_pointer
5656
mouse = sdl_pointer.SDLPointer()

internal_filesystem/builtin/apps/com.micropythonos.settings/assets/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,6 @@ def save_setting(self, setting):
327327
if changed_callback and old_value != new_value:
328328
print(f"Setting {setting['key']} changed from {old_value} to {new_value}, calling changed_callback...")
329329
changed_callback()
330+
if setting["key"] == "theme_light_dark" or setting["key"] == "theme_primary_color":
331+
mpos.ui.set_theme(self.prefs)
330332
self.finish()

internal_filesystem/lib/mpos/app/activity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def onStart(self, screen):
1919

2020
def onResume(self, screen): # app goes to foreground
2121
self._has_foreground = True
22-
mpos.ui.th.add_event_cb(self.task_handler_callback, 1)
22+
mpos.ui.task_handler.add_event_cb(self.task_handler_callback, 1)
2323

2424
def onPause(self, screen): # app goes to background
2525
self._has_foreground = False

internal_filesystem/lib/mpos/ui/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
screen_stack, remove_and_stop_current_activity, remove_and_stop_all_activities
44
)
55
from .gesture_navigation import handle_back_swipe, handle_top_swipe
6+
from .theme import set_theme
67
from .topmenu import open_bar, close_bar, open_drawer, drawer_open, NOTIFICATION_BAR_HEIGHT
78
from .focus import save_and_clear_current_focusgroup
89
from .display import (
@@ -17,6 +18,7 @@
1718
__all__ = [
1819
"setContentView", "back_screen", "remove_and_stop_current_activity", "remove_and_stop_all_activities"
1920
"handle_back_swipe", "handle_top_swipe",
21+
"set_theme",
2022
"open_bar", "close_bar", "open_drawer", "drawer_open", "NOTIFICATION_BAR_HEIGHT",
2123
"save_and_clear_current_focusgroup",
2224
"get_display_width", "get_display_height",

internal_filesystem/lib/mpos/ui/display.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ def init_rootscreen():
1212
_vertical_resolution = disp.get_vertical_resolution()
1313
print(f"init_rootscreen set _vertical_resolution to {_vertical_resolution}")
1414

15+
# It seems this style
1516
style = lv.style_t()
1617
style.init()
17-
style.set_bg_opa(lv.OPA.TRANSP)
18+
#style.set_bg_opa(lv.OPA.TRANSP)
1819
style.set_border_width(0)
19-
style.set_outline_width(0)
20-
style.set_shadow_width(0)
20+
#style.set_outline_width(0)
21+
#style.set_shadow_width(0)
2122
style.set_pad_all(0)
2223
style.set_radius(0)
2324
screen.add_style(style, 0)
24-
screen.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
25-
screen.set_scroll_dir(lv.DIR.NONE)
25+
#screen.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
26+
#screen.set_scroll_dir(lv.DIR.NONE)
2627

2728
label = lv.label(screen)
2829
label.set_text("Welcome to MicroPythonOS")

0 commit comments

Comments
 (0)