Skip to content

Commit 0b8a128

Browse files
Settings: support arbitrary number of radio button options
1 parent 1432ec6 commit 0b8a128

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Move wifi icon to the right-hand side
44
- Power off camera after boot and before deepsleep to conserve power
55
- Properly handle misconfigurations in theme color
6+
- Add common theme colors in dropdown list
67

78
0.0.7
89
=====

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self):
1515
("Dark Slate", "2f4f4f"),
1616
("Forest Green", "228b22"),
1717
("Piggy Pink", "ff69b4"),
18-
("Matrix Green", "00ff00"),
18+
("Matrix Green", "03a062"),
1919
("Midnight Blue", "191970"),
2020
("Nostr Purple", "ff00ff"),
2121
("Saddle Brown", "8b4513"),
@@ -136,28 +136,23 @@ def onCreate(self):
136136
self.radio_container.set_height(lv.SIZE_CONTENT)
137137
self.radio_container.set_flex_flow(lv.FLEX_FLOW.COLUMN)
138138
self.radio_container.add_event_cb(self.radio_event_handler, lv.EVENT.CLICKED, None)
139-
# Create radio buttons
139+
# Create radio buttons and check the right one
140140
self.active_radio_index = -1 # none
141-
# currently only supports 2 options, could be more generic:
142-
if current_setting == ui_options[0][1]:
143-
self.active_radio_index = 0
144-
elif current_setting == ui_options[1][1]:
145-
self.active_radio_index = 1
146-
# create radio buttons and check the right one
147-
for i, (text, _) in enumerate(ui_options):
148-
cb = self.create_radio_button(self.radio_container, text, i)
149-
if i == self.active_radio_index:
141+
for i, (option_text, option_value) in enumerate(ui_options):
142+
cb = self.create_radio_button(self.radio_container, option_text, i)
143+
if current_setting == option_value:
144+
self.active_radio_index = i
150145
cb.add_state(lv.STATE.CHECKED)
151146
elif ui and ui == "dropdown" and ui_options:
152147
self.dropdown = lv.dropdown(settings_screen_detail)
153148
self.dropdown.set_width(lv.pct(100))
154149
options_with_newlines = "\n".join(f"{option[0]} ({option[1]})" for option in ui_options)
155150
self.dropdown.set_options(options_with_newlines)
156151
# select the right one:
157-
for i, (option) in enumerate(ui_options):
158-
if option[1] == current_setting:
152+
for i, (option_text, option_value) in enumerate(ui_options):
153+
if current_setting == option_value:
159154
self.dropdown.set_selected(i)
160-
break
155+
break # no need to check the rest because only one can be selected
161156
else:
162157
# Textarea for other settings
163158
self.textarea = lv.textarea(settings_screen_detail)

0 commit comments

Comments
 (0)