from textual.app import ComposeResult from textual.containers import HorizontalGroup from textual.screen import Screen from textual.widget import Widget from textual.widgets import Button, DataTable, Footer, Header, Input, Static from .models import load_initial_data TEILCHEN_DATA_HEADER = "pk Name Description Number Tags".split() 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 = self.query_one(DataTable) table.add_columns(*TEILCHEN_DATA_HEADER) table.add_rows(await load_initial_data()) class AddInventoryScreen(Screen[None]): def compose(self) -> ComposeResult: yield Header() yield SearchBar() yield SearchResults() yield Footer()