plugin_custom_view.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. """
  3. Plugin SubView: Benutzerdefinierter Tab.
  4. Generischer View fuer plugin-spezifische Inhalte, die vom
  5. Plugin ueber get_config_tool_tabs() definiert werden.
  6. """
  7. from __future__ import annotations
  8. from textual.app import ComposeResult
  9. from textual.containers import Vertical
  10. from textual.widgets import Static
  11. from trixy_core.tui.views.base import MainView
  12. class PluginCustomView(MainView):
  13. """Dynamisch erstellter Tab fuer plugin-spezifische Inhalte."""
  14. def __init__(
  15. self,
  16. tab_title: str,
  17. tab_id: str,
  18. tab_data: dict | None = None,
  19. **kwargs,
  20. ) -> None:
  21. super().__init__(**kwargs)
  22. self.TITLE = tab_title
  23. self.VIEW_ID = tab_id
  24. self._plugin_data: dict = {}
  25. self._tab_data: dict = tab_data or {}
  26. def set_plugin(self, plugin_data: dict) -> None:
  27. """Setzt die Plugin-Basisdaten."""
  28. self._plugin_data = plugin_data
  29. def compose(self) -> ComposeResult:
  30. with Vertical(classes="section-box"):
  31. yield Static(
  32. f"[bold]{self.TITLE}[/bold]", classes="section-header"
  33. )
  34. yield Static(
  35. "[dim]Dieser Tab wird vom Plugin bereitgestellt.\n"
  36. "Plugin-spezifische Inhalte werden in zukuenftigen Versionen unterstuetzt.[/dim]",
  37. id=f"{self.VIEW_ID}-content",
  38. )
  39. async def on_activate(self) -> None:
  40. """Aktiviert den View."""
  41. content = self.query_one(f"#{self.VIEW_ID}-content", Static)
  42. tab_desc = self._tab_data.get("description", "")
  43. if tab_desc:
  44. content.update(f"[dim]{tab_desc}[/dim]")