2025-12-26 18:53:14 +01:00
|
|
|
from textual.app import ComposeResult
|
|
|
|
|
from textual.containers import HorizontalGroup
|
|
|
|
|
from textual.screen import Screen
|
|
|
|
|
from textual.widget import Widget
|
2026-02-07 02:52:31 +01:00
|
|
|
from textual.widgets import Button, DataTable, Footer, Header, Input, Static
|
2025-12-26 18:53:14 +01:00
|
|
|
|
2026-02-07 02:52:13 +01:00
|
|
|
from .models import load_initial_data
|
|
|
|
|
|
|
|
|
|
|
2026-02-14 16:36:07 +01:00
|
|
|
FAKE_DATA_HEADER = "pk Name Description Number Tags".split()
|
2026-02-07 02:52:13 +01:00
|
|
|
|
2025-12-26 18:53:14 +01:00
|
|
|
|
|
|
|
|
class SearchBar(Static):
|
|
|
|
|
DEFAULT_CSS = """
|
|
|
|
|
#teilchen-input {
|
|
|
|
|
width: 4fr;
|
|
|
|
|
}
|
|
|
|
|
#button-search, #button-add {
|
|
|
|
|
width: 1fr;
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def compose(self) -> ComposeResult:
|
|
|
|
|
with HorizontalGroup(id="search-bar-widget"):
|
|
|
|
|
yield Input(
|
|
|
|
|
placeholder="Enter Teilchen information: name, description, #tags",
|
|
|
|
|
tooltip=(
|
|
|
|
|
"This is a free-form field: Enter a name and "
|
|
|
|
|
"description any way you like. You should use #hashtags for any "
|
|
|
|
|
"meta information."
|
|
|
|
|
),
|
|
|
|
|
id="teilchen-input",
|
|
|
|
|
type="text",
|
|
|
|
|
)
|
|
|
|
|
yield Button("Add", variant="success", classes="search-bar-buttons", id="button-add")
|
|
|
|
|
yield Button(
|
|
|
|
|
"Search",
|
|
|
|
|
variant="default",
|
|
|
|
|
classes="search-bar-buttons",
|
|
|
|
|
id="button-search",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearchResults(Widget):
|
|
|
|
|
def compose(self) -> ComposeResult:
|
|
|
|
|
yield DataTable(id="table-search-result", cursor_type="row", zebra_stripes=True)
|
|
|
|
|
|
|
|
|
|
async def on_mount(self) -> None:
|
|
|
|
|
table: DataTable[None] = self.query_one(DataTable[None])
|
2026-02-14 16:36:07 +01:00
|
|
|
_ = table.add_columns(*FAKE_DATA_HEADER)
|
2026-02-07 02:52:13 +01:00
|
|
|
_ = table.add_rows(await load_initial_data()) # ty:ignore[invalid-argument-type]
|
2025-12-26 18:53:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AddInventoryScreen(Screen[None]):
|
|
|
|
|
def compose(self) -> ComposeResult:
|
|
|
|
|
yield Header()
|
|
|
|
|
yield SearchBar()
|
|
|
|
|
yield SearchResults()
|
|
|
|
|
yield Footer()
|