44 lines
1,011 B
Python
44 lines
1,011 B
Python
from textual.widgets import RichLog, Button
|
|
from textual.containers import Vertical, Horizontal
|
|
from textual.message import Message
|
|
|
|
|
|
class LogPanel(Vertical):
|
|
DEFAULT_CSS = """
|
|
LogPanel {
|
|
padding: 1 2;
|
|
}
|
|
#log-toolbar {
|
|
height: auto;
|
|
margin-bottom: 1;
|
|
}
|
|
RichLog {
|
|
height: 1fr;
|
|
border: solid $primary;
|
|
}
|
|
"""
|
|
|
|
class BackPressed(Message):
|
|
pass
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.log = None
|
|
|
|
def compose(self):
|
|
with Horizontal(id="log-toolbar"):
|
|
yield Button("⬅ Retour", id="log-back")
|
|
self.log = RichLog(id="log-view", highlight=True)
|
|
yield self.log
|
|
|
|
def write(self, line: str):
|
|
if self.log:
|
|
self.log.write(line)
|
|
|
|
def clear(self):
|
|
if self.log:
|
|
self.log.clear()
|
|
|
|
def on_button_pressed(self, event: Button.Pressed):
|
|
if event.button.id == "log-back":
|
|
self.post_message(self.BackPressed())
|