| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- # -*- coding: utf-8 -*-
- """
- Popup-Fenster (Modal) fuer die TUI.
- """
- from textual.screen import ModalScreen
- from textual.containers import Vertical, Horizontal
- from textual.widgets import Static, Button
- from textual.app import ComposeResult
- class PopupWindow(ModalScreen[bool]):
- """
- Modales Popup-Fenster.
- Zeigt eine Nachricht mit OK-Button.
- """
- DEFAULT_CSS = """
- PopupWindow {
- align: center middle;
- }
- PopupWindow > Vertical {
- width: 60;
- height: auto;
- max-height: 20;
- border: thick $accent;
- background: $surface;
- padding: 1 2;
- }
- PopupWindow > Vertical > Static {
- margin-bottom: 1;
- }
- PopupWindow > Vertical > Button {
- width: 100%;
- }
- """
- def __init__(self, title: str, message: str, **kwargs) -> None:
- super().__init__(**kwargs)
- self._title = title
- self._message = message
- def compose(self) -> ComposeResult:
- with Vertical():
- yield Static(f"[bold]{self._title}[/bold]")
- yield Static(self._message)
- yield Button("OK", variant="primary", id="popup-ok")
- def on_button_pressed(self, event: Button.Pressed) -> None:
- """Schliesst das Popup."""
- self.dismiss(True)
- class ConfirmDialog(ModalScreen[bool]):
- """
- Bestaetigungs-Dialog mit OK und Abbrechen.
- Gibt True bei OK, False bei Abbrechen zurueck.
- """
- DEFAULT_CSS = """
- ConfirmDialog {
- align: center middle;
- }
- ConfirmDialog > Vertical {
- width: 70;
- height: auto;
- max-height: 24;
- border: thick $accent;
- background: $surface;
- padding: 1 2;
- }
- ConfirmDialog > Vertical > Static {
- margin-bottom: 1;
- }
- ConfirmDialog > Vertical > Horizontal {
- height: 3;
- margin-top: 1;
- }
- ConfirmDialog > Vertical > Horizontal > Button {
- width: 1fr;
- margin: 0 1;
- }
- """
- def __init__(self, title: str, message: str, **kwargs) -> None:
- super().__init__(**kwargs)
- self._title = title
- self._message = message
- def compose(self) -> ComposeResult:
- with Vertical():
- yield Static(f"[bold]{self._title}[/bold]")
- yield Static(self._message)
- with Horizontal():
- yield Button("OK", variant="warning", id="confirm-ok")
- yield Button("Abbrechen", variant="default", id="confirm-cancel")
- def on_button_pressed(self, event: Button.Pressed) -> None:
- if event.button.id == "confirm-ok":
- self.dismiss(True)
- else:
- self.dismiss(False)
|