Skip to content

Commit 8caa77e

Browse files
committed
Improve style
1 parent 9d32f26 commit 8caa77e

File tree

2 files changed

+117
-21
lines changed

2 files changed

+117
-21
lines changed

tools/config_editor/compile.py

+50-18
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,55 @@ class CompileScreen(Screen):
1717
# Child process running the libraries compilation
1818
child_process = None
1919

20-
def print_output(self, renderable: RenderableType) -> None:
20+
log_widget: RichLog
21+
button_widget: Button
22+
23+
def print_output(self, renderable: RenderableType, style=None) -> None:
2124
# Print output to the RichLog widget
22-
self.query_one(RichLog).write(renderable)
25+
if style is None:
26+
self.log_widget.write(renderable)
27+
else:
28+
# Check the available styles at https://rich.readthedocs.io/en/stable/style.html
29+
self.log_widget.write("[" + str(style) + "]" + renderable)
30+
31+
def print_error(self, error: str) -> None:
32+
# Print error to the RichLog widget
33+
self.log_widget.write("[b bright_red]" + error)
34+
self.button_widget.add_class("-error")
35+
#print("Error: " + error) # For debugging
36+
37+
def print_success(self, message: str) -> None:
38+
# Print success message to the RichLog widget
39+
self.log_widget.write("[b bright_green]" + message)
40+
self.button_widget.add_class("-success")
41+
#print("Success: " + message) # For debugging
42+
43+
def print_info(self, message: str) -> None:
44+
# Print info message to the RichLog widget
45+
self.log_widget.write("[b bright_cyan]" + message)
46+
#print("Info: " + message) # For debugging
2347

2448
@work(name="compliation_worker", group="compilation", exclusive=True, thread=True)
2549
def compile_libs(self) -> None:
2650
# Compile the libraries
51+
print("Starting compilation process")
2752

2853
label = self.query_one("#compile-title", Static)
2954
self.child_process = None
3055
target = self.app.setting_target
3156

32-
print("Compiling for " + target.upper())
3357
label.update("Compiling for " + target.upper())
34-
self.print_output("======== Compiling for " + target.upper() + " ========")
58+
self.print_info("======== Compiling for " + target.upper() + " ========")
3559

3660
command = ["./build.sh", "-t", target, "-D", self.app.setting_debug_level]
61+
3762
#command.append("--help") # For testing output without compiling
3863

3964
if self.app.setting_enable_copy:
4065
if os.path.isdir(self.app.setting_arduino_path):
4166
command.extend(["-c", self.app.setting_arduino_path])
4267
else:
43-
print("Invalid path to Arduino core: " + self.app.setting_arduino_path)
44-
self.print_output("Invalid path to Arduino core: " + self.app.setting_arduino_path)
68+
self.print_error("Invalid path to Arduino core: " + self.app.setting_arduino_path)
4569
label.update("Invalid path to Arduino core")
4670
return
4771

@@ -54,8 +78,7 @@ def compile_libs(self) -> None:
5478
if self.app.setting_idf_commit:
5579
command.extend(["-i", self.app.setting_idf_commit])
5680

57-
self.print_output("Running: " + " ".join(command) + "\n")
58-
print("Running: " + " ".join(command))
81+
self.print_info("Running: " + " ".join(command) + "\n")
5982
self.child_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
6083
try:
6184
for output in self.child_process.stdout:
@@ -69,19 +92,25 @@ def compile_libs(self) -> None:
6992
print("Process might have terminated")
7093

7194
if not self.child_process:
72-
print("Compilation failed for " + target.upper() + "Child process failed to start")
95+
self.print_error("Compilation failed for " + target.upper() + "Child process failed to start")
7396
label.update("Compilation failed for " + target.upper() + "Child process failed to start")
7497
return
7598
else:
7699
self.child_process.wait()
77100

