2) Added keyboard shortcut bindings for switching the language (Ctrl-T) and showing the help (Ctrl-A) The help should use a markdown viewer 3) Include a test folder containing all the tests
35 lines
1.2 KiB
Python
35 lines
1.2 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."""
|
|
|
|
# Styling for this screen lives in the app's shared external stylesheet
|
|
# (app/styles.tcss), loaded via DownloadManagerApp.CSS_PATH.
|
|
|
|
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)
|