Files
DOLPHIN/Observability/TUI/textual_poc.py

64 lines
1.9 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
Minimal Textual proof-of-concept.
Run: python3 textual_poc.py
Press q to quit.
"""
from textual.app import App, ComposeResult
from textual.widgets import Static, Header, Footer
from textual.containers import Horizontal
import time
class Box(Static):
def on_mount(self) -> None:
self.update(self.id or "box")
class PocApp(App):
CSS = """
Screen { background: #111; }
Box {
border: solid green;
height: 8;
content-align: center middle;
color: white;
}
#clock { border: solid cyan; height: 3; }
"""
BINDINGS = [("q", "quit", "Quit")]
def compose(self) -> ComposeResult:
yield Static(id="clock")
with Horizontal():
yield Box("PANEL A\nstatic text", id="panel_a")
yield Box("PANEL B\nstatic text", id="panel_b")
yield Box("PANEL C\nstatic text", id="panel_c")
yield Static("[green]q=quit[/green] | Textual POC running OK")
def on_mount(self) -> None:
self.set_interval(1, self._tick)
self._tick()
def _tick(self) -> None:
t = time.strftime("%Y-%m-%d %H:%M:%S UTC", time.gmtime())
self.query_one("#clock", Static).update(
f"[bold cyan]🐬 DOLPHIN TUI POC[/bold cyan] | {t} | Textual is working"
)
# Update panels with incrementing counter
n = int(time.time()) % 100
self.query_one("#panel_a", Box).update(
f"[green]PANEL A[/green]\nvalue = {n}\nstatus = OK"
)
self.query_one("#panel_b", Box).update(
f"[yellow]PANEL B[/yellow]\nvalue = {n*2}\nstatus = WARN"
)
self.query_one("#panel_c", Box).update(
f"[red]PANEL C[/red]\nvalue = {n*3}\nstatus = CRIT"
)
if __name__ == "__main__":
PocApp().run()