From 505c5f342180dbaad4f1b1e273651526ac9096f0 Mon Sep 17 00:00:00 2001 From: erjemin Date: Sun, 8 Jun 2025 23:42:38 +0300 Subject: [PATCH] =?UTF-8?q?tmp:=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BA=D1=80?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=8E=D1=89=D0=B5=D0=B5=20=D0=BE=D0=BA=D0=BD?= =?UTF-8?q?=D0=BE=20textual=20=D0=BF=D1=80=D0=B8=20backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pganec/tui.py | 50 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/pganec/tui.py b/src/pganec/tui.py index 12f97b9..dfd8944 100644 --- a/src/pganec/tui.py +++ b/src/pganec/tui.py @@ -3,10 +3,13 @@ import logging from logging.handlers import MemoryHandler -from typing import Dict, Any, Optional +from typing import Dict, Any, Optional, List, Tuple from textual.app import App, ComposeResult -from textual.containers import Vertical, Horizontal -from textual.widgets import Button, Header, Footer, Static, Log +from textual.containers import Vertical, Horizontal, Container +from textual.css.query import DOMQuery +from textual.reactive import reactive +from textual.screen import Screen +from textual.widgets import Button, Header, Footer, Static, Log, Label, ListView, ListItem, OptionList # --- Настройки и инициирование логирования модуля --- logger = logging.getLogger(__name__) @@ -44,6 +47,24 @@ class MainMenu(Static): id="menu", ) +# Новый простой экран для Backup +class SimpleBackupScreen(Screen): + """ + Простой экран для демонстрации перехода при выборе Backup. + """ + + BINDINGS = [ + ("escape", "pop_screen", "Назад"), # Позволяет вернуться на главный экран по Escape + ] + + def compose(self) -> ComposeResult: + yield Header(name="Экран Бэкапа") # Заголовок для нового экрана + yield Label("Привет, мир! Это экран для бэкапа.", classes="greeting-label") + yield Footer() + + def on_mount(self) -> None: + logger.info(f"Экран '{self.id}' (SimpleBackupScreen) смонтирован.") + class PGanecApp(App): CSS = """ Screen { @@ -65,9 +86,9 @@ class PGanecApp(App): margin: 0; padding: 0; } - Button#backup, Button#restore { color: orange; border: round orange; } + Button#backup, Button#restore, Button#quit { color: orange; border: round orange; } - Button#copy, Button#quit { color: grey; border: round orange; } + Button#copy { color: grey; border: round orange; } Button:focus { border: heavy green; } @@ -79,6 +100,15 @@ class PGanecApp(App): background: 15%; } Log#app_log_viewer:focus { height: 50%; border-top: solid green; background: 45%; } + + /* Стили для нового экрана */ + SimpleBackupScreen .greeting-label { + width: 100%; + text-align: center; + padding: 2 0; /* Немного отступов сверху и снизу */ + text-style: bold; + } + Footer { dock: bottom; height: 1; } Header { dock: top; height: 1; } @@ -91,7 +121,7 @@ class PGanecApp(App): ("q", "quit", "Quit"), ("right", "focus_next"), ("down", "focus_next"), # Стрелочки для навигации (вниз/вправо -- вперед) ("left", "focus_previous"), ("up", "focus_previous"), # Стрелочки для навигации (вверх/влево -- назад) - ("enter", "activate", "Activate"), + ("enter", "activate"), ] def __init__(self, @@ -124,10 +154,12 @@ class PGanecApp(App): async def on_button_pressed(self, event: Button.Pressed) -> None: button_id = event.button.id if button_id == "backup": - await self.push_screen(BackupScreen()) # пока заглушка + await self.push_screen(SimpleBackupScreen()) elif button_id == "restore": - await self.push_screen(RestoreScreen()) # пока заглушка + logger.info("Действие 'Restore' пока не реализовано с новым экраном.") + self.app.bell() # Сигнал, что действие не выполнено elif button_id == "copy": + logger.warning("Copy action is currently a placeholder for quit.") await self.action_quit() elif button_id == "quit": await self.action_quit() @@ -168,8 +200,8 @@ class PGanecApp(App): self.early_log_handler = None # Очищаем ссылку # --- Конец переноса и сброса --- - logger.debug("TUI: DEBUG сообщение для проверки") logger.info("TUI-логгер инициализирован") + logger.debug("TUI: DEBUG сообщение для проверки") logger.warning("TUI: WARNING для проверки") logger.error("TUI: ERROR тоже для проверки")