3
3
from textual .containers import VerticalScroll , Container , Horizontal
4
4
from textual .screen import Screen
5
5
from textual .events import ScreenResume
6
- from textual .widgets import Header , Button , Switch
6
+ from textual .widgets import Header , Button , Switch , Label
7
7
8
8
from widgets import LabelledInput , LabelledSelect
9
9
10
10
class SettingsScreen (Screen ):
11
11
# Settings screen
12
12
13
+ target_select : LabelledSelect
14
+ enable_copy_switch : Switch
15
+ arduino_path_input : LabelledInput
16
+ arduino_branch_input : LabelledInput
17
+ idf_branch_input : LabelledInput
18
+ idf_commit_input : LabelledInput
19
+ idf_debug_select : LabelledSelect
20
+
13
21
def on_button_pressed (self , event : Button .Pressed ) -> None :
14
22
# Event handler called when a button is pressed
15
23
if event .button .id == "save-settings-button" :
16
24
print ("Save button pressed" )
17
25
18
- # Update the target setting
19
- self .app .setting_target = self .query_one ("#target-select" , LabelledSelect ).get_select_value ()
26
+ self .app .setting_target = self .target_select .get_select_value ()
20
27
print ("Target setting updated: " + self .app .setting_target )
21
28
29
+ self .app .setting_enable_copy = self .enable_copy_switch .value
30
+ print ("Enable copy setting updated: " + str (self .app .setting_enable_copy ))
31
+
32
+ if self .enable_copy_switch .value :
33
+ self .app .setting_arduino_path = self .arduino_path_input .get_input_value ()
34
+ print ("Arduino path setting updated: " + self .app .setting_arduino_path )
35
+
36
+ self .app .setting_arduino_branch = self .arduino_branch_input .get_input_value ()
37
+ print ("Arduino branch setting updated: " + self .app .setting_arduino_branch )
38
+
39
+ self .app .setting_idf_branch = self .idf_branch_input .get_input_value ()
40
+ print ("IDF branch setting updated: " + self .app .setting_idf_branch )
41
+
42
+ self .app .setting_idf_commit = self .idf_commit_input .get_input_value ()
43
+ print ("IDF commit setting updated: " + self .app .setting_idf_commit )
44
+
45
+ self .app .setting_debug_level = self .idf_debug_select .get_select_value ()
46
+ print ("Debug level setting updated: " + self .app .setting_debug_level )
47
+
22
48
self .dismiss ()
23
49
elif event .button .id == "cancel-settings-button" :
24
50
print ("Cancel button pressed" )
@@ -28,9 +54,13 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
28
54
def on_resume (self ) -> None :
29
55
# Event handler called every time the screen is activated
30
56
print ("Settings screen resumed. Updating settings." )
31
-
32
- # Update Target selection
33
- self .query_one ("#target-select" , LabelledSelect ).set_select_value (self .app .setting_target )
57
+ self .target_select .set_select_value (self .app .setting_target )
58
+ self .enable_copy_switch .value = self .app .setting_enable_copy
59
+ self .arduino_path_input .set_input_value (self .app .setting_arduino_path )
60
+ self .arduino_branch_input .set_input_value (self .app .setting_arduino_branch )
61
+ self .idf_branch_input .set_input_value (self .app .setting_idf_branch )
62
+ self .idf_commit_input .set_input_value (self .app .setting_idf_commit )
63
+ self .idf_debug_select .set_select_value (self .app .setting_debug_level )
34
64
35
65
def compose (self ) -> ComposeResult :
36
66
# Compose the target selection screen
@@ -46,11 +76,38 @@ def compose(self) -> ComposeResult:
46
76
("ESP32-C6" , "esp32c6" ),
47
77
("ESP32-H2" , "esp32h2" )
48
78
]
49
- yield LabelledSelect ("Compilation Target" , target_options , id = "target-select" , classes = "settings-select" , allow_blank = False )
79
+ self .target_select = LabelledSelect ("Compilation Target" , target_options , allow_blank = False , id = "target-select" )
80
+ yield self .target_select
81
+
50
82
with Horizontal (id = "settings-enable-copy-container" ):
51
- yield Switch (id = "enable-copy-switch" , classes = "settings-switch" , value = self .app .setting_enable_copy )
52
- yield LabelledInput ("Arduino-esp32 Path" , placeholder = "Path to your arduino-esp32 installation" , value = self .app .setting_arduino_path )
53
- yield LabelledInput ("Arduino-esp32 Branch" , placeholder = "Leave empty to use default" , value = self .app .setting_arduino_branch )
83
+ yield Label ("Copy to arduino-esp32 after compilation" , id = "enable-copy-label" )
84
+
85
+ self .enable_copy_switch = Switch (value = self .app .setting_enable_copy , id = "enable-copy-switch" )
86
+ yield self .enable_copy_switch
87
+
88
+ self .arduino_path_input = LabelledInput ("Arduino-esp32 Path" , placeholder = "Path to your arduino-esp32 installation" , value = self .app .setting_arduino_path , id = "arduino-path-input" )
89
+ yield self .arduino_path_input
90
+
91
+ self .arduino_branch_input = LabelledInput ("Arduino-esp32 Branch" , placeholder = "Leave empty to use default" , value = self .app .setting_arduino_branch , id = "arduino-branch-input" )
92
+ yield self .arduino_branch_input
93
+
94
+ self .idf_branch_input = LabelledInput ("ESP-IDF Branch" , placeholder = "Leave empty to use default" , value = self .app .setting_idf_branch , id = "idf-branch-input" )
95
+ yield self .idf_branch_input
96
+
97
+ self .idf_commit_input = LabelledInput ("ESP-IDF Commit" , placeholder = "Leave empty to use default" , value = self .app .setting_idf_commit , id = "idf-commit-input" )
98
+ yield self .idf_commit_input
99
+
100
+ debug_options = [
101
+ ("Default" , "default" ),
102
+ ("None" , "none" ),
103
+ ("Error" , "error" ),
104
+ ("Warning" , "warning" ),
105
+ ("Info" , "info" ),
106
+ ("Debug" , "debug" ),
107
+ ("Verbose" , "verbose" )
108
+ ]
109
+ self .idf_debug_select = LabelledSelect ("ESP-IDF Debug Level" , debug_options , allow_blank = False , id = "idf-debug-select" )
110
+ yield self .idf_debug_select
54
111
55
112
with Horizontal (id = "settings-button-container" ):
56
113
yield Button ("Save" , id = "save-settings-button" , classes = "settings-button" )
0 commit comments