from PySide6.QtCore import QObject, Signal, Slot
from PySide6.QtWidgets import QPlainTextEdit
import winsound

class UILogger(QObject):
    append_line = Signal(str)

    def __init__(self, widget: QPlainTextEdit):
        super().__init__()

        self.widget = widget
        self.widget.setReadOnly(True)
        self.widget.setMaximumBlockCount(2000)
        self.append_line.connect(self._append)


    @Slot(str)
    def _append(self, text: str):
        self.widget.appendPlainText(text)

    def log(self, text:str):
        self.append_line.emit(text)
        winsound.PlaySound("SystemExclamation", winsound.SND_ALIAS | winsound.SND_ASYNC)
