add: первый экран TUI

This commit is contained in:
2025-06-08 16:24:19 +03:00
parent ec1b585fb2
commit e6dd940d8a
5 changed files with 110 additions and 5 deletions

97
src/pganec/tui.py Normal file
View File

@@ -0,0 +1,97 @@
# -*- coding: utf-8 -*-
# src/pganec/tui.py
import logging
from textual.app import App, ComposeResult
from textual.containers import Vertical, Horizontal
from textual.widgets import Button, Header, Footer, Static
logger = logging.getLogger(__name__)
class MainMenu(Static):
def compose(self) -> ComposeResult:
yield Horizontal(
Button(label="Backup (DB -> Dump)", id="backup", variant="primary"),
Button(label="Restore (Dump -> DB)", id="restore", variant="primary"),
Button(label="Copy (DB -> DB)", id="copy", variant="error"),
Button(label="Quit", id="quit", variant="error"),
id="menu",
)
yield Footer()
class PGanecApp(App):
CSS = """
#menu {
width: 100%;
align: left top;
padding: 0;
}
Button {
align: left middle;
text-align: left;
width: 25%;
color: orange;
background: transparent;
margin: 0;
padding: 0;
}
Button.-primary {
color: orange;
border: round orange;
text-align: left;
}
Button.-error {
color: grey;
border: round orange;
text-align: left;
}
Button:focus {
border: heavy green;
}
"""
BINDINGS = [
("b", "backup", "Backup"),
("r", "restore", "Restore"),
("с", "copy", "Copy"),
("q", "quit", "Quit"),
("right", "focus_next"), ("down", "focus_next"),
("left", "focus_previous"), ("up", "focus_previous"),
("enter", "activate"),
]
def compose(self) -> ComposeResult:
yield Header()
yield Static("PGanec", id="title")
yield MainMenu()
yield Footer()
async def on_button_pressed(self, event: Button.Pressed) -> None:
button_id = event.button.id
if button_id == "backup":
await self.push_screen(BackupScreen()) # пока заглушка
elif button_id == "restore":
await self.push_screen(RestoreScreen()) # пока заглушка
elif button_id == "copy":
await self.action_quit()
elif button_id == "quit":
await self.action_quit()
async def action_activate(self) -> None:
focused = self.focused
if isinstance(focused, Button):
await self.on_button_pressed(Button.Pressed(focused))
# Заглушки для других экранов:
class BackupScreen(Static):
def on_mount(self) -> None:
self.update("🛠 Здесь будет экран выбора сервера для бэкапа.")
class RestoreScreen(Static):
def on_mount(self) -> None:
self.update("♻️ Здесь будет экран выбора сервера и бэкапа для восстановления.")