33from textual .containers import VerticalScroll , Container , Horizontal
44from textual .screen import Screen
55from textual .events import ScreenResume
6- from textual .widgets import Header , Button , Switch
6+ from textual .widgets import Header , Button , Switch , Label
77
88from widgets import LabelledInput , LabelledSelect
99
1010class SettingsScreen (Screen ):
1111 # Settings screen
1212
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+
1321 def on_button_pressed (self , event : Button .Pressed ) -> None :
1422 # Event handler called when a button is pressed
1523 if event .button .id == "save-settings-button" :
1624 print ("Save button pressed" )
1725
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 ()
2027 print ("Target setting updated: " + self .app .setting_target )
2128
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+
2248 self .dismiss ()
2349 elif event .button .id == "cancel-settings-button" :
2450 print ("Cancel button pressed" )
@@ -28,9 +54,13 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
2854 def on_resume (self ) -> None :
2955 # Event handler called every time the screen is activated
3056 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 )
3464
3565 def compose (self ) -> ComposeResult :
3666 # Compose the target selection screen
@@ -46,11 +76,38 @@ def compose(self) -> ComposeResult:
4676 ("ESP32-C6" , "esp32c6" ),
4777 ("ESP32-H2" , "esp32h2" )
4878 ]
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+
5082 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
54111
55112 with Horizontal (id = "settings-button-container" ):
56113 yield Button ("Save" , id = "save-settings-button" , classes = "settings-button" )
0 commit comments