|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +Arduino Static Libraries Configuration Editor |
| 5 | +""" |
| 6 | + |
| 7 | +from rich.syntax import Syntax |
| 8 | +from rich.traceback import Traceback |
| 9 | +from rich.console import RenderableType |
| 10 | + |
| 11 | +from textual.app import App, ComposeResult |
| 12 | +from textual.containers import Container |
| 13 | +from textual.widgets import Button, Footer, Header, RichLog, Label |
| 14 | + |
| 15 | +from targets import TargetsScreen |
| 16 | +from editor import EditorScreen |
| 17 | +from compile import CompileScreen |
| 18 | + |
| 19 | +target_dict = {} |
| 20 | + |
| 21 | +class ConfigEditorApp(App): |
| 22 | + """Textual config editor app.""" |
| 23 | + |
| 24 | + ENABLE_COMMAND_PALETTE = False |
| 25 | + CSS_PATH = "style.tcss" |
| 26 | + SCREENS = { |
| 27 | + "targets": TargetsScreen(), |
| 28 | + "compile": CompileScreen(), |
| 29 | + "editor": EditorScreen(), |
| 30 | + } |
| 31 | + BINDINGS = [ |
| 32 | + ("c", "push_screen('compile')", "Compile"), |
| 33 | + ("t", "push_screen('targets', update_targets)", "Change Targets"), |
| 34 | + ("o", "push_screen('editor')", "Change Options"), |
| 35 | + ("l", "app.toggle_class('RichLog', '-hidden')", "Log"), |
| 36 | + ("q", "quit", "Quit"), |
| 37 | + ] |
| 38 | + |
| 39 | + def log_print(self, renderable: RenderableType) -> None: |
| 40 | + self.query_one(RichLog).write(renderable) |
| 41 | + |
| 42 | + def update_targets(self, targets: dict) -> None: |
| 43 | + """Update the targets dictionary.""" |
| 44 | + self.log_print("Updating targets") |
| 45 | + self.log_print(targets) |
| 46 | + if targets: |
| 47 | + target_dict = targets |
| 48 | + |
| 49 | + def on_button_pressed(self, event: Button.Pressed) -> None: |
| 50 | + """Event handler called when a button is pressed.""" |
| 51 | + if event.button.id == "compile-button": |
| 52 | + self.log_print("Compile button pressed") |
| 53 | + self.push_screen('compile') |
| 54 | + elif event.button.id == "targets-button": |
| 55 | + self.log_print("Targets button pressed") |
| 56 | + self.push_screen('targets', self.update_targets) |
| 57 | + elif event.button.id == "options-button": |
| 58 | + self.log_print("Options button pressed") |
| 59 | + self.push_screen('editor') |
| 60 | + elif event.button.id == "quit-button": |
| 61 | + self.log_print("Quit button pressed") |
| 62 | + quit() |
| 63 | + |
| 64 | + def compose(self) -> ComposeResult: |
| 65 | + """Compose our UI.""" |
| 66 | + yield Header() |
| 67 | + with Container(id="main-menu-container"): |
| 68 | + yield Label("ESP32 Arduino Static Libraries Configuration Editor", id="main-menu-title") |
| 69 | + yield Button("Compile", id="compile-button", classes="main-menu-button") |
| 70 | + yield Button("Select Targets", id="targets-button", classes="main-menu-button") |
| 71 | + yield Button("Change Configuration Options", id="options-button", classes="main-menu-button") |
| 72 | + yield Button("Quit", id="quit-button", classes="main-menu-button") |
| 73 | + yield RichLog(classes="-hidden", wrap=False, highlight=True, markup=True) |
| 74 | + yield Footer() |
| 75 | + |
| 76 | + def on_mount(self) -> None: |
| 77 | + self.title = "Configurator" |
| 78 | + self.sub_title = "Main Menu" |
| 79 | + self.log_print("[b green]Welcome to the ESP32 Arduino Static Libraries Configuration Editor!") |
| 80 | + |
| 81 | +def main() -> None: |
| 82 | + """Run the app.""" |
| 83 | + ConfigEditorApp().run() |
| 84 | + |
| 85 | +if __name__ == "__main__": |
| 86 | + main() |
0 commit comments