DEBUG: minimal OperationLog - no RichLog, just Static + Button
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
import asyncio
|
|
||||||
|
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
from textual.app import ComposeResult
|
from textual.app import ComposeResult
|
||||||
from textual.screen import ModalScreen
|
from textual.screen import ModalScreen
|
||||||
from textual.widgets import RichLog, Button, Static
|
from textual.widgets import RichLog, Button, Static
|
||||||
from textual.containers import Vertical, Horizontal
|
from textual.containers import Vertical
|
||||||
|
|
||||||
|
|
||||||
class OperationLog(ModalScreen[None]):
|
class OperationLog(ModalScreen[None]):
|
||||||
@@ -18,10 +16,8 @@ class OperationLog(ModalScreen[None]):
|
|||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
with Vertical(id="op-log"):
|
with Vertical(id="op-log"):
|
||||||
with Horizontal(id="ol-header"):
|
yield Static(self._title, id="ol-title")
|
||||||
yield Static(self._title, id="ol-title")
|
yield Static("Running...", id="ol-status")
|
||||||
yield Static("⏳", id="ol-spinner")
|
|
||||||
yield RichLog(id="ol-log", wrap=True, highlight=True, markup=True)
|
|
||||||
yield Button("Close", variant="primary", id="ol-close")
|
yield Button("Close", variant="primary", id="ol-close")
|
||||||
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
@@ -30,22 +26,15 @@ class OperationLog(ModalScreen[None]):
|
|||||||
def action_close(self) -> None:
|
def action_close(self) -> None:
|
||||||
self.dismiss(None)
|
self.dismiss(None)
|
||||||
|
|
||||||
def _write_to_log(self, log: RichLog, text: str) -> None:
|
|
||||||
if "[" in text and "[/" in text:
|
|
||||||
log.write(Text.from_markup(text))
|
|
||||||
else:
|
|
||||||
log.write(text)
|
|
||||||
|
|
||||||
def finish(self) -> None:
|
def finish(self) -> None:
|
||||||
self._running = False
|
self._running = False
|
||||||
try:
|
try:
|
||||||
self.query_one("#ol-spinner", Static).update("✅")
|
self.query_one("#ol-status", Static).update("Done ✅")
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def write(self, text: str) -> None:
|
def write(self, text: str) -> None:
|
||||||
try:
|
try:
|
||||||
log = self.query_one("#ol-log", RichLog)
|
self.query_one("#ol-status", Static).update(text)
|
||||||
self._write_to_log(log, text)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user