Skip to content

Commit 0d6d21a

Browse files
committed
Add custom widgets
1 parent e9fbf63 commit 0d6d21a

File tree

5 files changed

+127
-62
lines changed

5 files changed

+127
-62
lines changed

tools/config_editor/app.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ class ConfigEditorApp(App):
4343
setting_enable_copy = True
4444

4545
# Options to be set by the command line arguments
46-
setting_target = None
47-
setting_arduino_path = None
48-
setting_arduino_branch = None
49-
setting_idf_branch = None
50-
setting_idf_commit = None
51-
setting_debug_level = None
46+
setting_target = ""
47+
setting_arduino_path = ""
48+
setting_arduino_branch = ""
49+
setting_idf_branch = ""
50+
setting_idf_commit = ""
51+
setting_debug_level = ""
5252

5353
ENABLE_COMMAND_PALETTE = False
5454
CSS_PATH = "style.tcss"
@@ -63,11 +63,11 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
6363
if event.button.id == "compile-button":
6464
print("Compile button pressed")
6565
self.push_screen("compile")
66-
elif event.button.id == "targets-button":
67-
print("Targets button pressed")
66+
elif event.button.id == "settings-button":
67+
print("Settings button pressed")
6868
self.push_screen("settings")
69-
elif event.button.id == "options-button":
70-
print("Options button pressed")
69+
elif event.button.id == "editor-button":
70+
print("Editor button pressed")
7171
self.push_screen("editor")
7272
elif event.button.id == "quit-button":
7373
print("Quit button pressed")
@@ -79,15 +79,16 @@ def compose(self) -> ComposeResult:
7979
with Container(id="main-menu-container"):
8080
yield Label("ESP32 Arduino Static Libraries Configuration Editor", id="main-menu-title")
8181
yield Button("Compile Static Libraries", id="compile-button", classes="main-menu-button")
82-
yield Button("Select Targets", id="targets-button", classes="main-menu-button")
83-
yield Button("Change Configuration Options", id="options-button", classes="main-menu-button")
82+
yield Button("Change sdkconfig Flags", id="editor-button", classes="main-menu-button")
83+
yield Button("Settings", id="settings-button", classes="main-menu-button")
8484
yield Button("Quit", id="quit-button", classes="main-menu-button")
8585

8686
def on_mount(self) -> None:
8787
# Event handler called when the app is mounted for the first time
8888
self.title = "Configurator"
8989
self.sub_title = "Main Menu"
9090
print("App started. Initial Options:")
91+
print("Enable Copy: " + str(self.setting_enable_copy))
9192
print("Target: " + str(self.setting_target))
9293
print("Arduino Path: " + str(self.setting_arduino_path))
9394
print("Arduino Branch: " + str(self.setting_arduino_branch))

tools/config_editor/editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def on_resume(self) -> None:
6464

6565
def compose(self) -> ComposeResult:
6666
# Compose editor screen
67-
path = os.path.join(self.app.root_path, 'configs')
67+
path = os.path.join(self.app.ROOT_PATH, 'configs')
6868
yield Header()
6969
with Container():
7070
yield DirectoryTree(path, id="tree-view")

tools/config_editor/settings.py

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,60 @@
33
from textual.containers import VerticalScroll, Container, Horizontal
44
from textual.screen import Screen
55
from textual.events import ScreenResume
6-
from textual.widgets import Header, RadioButton, Button, RadioSet
6+
from textual.widgets import Header, Button, Switch
7+
8+
from widgets import LabelledInput, LabelledSelect
79

810
class SettingsScreen(Screen):
911
# Settings screen
1012

11-
# Temporary target string
12-
temp_target_str = ""
13-
14-
def update_targets(self) -> None:
15-
# Update the targets in the screen
16-
self.temp_target_str = str(self.app.setting_target)
17-
print("Target updated in screen: " + self.temp_target_str)
18-
1913
def on_button_pressed(self, event: Button.Pressed) -> None:
2014
# Event handler called when a button is pressed
21-
if event.button.id == "save-target-button":
22-
for radiobutton in self.query("RadioButton"):
23-
target_text = radiobutton.id[:-12] # Remove "-radiobutton" from the id
24-
print(target_text + " " + str(radiobutton.value))
25-
if radiobutton.value:
26-
self.temp_target_str = target_text
27-
print("Save button pressed. Selected target: " + self.temp_target_str)
28-
self.app.setting_target = str(self.temp_target_str)
15+
if event.button.id == "save-settings-button":
16+
print("Save button pressed")
17+
18+
# Update the target setting
19+
self.app.setting_target = self.query_one("#target-select", LabelledSelect).value
20+
print("Target setting updated: " + self.app.setting_target)
21+
2922
self.dismiss()
30-
elif event.button.id == "cancel-target-button":
23+
elif event.button.id == "cancel-settings-button":
3124
print("Cancel button pressed")
3225
self.dismiss()
3326

3427
@on(ScreenResume)
3528
def on_resume(self) -> None:
3629
# Event handler called every time the screen is activated
37-
self.update_targets()
38-
print("Targets screen resumed. Loaded target: " + self.temp_target_str)
39-
for radiobutton in self.query("RadioButton"):
40-
target_text = radiobutton.id[:-12] # Remove "-radiobutton" from the id
41-
if target_text == self.temp_target_str:
42-
radiobutton.value = True
43-
else:
44-
radiobutton.value = False
30+
print("Settings screen resumed. Updating settings.")
31+
32+
# Update Target selection
33+
self.query_one("#target-select", LabelledSelect).value = self.app.setting_target
4534