78101
if self.child_process.returncode != 0:
79-
print("Compilation failed for " + target.upper() + ". Return code: " + str(self.child_process.returncode))
80-
self.print_output("Compilation failed for " + target.upper() + ". Return code: " + str(self.child_process.returncode))
81-
self.print_output("Error: " + self.child_process.stderr.read())
102+
self.print_error("Compilation failed for " + target.upper() + ". Return code: " + str(self.child_process.returncode))
103+
self.print_error("Errors:")
104+
try:
105+
for error in self.child_process.stderr:
106+
if error:
107+
self.print_error(error.strip())
108+
self.child_process.stderr.close()
109+
except Exception as e:
110+
print("Error reading child process errors: " + str(e))
82111
label.update("Compilation failed for " + target.upper())
83112
else:
84-
print("Compilation successful for " + target.upper())
113+
self.print_success("Compilation successful for " + target.upper())
85114
label.update("Compilation successful for " + target.upper())
86115

87116
def on_button_pressed(self, event: Button.Pressed) -> None:
@@ -103,16 +132,19 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
103132
def on_resume(self) -> None:
104133
# Event handler called every time the screen is activated
105134
print("Compile screen resumed. Clearing logs and starting compilation process")
106-
log = self.query_one(RichLog)
107-
log.clear()
108-
log.focus()
135+
self.button_widget.remove_class("-error")
136+
self.button_widget.remove_class("-success")
137+
self.log_widget.clear()
138+
self.log_widget.focus()
109139
self.compile_libs()
110140

111141
def compose(self) -> ComposeResult:
112142
# Compose the compilation screen
113143
yield Header()
114144
with Container(id="compile-log-container"):
115-
yield RichLog(markup=True, id="compile-log")
145+
self.log_widget = RichLog(markup=True, id="compile-log")
146+
yield self.log_widget
116147
with Container(id="compile-status-container"):
117148
yield Static("Compiling for ...", id="compile-title")
118-
yield Button("Back", id="compile-back-button")
149+
self.button_widget = Button("Back", id="compile-back-button")
150+
yield self.button_widget

tools/config_editor/style.tcss

+67-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,79 @@ Screen {
55
}
66

77
Button {
8-
margin-bottom: 1;
9-
background: rgb(73,158,165);
10-
border: rgb(73,158,165);
8+
width: auto;
9+
min-width: 16;
10+
height: auto;
11+
color: $text;
12+
border: none;
13+
background: #038c8c;
14+
border-top: tall #026868;
15+
border-bottom: tall #6ab8b8;
16+
text-align: center;
17+
content-align: center middle;
1118
text-style: bold;
19+
20+
&:focus {
21+
text-style: bold reverse;
22+
}
23+
&:hover {
24+
border-top: tall #014444;
25+
border-bottom: tall #3d8080;
26+
background: #025b5b;
27+
color: $text;
28+
}
29+
&.-active {
30+
background: #025b5b;
31+
border-bottom: tall #3d8080;
32+
border-top: tall #014444;
33+
tint: $background 30%;
34+
}
35+
36+
&.-success {
37+
background: $success;
38+
color: $text;
39+
border-top: tall $success-lighten-2;
40+
border-bottom: tall $success-darken-3;
41+
42+
&:hover {
43+
background: $success-darken-2;
44+
color: $text;
45+
border-top: tall $success;
46+
}
47+
48+
&.-active {
49+
background: $success;
50+
border-bottom: tall $success-lighten-2;
51+
border-top: tall $success-darken-2;
52+
}
53+
}
54+
55+
&.-error {
56+
background: $error;
57+
color: $text;
58+
border-top: tall $error-lighten-2;
59+
border-bottom: tall $error-darken-3;
60+
61+
&:hover {
62+
background: $error-darken-1;
63+
color: $text;
64+
border-top: tall $error;
65+
}
66+
67+
&.-active {
68+
background: $error;
69+
border-bottom: tall $error-lighten-2;
70+
border-top: tall $error-darken-2;
71+
}
72+
73+
}
74+
1275
}
1376

1477
# Main Screen
1578

1679
Button.main-menu-button {
80+
margin-bottom: 1;
1781
min-width: 100%;
1882
max-width: 0.4fr;
1983
}

0 commit comments

Comments
 (0)