Add theme to settings

This commit is contained in:
Thomas Farstrike
2025-06-17 10:45:29 +02:00
parent 3f4ab9c842
commit 5356ac1452
2 changed files with 22 additions and 15 deletions
@@ -18,11 +18,12 @@ class SettingsActivity(Activity):
super().__init__()
self.prefs = None
self.settings = [
{"title": "Light/Dark Theme", "key": "light_dark_theme", "value_label": None, "cont": None},
{"title": "Theme Color", "key": "theme_color", "value_label": None, "cont": None, "placeholder": "HTML hex color, like: EC048C"},
{"title": "Reboot into Bootloader", "key": "boot_mode", "value_label": None, "cont": None},
{"title": "Display Brightness", "key": "display_brightness", "value_label": None, "cont": None, "placeholder": "A value from 0 to 100."},
{"title": "Timezone", "key": "timezone", "value_label": None, "cont": None, "placeholder": "Example: Europe/Prague"},
{"title": "Light/Dark Theme", "key": "theme_light_dark", "value_label": None, "cont": None},
{"title": "Theme Color", "key": "theme_primary_color", "value_label": None, "cont": None, "placeholder": "HTML hex color, like: EC048C"},
#{"title": "Display Brightness", "key": "display_brightness", "value_label": None, "cont": None, "placeholder": "A value from 0 to 100."},
# Maybe also add font size (but ideally then all fonts should scale up/down)
#{"title": "Reboot into Bootloader", "key": "boot_mode", "value_label": None, "cont": None}, # special that doesn't get saved
#{"title": "Timezone", "key": "timezone", "value_label": None, "cont": None, "placeholder": "Example: Europe/Prague"},
]
def onCreate(self):
@@ -105,7 +106,7 @@ class SettingActivity(Activity):
setting_label.align(lv.ALIGN.TOP_LEFT,0,0)
setting_label.set_style_text_font(lv.font_montserrat_26, 0)
if setting["key"] == "light_dark_theme" or setting["key"] == "boot_mode":
if setting["key"] == "theme_light_dark" or setting["key"] == "boot_mode":
# Create container for radio buttons
self.radio_container = lv.obj(settings_screen_detail)
self.radio_container.set_width(lv.pct(100))
@@ -237,7 +238,7 @@ class SettingActivity(Activity):
self.startActivityForResult(Intent(activity_class=CameraApp).putExtra("scanqr_mode", True), self.gotqr_result_callback)
def save_setting(self, setting):
if ( setting["key"] =="light_dark_theme" or setting["key"] == "boot_mode" ) and self.radio_container:
if ( setting["key"] =="theme_light_dark" or setting["key"] == "boot_mode" ) and self.radio_container:
if setting["key"] == "boot_mode":
options = [("Normal", "normal"), ("Bootloader", "bootloader")]
else:
+14 -8
View File
@@ -7,16 +7,22 @@ fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'M')
import mpos.apps
import mpos.config
import mpos.ui
RED = lv.palette_main(lv.PALETTE.RED)
DARKPINK = lv.color_hex(0xEC048C)
MEDIUMPINK = lv.color_hex(0xF480C5)
LIGHTPINK = lv.color_hex(0xF9E9F2)
DARKYELLOW = lv.color_hex(0xFBDC05)
LIGHTYELLOW = lv.color_hex(0xFBE499)
theme = lv.theme_default_init(display._disp_drv, DARKPINK, DARKYELLOW, False, lv.font_montserrat_12)
#theme = lv.theme_default_init(display._disp_drv, DARKPINK, DARKYELLOW, True, lv.font_montserrat_12)
prefs = mpos.config.SharedPreferences("com.micropythonos.settings")
# Load and set theme:
theme_light_dark = prefs.get_string("theme_light_dark", "light") # default to a light theme
theme_dark_bool = ( theme_light_dark == "dark" )
primary_color = lv.theme_get_color_primary(None)
color_string = prefs.get_string("theme_primary_color")
if color_string:
color_string = color_string.replace("0x", "").replace("#", "").strip().lower()
color_int = int(color_string, 16)
print(f"Setting primary color: {color_int}")
primary_color = lv.color_hex(color_int)
theme = lv.theme_default_init(display._disp_drv, primary_color, lv.color_hex(0xFBDC05), theme_dark_bool, lv.font_montserrat_12)
#display.set_theme(theme)