4635
def compose(self) -> ComposeResult:
4736
# Compose the target selection screen
4837
yield Header()
49-
with VerticalScroll(id="target-scroll-container"):
50-
with RadioSet(id="target-radioset"):
51-
yield RadioButton("All", value=True, classes="target-radiobutton", id="all-radiobutton")
52-
yield RadioButton("ESP32", classes="target-radiobutton", id="esp32-radiobutton")
53-
yield RadioButton("ESP32-S2", classes="target-radiobutton", id="esp32s2-radiobutton")
54-
yield RadioButton("ESP32-S3", classes="target-radiobutton", id="esp32s3-radiobutton")
55-
yield RadioButton("ESP32-C2 (ESP8684)", classes="target-radiobutton", id="esp32c2-radiobutton")
56-
yield RadioButton("ESP32-C3", classes="target-radiobutton", id="esp32c3-radiobutton")
57-
yield RadioButton("ESP32-C6", classes="target-radiobutton", id="esp32c6-radiobutton")
58-
yield RadioButton("ESP32-H2", classes="target-radiobutton", id="esp32h2-radiobutton")
59-
with Horizontal(id="target-button-container"):
60-
yield Button("Save", id="save-target-button", classes="target-button")
61-
yield Button("Cancel", id="cancel-target-button", classes="target-button")
38+
with VerticalScroll(id="settings-scroll-container"):
39+
target_options = [
40+
("All", "all"),
41+
("ESP32", "esp32"),
42+
("ESP32-S2", "esp32s2"),
43+
("ESP32-S3", "esp32s3"),
44+
("ESP32-C2 (ESP8684)", "esp32c2"),
45+
("ESP32-C3", "esp32c3"),
46+
("ESP32-C6", "esp32c6"),
47+
("ESP32-H2", "esp32h2")
48+
]
49+
yield LabelledSelect("Compilation Target", target_options, id="target-select", classes="settings-select", allow_blank=False)
50+
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)
54+
55+
with Horizontal(id="settings-button-container"):
56+
yield Button("Save", id="save-settings-button", classes="settings-button")
57+
yield Button("Cancel", id="cancel-settings-button", classes="settings-button")
6258

6359
def on_mount(self) -> None:
6460
# Event handler called when the screen is mounted for the first time
65-
self.sub_title = "Target Selection"
66-
self.query_one("#all-radiobutton", RadioButton).focus()
67-
print("Targets screen mounted")
61+
self.sub_title = "Settings"
62+
print("Settings screen mounted")

tools/config_editor/style.tcss

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Button {
1414
# Main Screen
1515

1616
Button.main-menu-button {
17-
min-width: 100%;
18-
max-width: 0.4fr;
17+
min-width: 100%;
18+
max-width: 0.4fr;
1919
}
2020

2121
#main-menu-container {
@@ -53,31 +53,35 @@ Button.main-menu-button {
5353
margin: 1 2;
5454
}
5555

56-
# Targets Screen
56+
# Settings Screen
5757

58-
#target-radioset {
58+
#settings-radioset {
5959
align: center middle;
6060
width: 0.4fr;
6161
}
6262

63-
#target-scroll-container {
63+
#settings-scroll-container {
6464
align: center middle;
6565
}
6666

67-
#target-button-container {
67+
#settings-button-container {
6868
width: 100%;
6969
max-height: 20%;
7070
min-height: 5;
7171
align: center middle;
7272
}
7373

74-
.target-button {
74+
.settings-button {
7575
margin: 1;
7676
min-width: 100%;
7777
max-width: 0.2fr;
7878
align: center middle;
7979
}
8080

81+
.settings-labelled-input {
82+
margin: 1;
83+
}
84+
8185
# Editor Screen
8286

8387
#tree-view {

tools/config_editor/widgets.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from textual.widget import Widget
2+
3+
from textual.widgets import Input, Label, Select
4+
5+
class LabelledInput(Widget):
6+
DEFAULT_CSS = """
7+
LabelledInput {
8+
width: 1fr;
9+
height: 4;
10+
}
11+
LabelledInput Label {
12+
padding-left: 1;
13+
}
14+
"""
15+
16+
def __init__(self,
17+
label,
18+
*,
19+
placeholder="",
20+
value="",
21+
name=None,
22+
id=None,
23+
classes=None,
24+
disabled=False):
25+
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
26+
self.label = label
27+
self.placeholder = placeholder
28+
self.value = value
29+
30+
def compose(self):
31+
yield Label(f"{self.label}:")
32+
yield Input(placeholder=self.placeholder, value=self.value)
33+
34+
35+
class LabelledSelect(Widget):
36+
DEFAULT_CSS = """
37+
LabelledSelect {
38+
height: 4;
39+
}
40+
LabelledSelect Label {
41+
padding-left: 1;
42+
}
43+
"""
44+
45+
def __init__(self,
46+
label,
47+
options,
48+
*,
49+
prompt="Select",
50+
allow_blank=True,
51+
value=Select.BLANK,
52+
name=None,
53+
id=None,
54+
classes=None,
55+
disabled=False):
56+
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
57+
self.label = label
58+
self.options = options
59+
self.value = value
60+
self.prompt = prompt
61+
self.allow_blank = allow_blank
62+
63+
def compose(self):
64+
yield Label(f"{self.label}:")
65+
yield Select(options=self.options, value=self.value, prompt=self.prompt, allow_blank=self.allow_blank)

0 commit comments

Comments
 (0)