From 1e7fc357f9b4433605cea062bd38b4efa6557950 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Mon, 12 Jan 2026 11:09:07 +0100 Subject: [PATCH] Simplify --- .../assets/settings.py | 18 ++++++++++++------ .../lib/mpos/ui/settings_activity.py | 15 ++------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/internal_filesystem/builtin/apps/com.micropythonos.settings/assets/settings.py b/internal_filesystem/builtin/apps/com.micropythonos.settings/assets/settings.py index eb57d1bd..8772d67a 100644 --- a/internal_filesystem/builtin/apps/com.micropythonos.settings/assets/settings.py +++ b/internal_filesystem/builtin/apps/com.micropythonos.settings/assets/settings.py @@ -12,9 +12,8 @@ from check_imu_calibration import CheckIMUCalibrationActivity # Used to list and edit all settings: class Settings(SettingsActivity): - def __init__(self): - super().__init__() - self.prefs = mpos.config.SharedPreferences("com.micropythonos.settings") + """Override getIntent to provide prefs and settings via Intent extras""" + def getIntent(self): theme_colors = [ ("Aqua Blue", "00ffff"), ("Bitcoin Orange", "f0a010"), @@ -40,13 +39,19 @@ class Settings(SettingsActivity): ("Teal", "008080"), ("Turquoise", "40e0d0") ] - self.settings = [ + # Create a mock intent-like object with extras + class MockIntent: + def __init__(self, extras): + self.extras = extras + + return MockIntent({ + "prefs": mpos.config.SharedPreferences("com.micropythonos.settings"), + "settings": [ # Basic settings, alphabetically: {"title": "Light/Dark Theme", "key": "theme_light_dark", "ui": "radiobuttons", "ui_options": [("Light", "light"), ("Dark", "dark")], "changed_callback": self.theme_changed}, {"title": "Theme Color", "key": "theme_primary_color", "placeholder": "HTML hex color, like: EC048C", "ui": "dropdown", "ui_options": theme_colors, "changed_callback": self.theme_changed}, {"title": "Timezone", "key": "timezone", "ui": "dropdown", "ui_options": [(tz, tz) for tz in mpos.time.get_timezones()], "changed_callback": lambda *args: mpos.time.refresh_timezone_preference()}, # Advanced settings, alphabetically: - #{"title": "Audio Output Device", "key": "audio_device", "ui": "radiobuttons", "ui_options": [("Auto-detect", "auto"), ("I2S (Digital Audio)", "i2s"), ("Buzzer (PWM Tones)", "buzzer"), ("Both I2S and Buzzer", "both"), ("Disabled", "null")], "changed_callback": self.audio_device_changed}, {"title": "Auto Start App", "key": "auto_start_app", "ui": "radiobuttons", "ui_options": [(app.name, app.fullname) for app in PackageManager.get_app_list()]}, {"title": "Check IMU Calibration", "key": "check_imu_calibration", "ui": "activity", "activity_class": CheckIMUCalibrationActivity}, {"title": "Calibrate IMU", "key": "calibrate_imu", "ui": "activity", "activity_class": CalibrateIMUActivity}, @@ -56,7 +61,8 @@ class Settings(SettingsActivity): # This is currently only in the drawer but would make sense to have it here for completeness: #{"title": "Display Brightness", "key": "display_brightness", "placeholder": "A value from 0 to 100."}, # Maybe also add font size (but ideally then all fonts should scale up/down) - ] + ] + }) # Change handlers: def reset_into_bootloader(self, new_value): diff --git a/internal_filesystem/lib/mpos/ui/settings_activity.py b/internal_filesystem/lib/mpos/ui/settings_activity.py index a8e0aef1..76a5c537 100644 --- a/internal_filesystem/lib/mpos/ui/settings_activity.py +++ b/internal_filesystem/lib/mpos/ui/settings_activity.py @@ -12,14 +12,8 @@ class SettingsActivity(Activity): settings = None def onCreate(self): - # Try to get from Intent first (for apps launched with Intent) - intent = self.getIntent() - if intent and intent.extras: - self.prefs = intent.extras.get("prefs") - self.settings = intent.extras.get("settings") - - # If not set from Intent, subclasses should have set them in __init__() - # (for apps that define their own settings) + self.prefs = self.getIntent().extras.get("prefs") + self.settings = self.getIntent().extras.get("settings") print("creating SettingsActivity ui...") screen = lv.obj() @@ -29,11 +23,6 @@ class SettingsActivity(Activity): self.setContentView(screen) def onResume(self, screen): - # If prefs/settings not set yet, they should be set by subclass - if not self.prefs or not self.settings: - print("WARNING: SettingsActivity.onResume() called but prefs or settings not set") - return - # Create settings entries screen.clean() # Get the group for focusable objects