First checkin of the sources
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""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)
|
||||
Reference in New Issue
Block a user