Files
hk4e-gm-clone/ui2/pages_log.py
T

27 lines
874 B
Python

"""日志页。"""
from __future__ import annotations
from PySide6.QtGui import QColor, QTextCharFormat, QTextCursor
from . import widgets as W
from .main import Page
class LogPage(Page):
key = "log"
def build(self) -> None:
self.view = W.logview(self, 84, 40, 1283, 900)
self.view.document().setMaximumBlockCount(3000)
self.view.setStyleSheet("background:#393939;border-radius:6px;padding:6px;")
def append(self, line: str, level: str = "info") -> None:
color = {"ok": "#43C08A", "warn": "#E0B04A", "error": "#E05C6E"}.get(level, "#D8D8D8")
fmt = QTextCharFormat()
fmt.setForeground(QColor(color))
cursor = self.view.textCursor()
cursor.movePosition(QTextCursor.End)
cursor.insertText(line + "\n", fmt)
self.view.setTextCursor(cursor)
self.view.ensureCursorVisible()