diff --git a/README.md b/README.md index 8133c0d7a..501c62887 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,32 @@ git clone https://github.com/espressif/esp32-arduino-lib-builder cd esp32-arduino-lib-builder ./build.sh ``` + +### Using the User Interface + +You can more easily build the libraries using the user interface found in the `tools/config_editor/` folder. +It is a Python script that allows you to select and edit the options for the libraries you want to build. +The script has mouse support and can also be pre-configured using the same command line arguments as the `build.sh` script. +For more information and troubleshooting, please refer to the [UI README](tools/config_editor/README.md). + +To use it, follow these steps: + +1. Make sure you have the required dependencies installed: + - Python 3.9 or later + - The [Textual](https://github.com/textualize/textual/) library + - All the dependencies listed in the previous section + +2. Execute the script `tools/config_editor/app.py` from any folder. It will automatically detect the path to the root of the repository. + +3. Configure the compilation and ESP-IDF options as desired. + +4. Click on the "Compile Static Libraries" button to start the compilation process. + +5. The script will show the compilation output in a new screen. Note that the compilation process can take many hours, depending on the number of libraries selected and the options chosen. + +6. If the compilation is successful and the option to copy the libraries to the Arduino Core folder is enabled, it will already be available for use in the Arduino IDE. Otherwise, you can find the compiled libraries in the `esp32-arduino-libs` folder alongside this repository. + - Note that the copy operation doesn't currently support the core downloaded from the Arduino IDE Boards Manager, only the manual installation from the [`arduino-esp32`](https://github.com/espressif/arduino-esp32) repository. + ### Documentation For more information about how to use the Library builder, please refer to this [Documentation page](https://docs.espressif.com/projects/arduino-esp32/en/latest/lib_builder.html?highlight=lib%20builder) diff --git a/tools/config_editor/.gitignore b/tools/config_editor/.gitignore new file mode 100644 index 000000000..a230a78ae --- /dev/null +++ b/tools/config_editor/.gitignore @@ -0,0 +1,2 @@ +.venv/ +__pycache__/ diff --git a/tools/config_editor/README.md b/tools/config_editor/README.md new file mode 100644 index 000000000..c0ba0bc40 --- /dev/null +++ b/tools/config_editor/README.md @@ -0,0 +1,38 @@ +# Arduino Static Libraries Configuration Editor + +This is a simple application to configure the static libraries for the ESP32 Arduino core. +It allows the user to select the targets to compile, change the configuration options and compile the libraries. +It has mouse support and can be pre-configured using command line arguments. + +## Requirements + - Python 3.9 or later + - The "textual" library (install it using `pip install textual`) + - The requirements from esp32-arduino-lib-builder + +## Troubleshooting + +In some cases, the UI might not look as expected. This can happen due to the terminal emulator not supporting the required features. + +### WSL + +If you are using WSL, it is recommended to use the Windows Terminal to visualize the application. Otherwise, the application layout and colors might not be displayed correctly. +The Windows Terminal can be installed from the Microsoft Store. + +### MacOS + +If you are using MacOS and the application looks weird, check [this guide from Textual](https://textual.textualize.io/FAQ/#why-doesnt-textual-look-good-on-macos) to fix it. + +## Usage + +These command line arguments can be used to pre-configure the application: + +Command line arguments: + -t, --target Comma-separated list of targets to be compiled. + Choose from: all, esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2. Default: all except esp32c2 + --copy, --no-copy Enable/disable copying the compiled libraries to arduino-esp32. Enabled by default + -c, --arduino-path Path to arduino-esp32 directory. Default: OS dependent + -A, --arduino-branch Branch of the arduino-esp32 repository to be used. Default: set by the build script + -I, --idf-branch Branch of the ESP-IDF repository to be used. Default: set by the build script + -i, --idf-commit Commit of the ESP-IDF repository to be used. Default: set by the build script + -D, --debug-level Debug level to be set to ESP-IDF. + Choose from: default, none, error, warning, info, debug, verbose. Default: default diff --git a/tools/config_editor/app.py b/tools/config_editor/app.py new file mode 100755 index 000000000..8a7b2ce24 --- /dev/null +++ b/tools/config_editor/app.py @@ -0,0 +1,278 @@ +#!/usr/bin/env python + +""" +Arduino Static Libraries Configuration Editor + +This is a simple application to configure the static libraries for the ESP32 Arduino core. +It allows the user to select the targets to compile, change the configuration options and compile the libraries. + +Requires Python 3.9 or later. + +The application is built using the "textual" library, which is a Python library for building text-based user interfaces. + +Note that this application still needs the requirements from esp32-arduino-lib-builder to be installed. + +Command line arguments: + -t, --target Comma-separated list of targets to be compiled. + Choose from: all, esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2. Default: all except esp32c2 + --copy, --no-copy Enable/disable copying the compiled libraries to arduino-esp32. Enabled by default + -c, --arduino-path Path to arduino-esp32 directory. Default: OS dependent + -A, --arduino-branch Branch of the arduino-esp32 repository to be used. Default: set by the build script + -I, --idf-branch Branch of the ESP-IDF repository to be used. Default: set by the build script + -i, --idf-commit Commit of the ESP-IDF repository to be used. Default: set by the build script + -D, --debug-level Debug level to be set to ESP-IDF. + Choose from: default, none, error, warning, info, debug, verbose. Default: default + +""" + +import argparse +import json +import os +import platform +import sys + +from pathlib import Path + +try: + from textual.app import App, ComposeResult + from textual.binding import Binding + from textual.containers import VerticalScroll + from textual.screen import Screen + from textual.widgets import Button, Header, Label, Footer +except ImportError: + print("Please install the \"textual\" package before running this script.") + exit(1) + +from settings import SettingsScreen +from editor import EditorScreen +from compile import CompileScreen + +class MainScreen(Screen): + # Main screen class + + # Set the key bindings + BINDINGS = [ + Binding("c", "app.push_screen('compile')", "Compile"), + Binding("e", "app.push_screen('editor')", "Editor"), + Binding("s", "app.push_screen('settings')", "Settings"), + Binding("q", "app.quit", "Quit"), + ] + + def on_button_pressed(self, event: Button.Pressed) -> None: + # Event handler called when a button is pressed + if event.button.id == "compile-button": + print("Compile button pressed") + self.app.push_screen("compile") + elif event.button.id == "settings-button": + print("Settings button pressed") + self.app.push_screen("settings") + elif event.button.id == "editor-button": + print("Editor button pressed") + self.app.push_screen("editor") + elif event.button.id == "quit-button": + print("Quit button pressed") + self.app.exit() + + def compose(self) -> ComposeResult: + # Compose main menu + yield Header() + with VerticalScroll(id="main-menu-container"): + yield Label("ESP32 Arduino Static Libraries Configuration Editor", id="main-menu-title") + yield Button("Compile Static Libraries", id="compile-button", classes="main-menu-button") + yield Button("Sdkconfig Editor", id="editor-button", classes="main-menu-button") + yield Button("Settings", id="settings-button", classes="main-menu-button") + yield Button("Quit", id="quit-button", classes="main-menu-button") + yield Footer() + + def on_mount(self) -> None: + # Event handler called when the app is mounted for the first time + self.title = "Configurator" + self.sub_title = "Main Menu" + print("Main screen mounted.") + +class ConfigEditorApp(App): + # Main application class + + # Set the root and script paths + SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__)) + ROOT_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", "..")) + + # Set the application options + supported_targets = [] + setting_enable_copy = True + + # Options to be set by the command line arguments + setting_target = "" + setting_arduino_path = "" + setting_arduino_branch = "" + setting_idf_branch = "" + setting_idf_commit = "" + setting_debug_level = "" + + ENABLE_COMMAND_PALETTE = False + CSS_PATH = "style.tcss" + SCREENS = { + "main": MainScreen(), + "settings": SettingsScreen(), + "compile": CompileScreen(), + "editor": EditorScreen(), + } + + def on_mount(self) -> None: + print("Application mounted. Initial options:") + print("Python version: " + sys.version) + print("Root path: " + self.ROOT_PATH) + print("Script path: " + self.SCRIPT_PATH) + print("Supported Targets: " + ", ".join(self.supported_targets)) + print("Default targets: " + self.setting_target) + print("Enable Copy: " + str(self.setting_enable_copy)) + print("Arduino Path: " + str(self.setting_arduino_path)) + print("Arduino Branch: " + str(self.setting_arduino_branch)) + print("IDF Branch: " + str(self.setting_idf_branch)) + print("IDF Commit: " + str(self.setting_idf_commit)) + print("IDF Debug Level: " + str(self.setting_debug_level)) + self.push_screen("main") + +def arduino_default_path(): + sys_name = platform.system() + home = str(Path.home()) + if sys_name == "Linux": + return os.path.join(home, "Arduino", "hardware", "espressif", "esp32") + else: # Windows and MacOS + return os.path.join(home, "Documents", "Arduino", "hardware", "espressif", "esp32") + +def check_arduino_path(path): + return os.path.isdir(path) + +def main() -> None: + # Set the PYTHONUNBUFFERED environment variable to "1" to disable the output buffering + os.environ['PYTHONUNBUFFERED'] = "1" + + # Check Python version + if sys.version_info < (3, 9): + print("This script requires Python 3.9 or later") + exit(1) + + app = ConfigEditorApp() + + # List of tuples for the target choices containing the target name and if it is enabled by default + target_choices = [] + + # Parse build JSON file + build_json_path = os.path.join(app.ROOT_PATH, "configs", "builds.json") + if os.path.isfile(build_json_path): + with open(build_json_path, "r") as build_json_file: + build_json = json.load(build_json_file) + for target in build_json["targets"]: + try: + default = False if target["skip"] else True + except: + default = True + target_choices.append((target["target"], default)) + else: + print("Error: configs/builds.json file not found.") + exit(1) + + target_choices.sort(key=lambda x: x[0]) + + parser = argparse.ArgumentParser(description="Configure and compile the ESP32 Arduino static libraries") + + parser.add_argument("-t", "--target", + metavar="", + type=str, + default="default", + required=False, + help="Comma-separated list of targets to be compiled. Choose from: " + ", ".join([x[0] for x in target_choices]) + + ". Default: All except " + ", ".join([x[0] for x in target_choices if not x[1]])) + + parser.add_argument("--copy", + type=bool, + action=argparse.BooleanOptionalAction, + default=True, + required=False, + help="Enable/disable copying the compiled libraries to arduino-esp32. Enabled by default") + + parser.add_argument("-c", "--arduino-path", + metavar="", + type=str, + default=arduino_default_path(), + required=False, + help="Path to arduino-esp32 directory. Default: " + arduino_default_path()) + + parser.add_argument("-A", "--arduino-branch", + metavar="", + type=str, + default="", + required=False, + help="Branch of the arduino-esp32 repository to be used") + + parser.add_argument("-I", "--idf-branch", + metavar="", + type=str, + default="", + required=False, + help="Branch of the ESP-IDF repository to be used") + + parser.add_argument("-i", "--idf-commit", + metavar="", + type=str, + default="", + required=False, + help="Commit of the ESP-IDF repository to be used") + + debug_level_choices = ("default", "none", "error", "warning", "info", "debug", "verbose") + parser.add_argument("-D", "--debug-level", + metavar="", + type=str, + default="default", + choices=debug_level_choices, + required=False, + help="Debug level to be set to ESP-IDF. Choose from: " + ", ".join(debug_level_choices)) + + args = parser.parse_args() + + # Set the options in the app + if args.target.strip() == "default": + args.target = ",".join([x[0] for x in target_choices if x[1]]) + elif args.target.strip() == "all": + args.target = ",".join([x[0] for x in target_choices]) + + app.supported_targets = [x[0] for x in target_choices] + + for target in args.target.split(","): + if target not in app.supported_targets: + print("Invalid target: " + target) + exit(1) + + app.setting_target = args.target + + if args.copy: + if check_arduino_path(args.arduino_path): + app.setting_enable_copy = True + elif args.arduino_path == arduino_default_path(): + print("Warning: Default Arduino path not found. Disabling copy to Arduino.") + app.setting_enable_copy = False + else: + print("Invalid path to Arduino core: " + os.path.abspath(args.arduino_path)) + exit(1) + else: + app.setting_enable_copy = False + + app.setting_arduino_path = os.path.abspath(args.arduino_path) + app.setting_arduino_branch = args.arduino_branch + app.setting_idf_branch = args.idf_branch + app.setting_idf_commit = args.idf_commit + app.setting_debug_level = args.debug_level + + # Change to the root directory of the app to the root of the project + os.chdir(app.ROOT_PATH) + + # Main function to run the app + app.run() + + # Propagate the exit code from the app + exit(app.return_code or 0) + +if __name__ == "__main__": + # If this script is run directly, start the app + main() diff --git a/tools/config_editor/compile.py b/tools/config_editor/compile.py new file mode 100644 index 000000000..3cfb056b7 --- /dev/null +++ b/tools/config_editor/compile.py @@ -0,0 +1,163 @@ +import sys +import subprocess +import os + +from rich.console import RenderableType + +from textual import on, work +from textual.app import ComposeResult +from textual.binding import Binding +from textual.events import ScreenResume +from textual.containers import Container +from textual.screen import Screen +from textual.widgets import Header, Static, RichLog, Button, Footer + +class CompileScreen(Screen): + # Compile screen + + # Set the key bindings + BINDINGS = [ + Binding("escape", "back", "Back") + ] + + # Child process running the libraries compilation + child_process = None + + log_widget: RichLog + button_widget: Button + + def action_back(self) -> None: + self.workers.cancel_all() + if self.child_process: + # Terminate the child process if it is running + print("Terminating child process") + self.child_process.terminate() + try: + self.child_process.stdout.close() + self.child_process.stderr.close() + except: + pass + self.child_process.wait() + self.dismiss() + + def print_output(self, renderable: RenderableType, style=None) -> None: + # Print output to the RichLog widget + if style is None: + self.log_widget.write(renderable) + else: + # Check the available styles at https://rich.readthedocs.io/en/stable/style.html + self.log_widget.write("[" + str(style) + "]" + renderable) + + def print_error(self, error: str) -> None: + # Print error to the RichLog widget + self.log_widget.write("[b bright_red]" + error) + self.button_widget.add_class("-error") + #print("Error: " + error) # For debugging + + def print_success(self, message: str) -> None: + # Print success message to the RichLog widget + self.log_widget.write("[b bright_green]" + message) + self.button_widget.add_class("-success") + #print("Success: " + message) # For debugging + + def print_info(self, message: str) -> None: + # Print info message to the RichLog widget + self.log_widget.write("[b bright_cyan]" + message) + #print("Info: " + message) # For debugging + + @work(name="compliation_worker", group="compilation", exclusive=True, thread=True) + def compile_libs(self) -> None: + # Compile the libraries + print("Starting compilation process") + + label = self.query_one("#compile-title", Static) + self.child_process = None + if self.app.setting_target == ",".join(self.app.supported_targets): + target = "all targets" + else: + target = self.app.setting_target.replace(",", ", ").upper() + + label.update("Compiling for " + target) + self.print_info("======== Compiling for " + target + " ========") + + command = ["./build.sh", "-t", self.app.setting_target, "-D", self.app.setting_debug_level] + + #command.append("--help") # For testing output without compiling + + if self.app.setting_enable_copy: + if os.path.isdir(self.app.setting_arduino_path): + command.extend(["-c", self.app.setting_arduino_path]) + else: + self.print_error("Invalid path to Arduino core: " + self.app.setting_arduino_path) + label.update("Invalid path to Arduino core") + return + + if self.app.setting_arduino_branch: + command.extend(["-A", self.app.setting_arduino_branch]) + + if self.app.setting_idf_branch: + command.extend(["-I", self.app.setting_idf_branch]) + + if self.app.setting_idf_commit: + command.extend(["-i", self.app.setting_idf_commit]) + + self.print_info("Running: " + " ".join(command) + "\n") + self.child_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + try: + for output in self.child_process.stdout: + if output == '' and self.child_process.poll() is not None: + break + if output: + self.print_output(output.strip()) # Update RichLog widget with subprocess output + self.child_process.stdout.close() + except Exception as e: + print("Error reading child process output: " + str(e)) + print("Process might have terminated") + + if not self.child_process: + self.print_error("Compilation failed for " + target + "Child process failed to start") + label.update("Compilation failed for " + target + "Child process failed to start") + return + else: + self.child_process.wait() + + if self.child_process.returncode != 0: + self.print_error("Compilation failed for " + target + ". Return code: " + str(self.child_process.returncode)) + self.print_error("Errors:") + try: + for error in self.child_process.stderr: + if error: + self.print_error(error.strip()) + self.child_process.stderr.close() + except Exception as e: + print("Error reading child process errors: " + str(e)) + label.update("Compilation failed for " + target) + else: + self.print_success("Compilation successful for " + target) + label.update("Compilation successful for " + target) + + def on_button_pressed(self, event: Button.Pressed) -> None: + # Event handler called when a button is pressed + self.action_back() + + @on(ScreenResume) + def on_resume(self) -> None: + # Event handler called every time the screen is activated + print("Compile screen resumed. Clearing logs and starting compilation process") + self.button_widget.remove_class("-error") + self.button_widget.remove_class("-success") + self.log_widget.clear() + self.log_widget.focus() + self.compile_libs() + + def compose(self) -> ComposeResult: + # Compose the compilation screen + yield Header() + with Container(id="compile-log-container"): + self.log_widget = RichLog(markup=True, id="compile-log") + yield self.log_widget + with Container(id="compile-status-container"): + yield Static("Compiling for ...", id="compile-title") + self.button_widget = Button("Back", id="compile-back-button") + yield self.button_widget + yield Footer() diff --git a/tools/config_editor/editor.py b/tools/config_editor/editor.py new file mode 100644 index 000000000..87217f49d --- /dev/null +++ b/tools/config_editor/editor.py @@ -0,0 +1,86 @@ +import os + +from textual import on +from textual.app import ComposeResult +from textual.binding import Binding +from textual.containers import Container, VerticalScroll, Horizontal +from textual.screen import Screen +from textual.events import ScreenResume +from textual.widgets import DirectoryTree, Header, TextArea, Button, Footer + +class EditorScreen(Screen): + # Configuration file editor screen + + # Set the key bindings + BINDINGS = [ + Binding("ctrl+s", "save", "Save", priority=True), + Binding("escape", "app.pop_screen", "Discard") + ] + + # Current file being edited + current_file = "" + + def action_save(self) -> None: + code_view = self.query_one("#code", TextArea) + current_text = code_view.text + try: + file = open(self.curent_file, "w") + file.write(current_text) + file.close() + except Exception: + print("Error saving file: " + self.curent_file) + self.sub_title = "ERROR" + else: + print("File saved: " + self.curent_file) + self.sub_title = self.curent_file + self.dismiss() + + def on_button_pressed(self, event: Button.Pressed) -> None: + # Event handler called when a button is pressed + if event.button.id == "save-editor-button" and self.curent_file != "": + print("Save button pressed. Trying to save file: " + self.curent_file) + self.action_save() + elif event.button.id == "cancel-editor-button": + print("Cancel button pressed") + self.dismiss() + + def on_directory_tree_file_selected(self, event: DirectoryTree.FileSelected) -> None: + # Called when the user click a file in the directory tree + event.stop() + code_view = self.query_one("#code", TextArea) + code_view.clear() + self.curent_file = str(event.path) + try: + print("Opening file: " + self.curent_file) + file = open(self.curent_file, "r") + file_content = file.read() + file.close() + except Exception: + print("Error opening file: " + self.curent_file) + self.sub_title = "ERROR" + else: + print("File opened: " + self.curent_file) + code_view.insert(file_content) + self.sub_title = self.curent_file + + @on(ScreenResume) + def on_resume(self) -> None: + # Event handler called every time the screen is activated + print("Editor screen resumed. Clearing code view") + self.sub_title = "Select a file" + self.query_one(DirectoryTree).focus() + self.query_one(TextArea).clear() + self.curent_file = "" + + def compose(self) -> ComposeResult: + # Compose editor screen + path = os.path.join(self.app.ROOT_PATH, 'configs') + yield Header() + with Container(): + yield DirectoryTree(path, id="tree-view") + with VerticalScroll(id="code-view"): + yield TextArea.code_editor("", id="code") + with Horizontal(id="editor-buttons-container"): + yield Button("Save", id="save-editor-button", classes="editor-button") + yield Button("Cancel", id="cancel-editor-button", classes="editor-button") + yield Footer() diff --git a/tools/config_editor/settings.py b/tools/config_editor/settings.py new file mode 100644 index 000000000..c92358374 --- /dev/null +++ b/tools/config_editor/settings.py @@ -0,0 +1,149 @@ +import math + +from textual import on +from textual.app import ComposeResult +from textual.binding import Binding +from textual.containers import VerticalScroll, Container, Horizontal +from textual.screen import Screen +from textual.events import ScreenResume +from textual.widgets import Header, Button, Switch, Label, Footer, Checkbox + +from widgets import LabelledInput, LabelledSelect + +class SettingsScreen(Screen): + # Settings screen + + # Set the key bindings + BINDINGS = [ + Binding("s", "save", "Save"), + Binding("escape", "app.pop_screen", "Discard") + ] + + enable_copy_switch: Switch + arduino_path_input: LabelledInput + arduino_branch_input: LabelledInput + idf_branch_input: LabelledInput + idf_commit_input: LabelledInput + idf_debug_select: LabelledSelect + + def action_save(self) -> None: + checkboxes = self.query(Checkbox) + self.app.setting_target = "" + for checkbox in checkboxes: + if checkbox.value: + if self.app.setting_target: + self.app.setting_target += "," + self.app.setting_target += checkbox.id.replace("-checkbox", "") + print("Target setting updated: " + self.app.setting_target) + + self.app.setting_enable_copy = self.enable_copy_switch.value + print("Enable copy setting updated: " + str(self.app.setting_enable_copy)) + + if self.enable_copy_switch.value: + self.app.setting_arduino_path = self.arduino_path_input.get_input_value() + print("Arduino path setting updated: " + self.app.setting_arduino_path) + + self.app.setting_arduino_branch = self.arduino_branch_input.get_input_value() + print("Arduino branch setting updated: " + self.app.setting_arduino_branch) + + self.app.setting_idf_branch = self.idf_branch_input.get_input_value() + print("IDF branch setting updated: " + self.app.setting_idf_branch) + + self.app.setting_idf_commit = self.idf_commit_input.get_input_value() + print("IDF commit setting updated: " + self.app.setting_idf_commit) + + self.app.setting_debug_level = self.idf_debug_select.get_select_value() + print("Debug level setting updated: " + self.app.setting_debug_level) + + def on_button_pressed(self, event: Button.Pressed) -> None: + # Event handler called when a button is pressed + if event.button.id == "save-settings-button": + print("Save button pressed") + self.action_save() + elif event.button.id == "cancel-settings-button": + print("Cancel button pressed") + self.dismiss() + + @on(ScreenResume) + def on_resume(self) -> None: + # Event handler called every time the screen is activated + print("Settings screen resumed. Updating settings.") + targets = self.app.setting_target.split(",") + checkboxes = self.query(Checkbox) + for checkbox in checkboxes: + checkbox.value = False + if checkbox.id.replace("-checkbox", "") in targets: + checkbox.value = True + self.enable_copy_switch.value = self.app.setting_enable_copy + if self.app.setting_enable_copy: + self.arduino_path_input.visible = True + else: + self.arduino_path_input.visible = False + self.arduino_path_input.set_input_value(self.app.setting_arduino_path) + self.arduino_branch_input.set_input_value(self.app.setting_arduino_branch) + self.idf_branch_input.set_input_value(self.app.setting_idf_branch) + self.idf_commit_input.set_input_value(self.app.setting_idf_commit) + self.idf_debug_select.set_select_value(self.app.setting_debug_level) + + def on_switch_changed(self, event: Switch.Changed) -> None: + # Event handler called when a switch is changed + if event.switch.id == "enable-copy-switch": + if event.switch.value: + self.arduino_path_input.visible = True + else: + self.arduino_path_input.visible = False + + def compose(self) -> ComposeResult: + # Compose the target selection screen + yield Header() + with VerticalScroll(id="settings-scroll-container"): + + yield Label("Compilation Targets", id="settings-target-label") + with Container(id="settings-target-container"): + for target in self.app.supported_targets: + yield Checkbox(target.upper(), id=target + "-checkbox") + + with Horizontal(classes="settings-switch-container"): + self.enable_copy_switch = Switch(value=self.app.setting_enable_copy, id="enable-copy-switch") + yield self.enable_copy_switch + + yield Label("Copy to arduino-esp32 after compilation") + + 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") + yield self.arduino_path_input + + self.arduino_branch_input = LabelledInput("Arduino-esp32 Branch", placeholder="Leave empty to use default", value=self.app.setting_arduino_branch, id="arduino-branch-input") + yield self.arduino_branch_input + + self.idf_branch_input = LabelledInput("ESP-IDF Branch", placeholder="Leave empty to use default", value=self.app.setting_idf_branch, id="idf-branch-input") + yield self.idf_branch_input + + self.idf_commit_input = LabelledInput("ESP-IDF Commit", placeholder="Leave empty to use default", value=self.app.setting_idf_commit, id="idf-commit-input") + yield self.idf_commit_input + + debug_options = [ + ("Default", "default"), + ("None", "none"), + ("Error", "error"), + ("Warning", "warning"), + ("Info", "info"), + ("Debug", "debug"), + ("Verbose", "verbose") + ] + self.idf_debug_select = LabelledSelect("ESP-IDF Debug Level", debug_options, allow_blank=False, id="idf-debug-select") + yield self.idf_debug_select + + with Horizontal(id="settings-button-container"): + yield Button("Save", id="save-settings-button", classes="settings-button") + yield Button("Cancel", id="cancel-settings-button", classes="settings-button") + yield Footer() + + def on_mount(self) -> None: + # Event handler called when the screen is mounted for the first time + self.sub_title = "Settings" + target_container = self.query_one("#settings-target-container") + # Height needs to be 3 for each row of targets + 1 + height_value = str(int(math.ceil(len(self.app.supported_targets) / int(target_container.styles.grid_size_columns)) * 3 + 1)) + print("Target container height: " + height_value) + target_container.styles.height = height_value + print("Settings screen mounted") diff --git a/tools/config_editor/style.tcss b/tools/config_editor/style.tcss new file mode 100644 index 000000000..4359e58e0 --- /dev/null +++ b/tools/config_editor/style.tcss @@ -0,0 +1,202 @@ +# General + +Screen { + background: $surface-darken-1; +} + +Button { + width: auto; + min-width: 16; + height: auto; + color: $text; + border: none; + background: #038c8c; + border-top: tall #026868; + border-bottom: tall #6ab8b8; + text-align: center; + content-align: center middle; + text-style: bold; + + &:focus { + text-style: bold reverse; + } + &:hover { + border-top: tall #014444; + border-bottom: tall #3d8080; + background: #025b5b; + color: $text; + } + &.-active { + background: #025b5b; + border-bottom: tall #3d8080; + border-top: tall #014444; + tint: $background 30%; + } + + &.-success { + background: $success; + color: $text; + border-top: tall $success-lighten-2; + border-bottom: tall $success-darken-3; + + &:hover { + background: $success-darken-2; + color: $text; + border-top: tall $success; + } + + &.-active { + background: $success; + border-bottom: tall $success-lighten-2; + border-top: tall $success-darken-2; + } + } + + &.-error { + background: $error; + color: $text; + border-top: tall $error-lighten-2; + border-bottom: tall $error-darken-3; + + &:hover { + background: $error-darken-1; + color: $text; + border-top: tall $error; + } + + &.-active { + background: $error; + border-bottom: tall $error-lighten-2; + border-top: tall $error-darken-2; + } + } +} + +# Main Screen + +.main-menu-button { + margin-bottom: 1; + min-width: 100%; + max-width: 0.4fr; +} + +#main-menu-container { + align: center middle; + width: 1fr; +} + +#main-menu-title { + text-align: center; + margin-bottom: 4; + text-style: bold; + color: auto; + width: 0.4fr; +} + +# Compile Screen + +#compile-status-container { + layout: horizontal; + padding: 0 2; + height: 4; +} + +#compile-title { + dock: left; +} + +#compile-back-button { + dock: right; +} + +#compile-log { + background: $surface; + padding: 0 1 1 1; + margin: 1 2; +} + +# Settings Screen + +#settings-scroll-container { + padding: 1; +} + +#settings-button-container { + width: 100%; + max-height: 20%; + min-height: 5; + align: center middle; +} + +#settings-target-label { + margin-left: 1; +} + +#settings-target-container { + layout: grid; + grid-size: 4; +} + +#settings-target-container Checkbox { + width: 100%; + margin-right: -1; +} + +.settings-button { + margin: 1; + min-width: 100%; + max-width: 0.2fr; + align: center middle; +} + +.settings-switch-container { + height: 4; +} + +.settings-switch-container Switch { + margin-right: 2; +} + +.settings-switch-container Label { + margin-top: 1; +} + +# Editor Screen + +#tree-view { + display: none; + scrollbar-gutter: stable; + overflow: auto; + width: auto; + height: 100%; + dock: left; + display: block; + max-width: 50%; +} + +#code-view { + overflow: auto scroll; + min-width: 100%; +} + +#code { + width: 100%; +} + +.editor-button { + width: 20%; +} + +#save-editor-button { + dock: left; + margin: 1; +} + +#cancel-editor-button { + dock: right; + margin: 1 3; +} + +#editor-buttons-container { + height: 5; +} diff --git a/tools/config_editor/widgets.py b/tools/config_editor/widgets.py new file mode 100644 index 000000000..afec3297f --- /dev/null +++ b/tools/config_editor/widgets.py @@ -0,0 +1,95 @@ +from textual.widget import Widget + +from textual.widgets import Input, Label, Select + +class LabelledInput(Widget): + DEFAULT_CSS = """ + LabelledInput { + height: 4; + margin-bottom: 1; + } + LabelledInput Label { + padding-left: 1; + } + """ + + label_widget: Label + input_widget: Input + + def set_input_value(self, value): + self.input_widget.value = value + + def get_input_value(self): + return self.input_widget.value + + def __init__(self, + label, + *, + placeholder="", + value="", + name=None, + id=None, + classes=None, + disabled=False): + super().__init__(name=name, id=id, classes=classes, disabled=disabled) + self.__label = label + self.__placeholder = placeholder + self.__init_value = value + + def compose(self): + self.label_widget = Label(f"{self.__label}:") + self.input_widget = Input(placeholder=self.__placeholder, value=self.__init_value) + yield self.label_widget + yield self.input_widget + + +class LabelledSelect(Widget): + DEFAULT_CSS = """ + LabelledSelect { + height: 4; + margin-bottom: 1; + } + LabelledSelect Label { + padding-left: 1; + } + """ + + label_widget: Label + select_widget: Select + + def set_select_options(self, options): + self.__options = options + self.select_widget.options = options + + def get_select_options(self): + return self.__options + + def set_select_value(self, value): + self.select_widget.value = value + + def get_select_value(self): + return self.select_widget.value + + def __init__(self, + label, + options, + *, + prompt="Select", + allow_blank=True, + value=Select.BLANK, + name=None, + id=None, + classes=None, + disabled=False): + super().__init__(name=name, id=id, classes=classes, disabled=disabled) + self.__label = label + self.__options = options + self.__init_value = value + self.__prompt = prompt + self.__allow_blank = allow_blank + + def compose(self): + self.label_widget = Label(f"{self.__label}:") + self.select_widget = Select(options=self.__options, value=self.__init_value, prompt=self.__prompt, allow_blank=self.__allow_blank) + yield self.label_widget + yield self.select_widget