#!/usr/bin/env python3 """ TUI for managing wallpaper scripts with Gemini/claude-style interface """ import os import subprocess import sys from pathlib import Path from typing import List, Optional import asyncio import threading from datetime import datetime import rich from rich.console import Console from rich.panel import Panel from rich.table import Table from rich.text import Text from rich.layout import Layout from rich.live import Live from rich.prompt import Prompt, Confirm from rich.syntax import Syntax from textual.app import App, ComposeResult from textual.containers import Container, Vertical, Horizontal from textual.widgets import Button, Header, Footer, Static, Input, Label from textual import events from textual.binding import Binding class WallpaperTUI(App): """Main TUI application for wallpaper management""" BINDINGS = [ Binding("q", "quit", "Quit"), Binding("r", "refresh", "Refresh"), Binding("1", "run_sort", "Run Sort"), Binding("2", "run_sync", "Run Sync"), Binding("3", "run_wallpaper_menu", "Wallpaper Menu"), Binding("4", "run_waybar_update", "Update Waybar"), Binding("5", "run_openrgb", "Set OpenRGB") ] def __init__(self): super().__init__() self.console = Console() self.scripts_dir = Path(__file__).parent self.sort_script = self.scripts_dir / "sort_images_by_color.py" self.sync_script = self.scripts_dir / "wallpapersync.sh" self.wallpaper_menu = self.scripts_dir / "pywal" / "wallpapermenu.sh" self.waybar_script = self.scripts_dir / "pywal" / "update-waybar-theme.sh" self.openrgb_script = self.scripts_dir / "pywal" / "pywal-openrgb.py" def compose(self) -> ComposeResult: yield Header() yield self.create_main_layout() yield Footer() def create_main_layout(self): layout = Layout(name="main") layout.split( Layout(name="top", size=10), Layout(name="middle", ratio=1), Layout(name="bottom", size=5), ) layout["top"].update(Panel("Wallpaper Manager", title="Status")) layout["middle"].update(Panel(Static("Welcome to Wallpaper TUI"), title="Controls")) layout["bottom"].update(Panel(Static("Ready"), title="Status")) return layout def on_mount(self) -> None: self.refresh_status("Application started") def refresh_status(self, message: str): """Update the status message""" self.query_one("#status", Static).update(message) def on_button_pressed(self, event: Button.Pressed) -> None: """Handle button presses""" button_id = event.button.id if button_id == "run_sort": self.run_sort() elif button_id == "run_sync": self.run_sync() elif button_id == "run_wallpaper_menu": self.run_wallpaper_menu() elif button_id == "run_waybar": self.run_waybar_update() elif button_id == "run_openrgb": self.run_openrgb() def run_sort(self): """Run the sort script""" self.refresh_status("Running sort script...") try: result = subprocess.run([sys.executable, str(self.sort_script), "."], capture_output=True, text=True, check=True) self.refresh_status("Sort completed successfully") self.show_output(result.stdout, "Sort Output") except subprocess.CalledProcessError as e: self.refresh_status("Sort failed") self.show_output(e.stderr, "Sort Error") def run_sync(self): """Run the sync script""" self.refresh_status("Running sync script...") try: result = subprocess.run([str(self.sync_script)], capture_output=True, text=True, check=True) self.refresh_status("Sync completed successfully") self.show_output(result.stdout, "Sync Output") except subprocess.CalledProcessError as e: self.refresh_status("Sync failed") self.show_output(e.stderr, "Sync Error") def run_wallpaper_menu(self): """Run the wallpaper menu script""" self.refresh_status("Opening wallpaper menu...") try: # This would typically open an interactive menu # For now, we'll just show a message self.refresh_status("Wallpaper menu opened (interactive)") except Exception as e: self.refresh_status("Wallpaper menu failed") self.show_output(str(e), "Wallpaper Menu Error") def run_waybar_update(self): """Run the waybar update script""" self.refresh_status("Updating waybar theme...") try: # This would need a wallpaper path self.refresh_status("Waybar update initiated") except Exception as e: self.refresh_status("Waybar update failed") self.show_output(str(e), "Waybar Error") def run_openrgb(self): """Run the openrgb script""" self.refresh_status("Setting OpenRGB color...") try: result = subprocess.run([sys.executable, str(self.openrgb_script)], capture_output=True, text=True, check=True) self.refresh_status("OpenRGB color set") self.show_output(result.stdout, "OpenRGB Output") except subprocess.CalledProcessError as e: self.refresh_status("OpenRGB failed") self.show_output(e.stderr, "OpenRGB Error") def show_output(self, output: str, title: str): """Display output in a panel""" # In a real implementation, this would show the output in a scrollable panel self.refresh_status(f"{title} displayed") def main(): app = WallpaperTUI() app.run() if __name__ == "__main__": main()