1) Uses textuals CSS_PATH and an external tcss file to bundle all DEFAULT_CSS into one file
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
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from .error_screen import ErrorScreen
|
||||
from .format_select_screen import FormatSelectScreen
|
||||
from .help_screen import HelpScreen
|
||||
from .language_select_screen import LanguageSelectScreen
|
||||
|
||||
__all__ = ["ErrorScreen", "FormatSelectScreen"]
|
||||
__all__ = ["ErrorScreen", "FormatSelectScreen", "HelpScreen", "LanguageSelectScreen"]
|
||||
|
||||
@@ -13,35 +13,8 @@ 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;
|
||||
}
|
||||
"""
|
||||
# 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__()
|
||||
|
||||
@@ -24,37 +24,8 @@ class FormatSelectScreen(ModalScreen[FormatEntry | None]):
|
||||
can treat that as "no valid entry selected".
|
||||
"""
|
||||
|
||||
DEFAULT_CSS = """
|
||||
FormatSelectScreen {
|
||||
align: center middle;
|
||||
}
|
||||
|
||||
FormatSelectScreen > Container {
|
||||
width: 90%;
|
||||
max-width: 120;
|
||||
height: auto;
|
||||
max-height: 80%;
|
||||
border: thick $primary 80%;
|
||||
background: $surface;
|
||||
padding: 1 2;
|
||||
}
|
||||
|
||||
FormatSelectScreen #dialog-title {
|
||||
text-style: bold;
|
||||
margin-bottom: 1;
|
||||
}
|
||||
|
||||
FormatSelectScreen DataTable {
|
||||
height: auto;
|
||||
max-height: 20;
|
||||
margin-bottom: 1;
|
||||
}
|
||||
|
||||
FormatSelectScreen Horizontal {
|
||||
align-horizontal: center;
|
||||
height: auto;
|
||||
}
|
||||
"""
|
||||
# Styling for this screen lives in the app's shared external stylesheet
|
||||
# (app/styles.tcss), loaded via DownloadManagerApp.CSS_PATH.
|
||||
|
||||
BINDINGS = [("escape", "cancel", "Cancel")]
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Modal dialog showing the current language's help text as Markdown."""
|
||||
|
||||
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, MarkdownViewer
|
||||
|
||||
from i18n import I18n
|
||||
|
||||
|
||||
class HelpScreen(ModalScreen[None]):
|
||||
"""Renders ``I18n.get_help()`` in a scrollable Markdown viewer."""
|
||||
|
||||
# Styling for this screen lives in the app's shared external stylesheet
|
||||
# (app/styles.tcss), loaded via DownloadManagerApp.CSS_PATH.
|
||||
|
||||
BINDINGS = [("escape", "close", "Close")]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
i18n = I18n()
|
||||
try:
|
||||
help_text = i18n.get_help()
|
||||
except FileNotFoundError:
|
||||
help_text = i18n.t("dialog.help_missing", default="No help is available.")
|
||||
|
||||
with Container():
|
||||
yield Label(i18n.t("dialog.help_title", default="Help"), id="help-title")
|
||||
yield MarkdownViewer(help_text, show_table_of_contents=False)
|
||||
with Horizontal():
|
||||
yield Button(i18n.t("button.close", default="Close"), id="help-close")
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
self.dismiss(None)
|
||||
|
||||
def action_close(self) -> None:
|
||||
self.dismiss(None)
|
||||
@@ -0,0 +1,48 @@
|
||||
"""Modal dialog for picking one of the application's available languages."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from textual.app import ComposeResult
|
||||
from textual.containers import Container, Horizontal, Vertical
|
||||
from textual.screen import ModalScreen
|
||||
from textual.widgets import Button, Label
|
||||
|
||||
from i18n import I18n
|
||||
|
||||
|
||||
class LanguageSelectScreen(ModalScreen[str | None]):
|
||||
"""Shows one button per available language; returns the chosen code.
|
||||
|
||||
Returns ``None`` if the dialog is cancelled (Escape or the Cancel
|
||||
button), leaving the current language unchanged.
|
||||
"""
|
||||
|
||||
# Styling for this screen lives in the app's shared external stylesheet
|
||||
# (app/styles.tcss), loaded via DownloadManagerApp.CSS_PATH.
|
||||
|
||||
BINDINGS = [("escape", "cancel", "Cancel")]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
i18n = I18n()
|
||||
with Container():
|
||||
yield Label(
|
||||
i18n.t("dialog.select_language", default="Select language"),
|
||||
id="language-title",
|
||||
)
|
||||
with Vertical(id="language-options"):
|
||||
for code, display_name in i18n.get_available_languages().items():
|
||||
variant = "primary" if code == i18n.get_language() else "default"
|
||||
yield Button(display_name, id=f"lang-{code}", variant=variant)
|
||||
with Horizontal():
|
||||
yield Button(i18n.t("button.cancel", default="Cancel"), id="language-cancel")
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
button_id = event.button.id or ""
|
||||
if button_id == "language-cancel":
|
||||
self.dismiss(None)
|
||||
return
|
||||
if button_id.startswith("lang-"):
|
||||
self.dismiss(button_id.removeprefix("lang-"))
|
||||
|
||||
def action_cancel(self) -> None:
|
||||
self.dismiss(None)
|
||||
Reference in New Issue
Block a user