22
33import mpos .config
44import mpos .ui
5+ import mpos .time
56
67# Used to list and edit all settings:
78class SettingsActivity (Activity ):
@@ -37,10 +38,10 @@ def __init__(self):
3738 {"title" : "Light/Dark Theme" , "key" : "theme_light_dark" , "value_label" : None , "cont" : None , "ui" : "radiobuttons" , "ui_options" : [("Light" , "light" ), ("Dark" , "dark" )]},
3839 {"title" : "Theme Color" , "key" : "theme_primary_color" , "value_label" : None , "cont" : None , "placeholder" : "HTML hex color, like: EC048C" , "ui" : "dropdown" , "ui_options" : theme_colors },
3940 {"title" : "Restart to Bootloader" , "key" : "boot_mode" , "value_label" : None , "cont" : None , "ui" : "radiobuttons" , "ui_options" : [("Normal" , "normal" ), ("Bootloader" , "bootloader" )]}, # special that doesn't get saved
41+ {"title" : "Timezone" , "key" : "timezone" , "value_label" : None , "cont" : None , "ui" : "dropdown" , "ui_options" : self .get_timezone_tuples (), "changed_callback" : lambda : mpos .time .refresh_timezone_preference ()},
4042 # This is currently only in the drawer but would make sense to have it here for completeness:
4143 #{"title": "Display Brightness", "key": "display_brightness", "value_label": None, "cont": None, "placeholder": "A value from 0 to 100."},
4244 # Maybe also add font size (but ideally then all fonts should scale up/down)
43- #{"title": "Timezone", "key": "timezone", "value_label": None, "cont": None, "placeholder": "Example: Europe/Prague"},
4445 ]
4546
4647 def onCreate (self ):
@@ -59,6 +60,7 @@ def onResume(self, screen):
5960 # Create settings entries
6061 screen .clean ()
6162 for setting in self .settings :
63+ #print(f"setting {setting.get('title')} has changed_callback {setting.get('changed_callback')}")
6264 # Container for each setting
6365 setting_cont = lv .obj (screen )
6466 setting_cont .set_width (lv .pct (100 ))
@@ -91,6 +93,10 @@ def startSettingActivity(self, setting):
9193 intent .putExtra ("setting" , setting )
9294 self .startActivity (intent )
9395
96+ @staticmethod
97+ def get_timezone_tuples ():
98+ return [(tz , tz ) for tz in mpos .time .get_timezones ()]
99+
94100# Used to edit one setting:
95101class SettingActivity (Activity ):
96102
@@ -109,6 +115,7 @@ def __init__(self):
109115
110116 def onCreate (self ):
111117 setting = self .getIntent ().extras .get ("setting" )
118+ #print(f"onCreate changed_callback: {setting.get('changed_callback')}")
112119 settings_screen_detail = lv .obj ()
113120 settings_screen_detail .set_style_pad_all (mpos .ui .pct_of_display_width (2 ), 0 )
114121 settings_screen_detail .set_flex_flow (lv .FLEX_FLOW .COLUMN )
@@ -146,7 +153,12 @@ def onCreate(self):
146153 elif ui and ui == "dropdown" and ui_options :
147154 self .dropdown = lv .dropdown (settings_screen_detail )
148155 self .dropdown .set_width (lv .pct (100 ))
149- options_with_newlines = "\n " .join (f"{ option [0 ]} ({ option [1 ]} )" for option in ui_options )
156+ options_with_newlines = ""
157+ for option in ui_options :
158+ if option [0 ] != option [1 ]:
159+ options_with_newlines += (f"{ option [0 ]} ({ option [1 ]} )\n " )
160+ else : # don't show identical options
161+ options_with_newlines += (f"{ option [0 ]} \n " )
150162 self .dropdown .set_options (options_with_newlines )
151163 # select the right one:
152164 for i , (option_text , option_value ) in enumerate (ui_options ):
@@ -282,8 +294,14 @@ def save_setting(self, setting):
282294 new_value = self .textarea .get_text ()
283295 else :
284296 new_value = ""
297+ old_value = self .prefs .get_string (setting ["key" ])
285298 editor = self .prefs .edit ()
286299 editor .put_string (setting ["key" ], new_value )
287300 editor .commit ()
288301 setting ["value_label" ].set_text (new_value if new_value else "(not set)" )
302+ changed_callback = setting .get ("changed_callback" )
303+ #print(f"changed_callback: {changed_callback}")
304+ if changed_callback and old_value != new_value :
305+ print (f"Setting { setting ['key' ]} changed from { old_value } to { new_value } , calling changed_callback..." )
306+ changed_callback ()
289307 self .finish ()
0 commit comments