First checkin of the sources

This commit is contained in:
2026-09-19 14:18:15 +02:00
parent 56ea3736d7
commit 701ff3a6d3
17 changed files with 1196 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
from .error_screen import ErrorScreen
from .format_select_screen import FormatSelectScreen
__all__ = ["ErrorScreen", "FormatSelectScreen"]
+61
View File
@@ -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)
+123
View File
@@ -0,0 +1,123 @@
"""Modal dialog that lets the user pick one format from a table.
Used both for the audio-only selection and the video (or combined
audio+video) selection, since the table layout is identical: format_id,
resolution, acodec, vcodec, format.
"""
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, DataTable, Label
from i18n import I18n
from ..models import FormatEntry
class FormatSelectScreen(ModalScreen[FormatEntry | None]):
"""Shows ``entries`` in a table and returns the row the user picked.
Returns ``None`` (via Cancel, Escape, or an empty table) so the caller
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;
}
"""
BINDINGS = [("escape", "cancel", "Cancel")]
def __init__(self, title: str, entries: list[FormatEntry]) -> None:
super().__init__()
self._title = title
self._entries = entries
def compose(self) -> ComposeResult:
i18n = I18n()
with Container():
yield Label(self._title, id="dialog-title")
table: DataTable[str] = DataTable(id="format-table", cursor_type="row")
table.add_columns(
i18n.t("table.format_id", default="Format ID"),
i18n.t("table.resolution", default="Resolution"),
i18n.t("table.acodec", default="Audio codec"),
i18n.t("table.vcodec", default="Video codec"),
i18n.t("table.format", default="Format"),
)
for entry in self._entries:
table.add_row(
entry.format_id,
entry.resolution,
entry.acodec,
entry.vcodec,
entry.format,
key=entry.format_id,
)
yield table
with Horizontal():
yield Button(
i18n.t("button.ok", default="OK"),
id="select-ok",
variant="primary",
disabled=not self._entries,
)
yield Button(i18n.t("button.cancel", default="Cancel"), id="select-cancel")
def on_mount(self) -> None:
if self._entries:
self.query_one(DataTable).focus()
def on_data_table_row_selected(self, event: DataTable.RowSelected) -> None:
self._confirm(event.row_key.value)
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "select-ok":
table = self.query_one(DataTable)
if table.row_count == 0 or table.cursor_row is None:
self.dismiss(None)
return
row_key, _ = table.coordinate_to_cell_key(table.cursor_coordinate)
self._confirm(row_key.value)
else:
self.dismiss(None)
def action_cancel(self) -> None:
self.dismiss(None)
def _confirm(self, format_id: str | None) -> None:
for entry in self._entries:
if entry.format_id == format_id:
self.dismiss(entry)
return
self.dismiss(None)