Files
ytdlp-tui/app/screens/error_screen.py
T
2026-09-19 14:18:15 +02:00

62 lines
1.6 KiB
Python

"""A simple modal dialog for reporting error messages to the user."""
from __future__ import annotations
from textual.app import ComposeResult
from textual.containers import Container, Horizontal
from textual.screen import ModalScreen
from textual.widgets import Button, Label, Static
from i18n import I18n
class ErrorScreen(ModalScreen[None]):
"""Modal dialog showing a title and a message, dismissed via OK."""
DEFAULT_CSS = """
ErrorScreen {
align: center middle;
}
ErrorScreen > Container {
width: 60%;
max-width: 70;
height: auto;
border: thick $error 80%;
background: $surface;
padding: 1 2;
}
ErrorScreen #error-title {
text-style: bold;
color: $error;
margin-bottom: 1;
}
ErrorScreen #error-message {
margin-bottom: 1;
}
ErrorScreen Horizontal {
align-horizontal: center;
height: auto;
}
"""
def __init__(self, message: str, *, title: str | None = None) -> None:
super().__init__()
self._message = message
self._title = title
def compose(self) -> ComposeResult:
i18n = I18n()
title = self._title or i18n.t("dialog.error_title", default="Error")
with Container():
yield Label(title, id="error-title")
yield Static(self._message, id="error-message")
with Horizontal():
yield Button(i18n.t("button.ok", default="OK"), id="ok", variant="error")
def on_button_pressed(self, event: Button.Pressed) -> None:
self.dismiss(None)