| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- # -*- coding: utf-8 -*-
- """
- Trainer SubView: Info (F1).
- Zeigt allgemeine Trainer-Informationen als StatusTable:
- Name, Version, Autor, Modell-Typ, Trainer-Typ.
- """
- from __future__ import annotations
- from textual.app import ComposeResult
- from textual.containers import Vertical
- from textual.widgets import Static
- from trixy_core.tui.views.base import MainView
- from trixy_core.tui.widgets.status_table import StatusTable
- class TrainerInfoView(MainView):
- """F1 im Trainer-Kontext: Allgemeine Trainer-Informationen."""
- TITLE = "Info"
- VIEW_ID = "trainer_info"
- def __init__(self, **kwargs) -> None:
- super().__init__(**kwargs)
- self._trainer_data: dict = {}
- self._detail_data: object | None = None
- def set_trainer(self, trainer_data: dict) -> None:
- """Setzt die Trainer-Basisdaten."""
- self._trainer_data = trainer_data
- self._detail_data = None
- def compose(self) -> ComposeResult:
- with Vertical(classes="trainer-section"):
- yield Static("[bold]Trainer-Informationen[/bold]", classes="trainer-section-header")
- yield StatusTable(id="trainer-info-table")
- with Vertical(classes="trainer-section"):
- yield Static("[bold]Beschreibung[/bold]", classes="trainer-section-header")
- yield Static("", id="trainer-info-desc")
- async def on_activate(self) -> None:
- """Laedt Detail-Daten vom Server."""
- await self._load_detail()
- async def refresh_data(self) -> None:
- """Kein periodisches Update noetig fuer statische Info."""
- pass
- async def _load_detail(self) -> None:
- """Laedt detaillierte Trainer-Daten."""
- if not self.connection or not self._trainer_data:
- return
- trainer_id = self._trainer_data.get("trainer_id", "")
- if not trainer_id:
- return
- try:
- detail = await self.connection.request_trainer_detail(trainer_id)
- except Exception:
- return
- if detail is None or detail.error:
- return
- self._detail_data = detail
- self._populate(detail)
- def _populate(self, detail: object) -> None:
- """Befuellt die Anzeige mit Detail-Daten."""
- table = self.query_one("#trainer-info-table", StatusTable)
- table.update_data([
- ("Name", getattr(detail, "name", "")),
- ("Version", getattr(detail, "version", "")),
- ("Autor", getattr(detail, "author", "")),
- ("Modell-Typ", getattr(detail, "model_type", "")),
- ("Trainer-Typ", getattr(detail, "trainer_type", "")),
- ("Trainer-ID", getattr(detail, "trainer_id", "")),
- ])
- desc = self.query_one("#trainer-info-desc", Static)
- desc.update(getattr(detail, "description", "Keine Beschreibung"))
|