|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from rich.table import Table |
| 4 | + |
| 5 | +from textual.app import App, ComposeResult |
| 6 | +from textual.widgets import Footer, Header, OptionList |
| 7 | +from textual.widgets.option_list import Option, Separator |
| 8 | + |
| 9 | +COLONIES: tuple[tuple[str, str, str, str], ...] = ( |
| 10 | + ("Aerilon", "Demeter", "1.2 Billion", "Gaoth"), |
| 11 | + ("Aquaria", "Hermes", "75,000", "None"), |
| 12 | + ("Canceron", "Hephaestus", "6.7 Billion", "Hades"), |
| 13 | + ("Caprica", "Apollo", "4.9 Billion", "Caprica City"), |
| 14 | + ("Gemenon", "Hera", "2.8 Billion", "Oranu"), |
| 15 | + ("Leonis", "Artemis", "2.6 Billion", "Luminere"), |
| 16 | + ("Libran", "Athena", "2.1 Billion", "None"), |
| 17 | + ("Picon", "Poseidon", "1.4 Billion", "Queenstown"), |
| 18 | + ("Sagittaron", "Zeus", "1.7 Billion", "Tawa"), |
| 19 | + ("Scorpia", "Dionysus", "450 Million", "Celeste"), |
| 20 | + ("Tauron", "Ares", "2.5 Billion", "Hypatia"), |
| 21 | + ("Virgon", "Hestia", "4.3 Billion", "Boskirk"), |
| 22 | +) |
| 23 | + |
| 24 | + |
| 25 | +class OptionListApp(App[None]): |
| 26 | + CSS_PATH = "option_list.css" |
| 27 | + |
| 28 | + @staticmethod |
| 29 | + def colony(name: str, god: str, population: str, capital: str) -> Table: |
| 30 | + table = Table(title=f"Data for {name}", expand=True) |
| 31 | + table.add_column("Patron God") |
| 32 | + table.add_column("Population") |
| 33 | + table.add_column("Capital City") |
| 34 | + table.add_row(god, population, capital) |
| 35 | + return table |
| 36 | + |
| 37 | + def compose(self) -> ComposeResult: |
| 38 | + yield Header() |
| 39 | + yield OptionList(*[self.colony(*row) for row in COLONIES]) |
| 40 | + yield Footer() |
| 41 | + |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + OptionListApp().run() |
0 commit comments