@@ -8,9 +8,34 @@ class SettingsActivity(Activity):
88 def __init__ (self ):
99 super ().__init__ ()
1010 self .prefs = None
11+ theme_colors = [
12+ ("Aqua Blue" , "00ffff" ),
13+ ("Bitcoin Orange" , "f0a010" ),
14+ ("Coral Red" , "ff7f50" ),
15+ ("Dark Slate" , "2f4f4f" ),
16+ ("Forest Green" , "228b22" ),
17+ ("Piggy Pink" , "ff69b4" ),
18+ ("Matrix Green" , "00ff00" ),
19+ ("Midnight Blue" , "191970" ),
20+ ("Nostr Purple" , "ff00ff" ),
21+ ("Saddle Brown" , "8b4513" ),
22+ ("Sky Blue" , "87ceeb" ),
23+ ("Solarized Yellow" , "b58900" ),
24+ ("Vivid Violet" , "9f00ff" ),
25+ ("Amethyst" , "9966cc" ),
26+ ("Burnt Orange" , "cc5500" ),
27+ ("Charcoal Gray" , "36454f" ),
28+ ("Crimson" , "dc143c" ),
29+ ("Emerald" , "50c878" ),
30+ ("Goldenrod" , "daa520" ),
31+ ("Indigo" , "4b0082" ),
32+ ("Lime" , "00ff00" ),
33+ ("Teal" , "008080" ),
34+ ("Turquoise" , "40e0d0" )
35+ ]
1136 self .settings = [
1237 {"title" : "Light/Dark Theme" , "key" : "theme_light_dark" , "value_label" : None , "cont" : None , "ui" : "radiobuttons" , "ui_options" : [("Light" , "light" ), ("Dark" , "dark" )]},
13- {"title" : "Theme Color" , "key" : "theme_primary_color" , "value_label" : None , "cont" : None , "placeholder" : "HTML hex color, like: EC048C" },
38+ {"title" : "Theme Color" , "key" : "theme_primary_color" , "value_label" : None , "cont" : None , "placeholder" : "HTML hex color, like: EC048C" , "ui" : "dropdown" , "ui_options" : theme_colors },
1439 {"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
1540 # This is currently only in the drawer but would make sense to have it here for completeness:
1641 #{"title": "Display Brightness", "key": "display_brightness", "value_label": None, "cont": None, "placeholder": "A value from 0 to 100."},
@@ -69,10 +94,13 @@ def startSettingActivity(self, setting):
6994# Used to edit one setting:
7095class SettingActivity (Activity ):
7196
97+ active_radio_index = 0 # Track active radio button index
98+
99+ # Widgets:
72100 keyboard = None
73101 textarea = None
102+ dropdown = None
74103 radio_container = None
75- active_radio_index = 0 # Track active radio button index
76104
77105 def __init__ (self ):
78106 super ().__init__ ()
@@ -100,16 +128,15 @@ def onCreate(self):
100128
101129 ui = setting .get ("ui" )
102130 ui_options = setting .get ("ui_options" )
131+ current_setting = self .prefs .get_string (setting ["key" ])
103132 if ui and ui == "radiobuttons" and ui_options :
104133 # Create container for radio buttons
105134 self .radio_container = lv .obj (settings_screen_detail )
106135 self .radio_container .set_width (lv .pct (100 ))
107136 self .radio_container .set_height (lv .SIZE_CONTENT )
108137 self .radio_container .set_flex_flow (lv .FLEX_FLOW .COLUMN )
109138 self .radio_container .add_event_cb (self .radio_event_handler , lv .EVENT .CLICKED , None )
110-
111139 # Create radio buttons
112- current_setting = self .prefs .get_string (setting ["key" ])
113140 self .active_radio_index = - 1 # none
114141 # currently only supports 2 options, could be more generic:
115142 if current_setting == ui_options [0 ][1 ]:
@@ -121,15 +148,24 @@ def onCreate(self):
121148 cb = self .create_radio_button (self .radio_container , text , i )
122149 if i == self .active_radio_index :
123150 cb .add_state (lv .STATE .CHECKED )
151+ elif ui and ui == "dropdown" and ui_options :
152+ self .dropdown = lv .dropdown (settings_screen_detail )
153+ self .dropdown .set_width (lv .pct (100 ))
154+ options_with_newlines = "\n " .join (f"{ option [0 ]} ({ option [1 ]} )" for option in ui_options )
155+ self .dropdown .set_options (options_with_newlines )
156+ # select the right one:
157+ for i , (option ) in enumerate (ui_options ):
158+ if option [1 ] == current_setting :
159+ self .dropdown .set_selected (i )
160+ break
124161 else :
125162 # Textarea for other settings
126163 self .textarea = lv .textarea (settings_screen_detail )
127164 self .textarea .set_width (lv .pct (100 ))
128165 self .textarea .set_height (lv .SIZE_CONTENT )
129166 self .textarea .align_to (top_cont , lv .ALIGN .OUT_BOTTOM_MID , 0 , 0 )
130- current = self .prefs .get_string (setting ["key" ])
131- if current :
132- self .textarea .set_text (current )
167+ if current_setting :
168+ self .textarea .set_text (current_setting )
133169 placeholder = setting .get ("placeholder" )
134170 if placeholder :
135171 self .textarea .set_placeholder_text (placeholder )
@@ -237,20 +273,19 @@ def save_setting(self, setting):
237273 return
238274
239275 ui = setting .get ("ui" )
240- if ui and ui == "radiobuttons" and self .radio_container :
241- ui_options = setting .get ("ui_options" )
242- if ui_options :
243- options = ui_options
244- else :
245- print ("No ui_options are available, not saving..." )
246- return
276+ ui_options = setting .get ("ui_options" )
277+ if ui and ui == "radiobuttons" and ui_options :
247278 selected_idx = self .active_radio_index
248279 if selected_idx == 0 : # only supports 2 options, could be made more generic
249- new_value = options [0 ][1 ]
280+ new_value = ui_options [0 ][1 ]
250281 elif selected_idx == 1 :
251- new_value = options [1 ][1 ]
282+ new_value = ui_options [1 ][1 ]
252283 else :
253284 return # nothing to save
285+ elif ui and ui == "dropdown" and ui_options :
286+ selected_index = self .dropdown .get_selected ()
287+ print (f"selected item: { selected_index } " )
288+ new_value = ui_options [selected_index ][1 ]
254289 elif self .textarea :
255290 new_value = self .textarea .get_text ()
256291 else :
0 commit comments