Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9fd1430

Browse files
Settings: make more generic
1 parentf9ee7a9 commit9fd1430

File tree

1 file changed

+19
-18
lines changed
  • internal_filesystem/builtin/apps/com.micropythonos.settings/assets

1 file changed

+19
-18
lines changed

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
importmpos.config
44
importmpos.ui
55

6-
76
# Used to list and edit all settings:
87
classSettingsActivity(Activity):
98
def__init__(self):
109
super().__init__()
1110
self.prefs=None
1211
self.settings= [
13-
{"title":"Light/Dark Theme","key":"theme_light_dark","value_label":None,"cont":None},
12+
{"title":"Light/Dark Theme","key":"theme_light_dark","value_label":None,"cont":None,"ui":"radiobuttons","ui_options": [("Light","light"), ("Dark","dark")]},
1413
{"title":"Theme Color","key":"theme_primary_color","value_label":None,"cont":None,"placeholder":"HTML hex color, like: EC048C"},
15-
{"title":"Restart to Bootloader","key":"boot_mode","value_label":None,"cont":None},# special that doesn't get saved
14+
{"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
1615
# This is currently only in the drawer but would make sense to have it here for completeness:
1716
#{"title": "Display Brightness", "key": "display_brightness", "value_label": None, "cont": None, "placeholder": "A value from 0 to 100."},
1817
# Maybe also add font size (but ideally then all fonts should scale up/down)
@@ -99,7 +98,9 @@ def onCreate(self):
9998
setting_label.align(lv.ALIGN.TOP_LEFT,0,0)
10099
setting_label.set_style_text_font(lv.font_montserrat_26,0)
101100

102-
ifsetting["key"]=="theme_light_dark"orsetting["key"]=="boot_mode":
101+
ui=setting.get("ui")
102+
ui_options=setting.get("ui_options")
103+
ifuiandui=="radiobuttons"andui_options:
103104
# Create container for radio buttons
104105
self.radio_container=lv.obj(settings_screen_detail)
105106
self.radio_container.set_width(lv.pct(100))
@@ -108,18 +109,15 @@ def onCreate(self):
108109
self.radio_container.add_event_cb(self.radio_event_handler,lv.EVENT.CLICKED,None)
109110

110111
# Create radio buttons
111-
ifsetting["key"]=="boot_mode":
112-
options= [("Normal","normal"), ("Bootloader","bootloader")]
113-
else:
114-
options= [("Light","light"), ("Dark","dark")]
115112
current_setting=self.prefs.get_string(setting["key"])
116113
self.active_radio_index=-1# none
117-
ifcurrent_setting==options[0][1]:
114+
# currently only supports 2 options, could be more generic:
115+
ifcurrent_setting==ui_options[0][1]:
118116
self.active_radio_index=0
119-
elifcurrent_setting==options[1][1]:
117+
elifcurrent_setting==ui_options[1][1]:
120118
self.active_radio_index=1
121-
122-
fori, (text,_)inenumerate(options):
119+
# create radio buttons and check the right one
120+
fori, (text,_)inenumerate(ui_options):
123121
cb=self.create_radio_button(self.radio_container,text,i)
124122
ifi==self.active_radio_index:
125123
cb.add_state(lv.STATE.CHECKED)
@@ -231,20 +229,23 @@ def cambutton_cb_unused(self, event):
231229
self.startActivityForResult(Intent(activity_class=CameraApp).putExtra("scanqr_mode",True),self.gotqr_result_callback)
232230

233231
defsave_setting(self,setting):
234-
ifsetting["key"]=="boot_mode"andself.radio_container:
232+
ifsetting["key"]=="boot_mode"andself.radio_container:# special case that isn't saved
235233
ifself.active_radio_index==1:
236234
frommpos.bootloaderimportResetIntoBootloader
237235
intent=Intent(activity_class=ResetIntoBootloader)
238236
ActivityNavigator.startActivity(intent)
239237
return
240238

241-
if (setting["key"]=="theme_light_dark"orsetting["key"]=="boot_mode" )andself.radio_container:
242-
ifsetting["key"]=="boot_mode":
243-
options= [("Normal","normal"), ("Bootloader","bootloader")]
239+
ui=setting.get("ui")
240+
ifuiandui=="radiobuttons"andself.radio_container:
241+
ui_options=setting.get("ui_options")
242+
ifui_options:
243+
options=ui_options
244244
else:
245-
options= [("Light","light"), ("Dark","dark")]
245+
print("No ui_options are available, not saving...")
246+
return
246247
selected_idx=self.active_radio_index
247-
ifselected_idx==0:
248+
ifselected_idx==0:# only supports 2 options, could be made more generic
248249
new_value=options[0][1]
249250
elifselected_idx==1:
250251
new_value=options[1][1]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp