If you use the Python logging module, you can easily create your own logging handler that passes log messages through an instance of QPlainTextEdit (as described by Christopher).
For this, you are the first subclass of logging.Handler . In this __init__ we create a QPlainTextEdit that will contain the logs. The key bit here is that the handle will receive messages through the emit() function. Therefore, we overload this function and pass the message text to QPlainTextEdit .
import logging class QPlainTextEditLogger(logging.Handler): def __init__(self, parent): super(Logger, self).__init__() self.widget = QPlainTextEdit(parent) self.widget.setReadOnly(True) def emit(self, record): msg = self.format(record) self.widget.textCursor().appendPlainText(msg) def write(self, m): pass
Create an object from this class by passing it the parent element for QPlainTextEdit (for example, the main window or layout). Then you can add this handler for the current registrar.
mfitzp
source share