Files
ytdlp-tui/app/screens/language_select_screen.py
T
ingo fccd2def59 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
2026-09-19 14:28:40 +02:00

49 lines
1.8 KiB
Python

"""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)