1
+ import math
2
+
1
3
from textual import on
2
4
from textual .app import ComposeResult
3
5
from textual .binding import Binding
4
6
from textual .containers import VerticalScroll , Container , Horizontal
5
7
from textual .screen import Screen
6
8
from textual .events import ScreenResume
7
- from textual .widgets import Header , Button , Switch , Label , Footer
9
+ from textual .widgets import Header , Button , Switch , Label , Footer , Checkbox
8
10
9
11
from widgets import LabelledInput , LabelledSelect
10
12
@@ -17,7 +19,6 @@ class SettingsScreen(Screen):
17
19
Binding ("escape" , "app.pop_screen" , "Discard" )
18
20
]
19
21
20
- target_select : LabelledSelect
21
22
enable_copy_switch : Switch
22
23
arduino_path_input : LabelledInput
23
24
arduino_branch_input : LabelledInput
@@ -26,7 +27,13 @@ class SettingsScreen(Screen):
26
27
idf_debug_select : LabelledSelect
27
28
28
29
def action_save (self ) -> None :
29
- self .app .setting_target = self .target_select .get_select_value ()
30
+ checkboxes = self .query (Checkbox )
31
+ self .app .setting_target = ""
32
+ for checkbox in checkboxes :
33
+ if checkbox .value :
34
+ if self .app .setting_target :
35
+ self .app .setting_target += ","
36
+ self .app .setting_target += checkbox .id .replace ("-checkbox" , "" )
30
37
print ("Target setting updated: " + self .app .setting_target )
31
38
32
39
self .app .setting_enable_copy = self .enable_copy_switch .value
@@ -61,7 +68,12 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
61
68
def on_resume (self ) -> None :
62
69
# Event handler called every time the screen is activated
63
70
print ("Settings screen resumed. Updating settings." )
64
- self .target_select .set_select_value (self .app .setting_target )
71
+ targets = self .app .setting_target .split ("," )
72
+ checkboxes = self .query (Checkbox )
73
+ for checkbox in checkboxes :
74
+ checkbox .value = False
75
+ if checkbox .id .replace ("-checkbox" , "" ) in targets :
76
+ checkbox .value = True
65
77
self .enable_copy_switch .value = self .app .setting_enable_copy
66
78
if self .app .setting_enable_copy :
67
79
self .arduino_path_input .visible = True
@@ -85,18 +97,11 @@ def compose(self) -> ComposeResult:
85
97
# Compose the target selection screen
86
98
yield Header ()
87
99
with VerticalScroll (id = "settings-scroll-container" ):
88
- target_options = [
89
- ("All" , "all" ),
90
- ("ESP32" , "esp32" ),
91
- ("ESP32-S2" , "esp32s2" ),
92
- ("ESP32-S3" , "esp32s3" ),
93
- ("ESP32-C2 (ESP8684)" , "esp32c2" ),
94
- ("ESP32-C3" , "esp32c3" ),
95
- ("ESP32-C6" , "esp32c6" ),
96
- ("ESP32-H2" , "esp32h2" )
97
- ]
98
- self .target_select = LabelledSelect ("Compilation Target" , target_options , allow_blank = False , id = "target-select" )
99
- yield self .target_select
100
+
101
+ yield Label ("Compilation Targets" , id = "settings-target-label" )
102
+ with Container (id = "settings-target-container" ):
103
+ for target in self .app .supported_targets :
104
+ yield Checkbox (target .upper (), id = target + "-checkbox" )
100
105
101
106
with Horizontal (classes = "settings-switch-container" ):
102
107
self .enable_copy_switch = Switch (value = self .app .setting_enable_copy , id = "enable-copy-switch" )
@@ -136,4 +141,9 @@ def compose(self) -> ComposeResult:
136
141
def on_mount (self ) -> None :
137
142
# Event handler called when the screen is mounted for the first time
138
143
self .sub_title = "Settings"
144
+ target_container = self .query_one ("#settings-target-container" )
145
+ # Height needs to be 3 for each row of targets + 1
146
+ height_value = str (int (math .ceil (len (self .app .supported_targets ) / int (target_container .styles .grid_size_columns )) * 3 + 1 ))
147
+ print ("Target container height: " + height_value )
148
+ target_container .styles .height = height_value
139
149
print ("Settings screen mounted" )
0 commit comments