sp-hydra-veil-gui/gui/v2/ui/widgets/terminal_widget.py
2026-06-13 16:19:11 -04:00

52 lines
1.6 KiB
Python
Executable file

from PyQt6.QtWidgets import QPlainTextEdit
from PyQt6.QtGui import QFont
from PyQt6.QtCore import pyqtSignal
class TerminalWidget(QPlainTextEdit):
line_appended = pyqtSignal(str)
def __init__(self, parent=None):
super().__init__(parent)
self.setReadOnly(True)
font = QFont()
font.setFamily("Courier New")
font.setPointSize(11)
font.setWeight(QFont.Weight.Bold)
self.setFont(font)
self.setStyleSheet("""
QPlainTextEdit {
background-color: #0a0e27;
color: #0fff50;
border: 3px solid #0fff50;
border-radius: 8px;
padding: 10px;
font-family: 'Courier New', 'Consolas', monospace;
font-size: 11pt;
font-weight: bold;
}
""")
self.line_appended.connect(self._append_on_main_thread)
self._observer = None
self._topics = []
self._callbacks = []
def _append_on_main_thread(self, text):
self.appendPlainText(text)
def bind_observer(self, observer, topics):
self._observer = observer
self._topics = list(topics)
for topic in self._topics:
cb = lambda event, t=topic: self.line_appended.emit(self._format_event(t, event))
observer.subscribe(topic, cb)
self._callbacks.append((topic, cb))
def _format_event(self, topic, event):
subject = getattr(event, 'subject', None)
if subject is None:
return f"[{topic}]"
return f"[{topic}] {subject}"
def append(self, text):
self.line_appended.emit(str(text))