GUI for finger v1
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""Logging helpers for the finger dashboard."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PyQt5.QtGui import QFont
|
||||
from PyQt5.QtWidgets import QPlainTextEdit
|
||||
|
||||
|
||||
class TeeStream:
|
||||
"""Write to multiple text streams."""
|
||||
|
||||
def __init__(self, *streams):
|
||||
self.streams = streams
|
||||
|
||||
def write(self, text):
|
||||
for stream in self.streams:
|
||||
stream.write(text)
|
||||
|
||||
def flush(self):
|
||||
for stream in self.streams:
|
||||
stream.flush()
|
||||
|
||||
|
||||
class WidgetLogHandler:
|
||||
"""Mirror print output into a QPlainTextEdit."""
|
||||
|
||||
def __init__(self, widget: QPlainTextEdit):
|
||||
self.widget = widget
|
||||
self.buf = ""
|
||||
|
||||
def write(self, text: str):
|
||||
self.buf += text
|
||||
while "\n" in self.buf:
|
||||
line, self.buf = self.buf.split("\n", 1)
|
||||
if line:
|
||||
self.widget.appendPlainText(line)
|
||||
|
||||
def flush(self):
|
||||
if self.buf:
|
||||
self.widget.appendPlainText(self.buf)
|
||||
self.buf = ""
|
||||
|
||||
|
||||
def make_log_widget() -> QPlainTextEdit:
|
||||
widget = QPlainTextEdit()
|
||||
widget.setReadOnly(True)
|
||||
widget.setMaximumBlockCount(2000)
|
||||
font = QFont("Consolas", 12)
|
||||
font.setStyleHint(QFont.Monospace)
|
||||
widget.setFont(font)
|
||||
return widget
|
||||
Reference in New Issue
Block a user