Skip to content

Commit b739904

Browse files
committed
Initial project template
1 parent fbf8143 commit b739904

File tree

9 files changed

+457
-0
lines changed

9 files changed

+457
-0
lines changed

tools/config_editor/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.venv/
2+
__pycache__/

tools/config_editor/README.md

Whitespace-only changes.

tools/config_editor/config_editor/__init__.py

Whitespace-only changes.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Arduino-esp32 Libraries Configuration Editor
5+
"""
6+
7+
import sys
8+
9+
from rich.syntax import Syntax
10+
from rich.traceback import Traceback
11+
12+
from textual.app import App, ComposeResult
13+
from textual.containers import Container, VerticalScroll
14+
from textual.reactive import var
15+
from textual.widgets import DirectoryTree, Footer, Header, Static
16+
17+
18+
class ConfigEditor(App):
19+
"""Textual config editor app."""
20+
21+
CSS_PATH = "style.tcss"
22+
BINDINGS = [
23+
("f", "toggle_files", "Toggle Files"),
24+
("q", "quit", "Quit"),
25+
]
26+
27+
show_tree = var(True)
28+
29+
def watch_show_tree(self, show_tree: bool) -> None:
30+
"""Called when show_tree is modified."""
31+
self.set_class(show_tree, "-show-tree")
32+
33+
def compose(self) -> ComposeResult:
34+
"""Compose our UI."""
35+
path = "./" if len(sys.argv) < 2 else sys.argv[1]
36+
yield Header()
37+
with Container():
38+
yield DirectoryTree(path, id="tree-view")
39+
with VerticalScroll(id="code-view"):
40+
yield Static(id="code", expand=True)
41+
yield Footer()
42+
43+
def on_mount(self) -> None:
44+
self.query_one(DirectoryTree).focus()
45+
46+
def on_directory_tree_file_selected(
47+
self, event: DirectoryTree.FileSelected
48+
) -> None:
49+
"""Called when the user click a file in the directory tree."""
50+
event.stop()
51+
code_view = self.query_one("#code", Static)
52+
try:
53+
syntax = Syntax.from_path(
54+
str(event.path),
55+
line_numbers=True,
56+
word_wrap=False,
57+
indent_guides=True,
58+
theme="github-dark",
59+
)
60+
except Exception:
61+
code_view.update(Traceback(theme="github-dark", width=None))
62+
self.sub_title = "ERROR"
63+
else:
64+
code_view.update(syntax)
65+
self.query_one("#code-view").scroll_home(animate=False)
66+
self.sub_title = str(event.path)
67+
68+
def action_toggle_files(self) -> None:
69+
"""Called in response to key binding."""
70+
self.show_tree = not self.show_tree
71+
72+
73+
def main() -> None:
74+
"""Run the app."""
75+
ConfigEditor().run()
76+
77+
if __name__ == "__main__":
78+
main()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import PyInstaller.__main__
2+
from pathlib import Path
3+
4+
main_folder = Path(__file__).parent.absolute()
5+
path_to_main = str(main_folder / "main.py")
6+
7+
def install():
8+
PyInstaller.__main__.run([
9+
path_to_main,
10+
'--onefile',
11+
'--windowed',
12+
# other pyinstaller options...
13+
])
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Screen {
2+
background: $surface-darken-1;
3+
}
4+
5+
#tree-view {
6+
display: none;
7+
scrollbar-gutter: stable;
8+
overflow: auto;
9+
width: auto;
10+
height: 100%;
11+
dock: left;
12+
}
13+
14+
ConfigEditor.-show-tree #tree-view {
15+
display: block;
16+
max-width: 50%;
17+
}
18+
19+
#code-view {
20+
overflow: auto scroll;
21+
min-width: 100%;
22+
}
23+
24+
#code {
25+
width: auto;
26+
}

0 commit comments

Comments
 (0)