Skip to content

LogTextEdit

Qt Base Class: QPlainTextEdit

Signature: QPlainTextEdit(self, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None QPlainTextEdit(self, text: str, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None

Base classes

Name Children Inherits
PlainTextEdit
prettyqt.widgets.plaintextedit

⋔ Inheritance diagram

graph TD
  1473367109680["custom_widgets.LogTextEdit"]
  1473296323232["widgets.PlainTextEdit"]
  1473296321280["widgets.PlainTextEditMixin"]
  1473293679456["widgets.AbstractScrollAreaMixin"]
  1473293662864["widgets.FrameMixin"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473290657408["QtWidgets.QPlainTextEdit"]
  1473290616416["QtWidgets.QAbstractScrollArea"]
  1473290626176["QtWidgets.QFrame"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473296323232 --> 1473367109680
  1473296321280 --> 1473296323232
  1473293679456 --> 1473296321280
  1473293662864 --> 1473293679456
  1473293688240 --> 1473293662864
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473290657408 --> 1473296323232
  1473290616416 --> 1473290657408
  1473290626176 --> 1473290616416
  1473290849680 --> 1473290626176
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: PlainTextEdit

Source code in prettyqt\custom_widgets\logtextedit.py
class LogTextEdit(widgets.PlainTextEdit):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.rules = []
        self.allow_wheel_zoom()
        self.set_font(gui.Font.mono(as_qt=True))
        self.append_text(f"Python version: {sys.version}")
        new_logger = logging.getLogger()
        # self.handler = signallogger.LineSignalLogger()
        # self.handler.log_line.connect(self.append_text)
        self.handler = signallogger.SignalLogger()
        self.handler.signals.log_record.connect(self.append_record)
        core.CoreApplication.call_on_exit(lambda: new_logger.removeHandler(self.handler))
        self.handler.setLevel(logging.INFO)
        new_logger.addHandler(self.handler)
        fmt = logging.Formatter("%(asctime)s  %(levelname)s  %(message)s")
        self.set_formatter(fmt)

    def set_formatter(self, formatter: logging.Formatter):
        self.formatter = formatter
        rules = [klass(self.formatter) for klass in Highlighter.__subclasses__()]
        self.rules = [r for r in rules if r.is_included]
        self.handler.setFormatter(formatter)

    def append_record(self, record: logging.LogRecord):
        start_of_line = len(self.text())
        if self.formatter._fmt is None:
            raise TypeError("Formatter does not contain format string")
        self.append_text(self.formatter._fmt)
        old_fmt = self.textCursor().charFormat()
        with self.selecter.create_cursor() as c:
            c.move_position("end")
            c.move_position("start_of_block")
            start_pos = c.position()
            for r in self.rules:
                line_text = c.select_text(start_pos, "end_of_block")
                matches = list(r.pattern.finditer(line_text))
                for m in reversed(matches):
                    pos = m.start(0) + start_of_line
                    if start_of_line != 0:
                        pos += 1
                    end = pos + m.end(0) - m.start(0)
                    fmt_string = r.format_string(record)
                    try:
                        value = f"%{m.group(1)}" % fmt_string
                    except (TypeError, ValueError):
                        value = fmt_string
                    c.replace_text(pos, end, value)
                    fmt = r.get_format(fmt_string)
                    c.setCharFormat(fmt)
                    c.clearSelection()
                    c.setCharFormat(old_fmt)

⌗ Property table

Qt Property Type Doc
objectName QString
modal bool
windowModality Qt::WindowModality
enabled bool
geometry QRect
frameGeometry QRect
normalGeometry QRect
x int
y int
pos QPoint
frameSize QSize
size QSize
width int
height int
rect QRect
childrenRect QRect
childrenRegion QRegion
sizePolicy QSizePolicy
minimumSize QSize
maximumSize QSize
minimumWidth int
minimumHeight int
maximumWidth int
maximumHeight int
sizeIncrement QSize
baseSize QSize
palette QPalette
font QFont
cursor QCursor
mouseTracking bool
tabletTracking bool
isActiveWindow bool
focusPolicy Qt::FocusPolicy
focus bool
contextMenuPolicy Qt::ContextMenuPolicy
updatesEnabled bool
visible bool
minimized bool
maximized bool
fullScreen bool
sizeHint QSize
minimumSizeHint QSize
acceptDrops bool
windowTitle QString
windowIcon QIcon
windowIconText QString
windowOpacity double
windowModified bool
toolTip QString
toolTipDuration int
statusTip QString
whatsThis QString
accessibleName QString
accessibleDescription QString
layoutDirection Qt::LayoutDirection
autoFillBackground bool
styleSheet QString
locale QLocale
windowFilePath QString
inputMethodHints QFlags
frameShape QFrame::Shape
frameShadow QFrame::Shadow
lineWidth int
midLineWidth int
frameWidth int
frameRect QRect
verticalScrollBarPolicy Qt::ScrollBarPolicy
horizontalScrollBarPolicy Qt::ScrollBarPolicy
sizeAdjustPolicy QAbstractScrollArea::SizeAdjustPolicy
tabChangesFocus bool
documentTitle QString
undoRedoEnabled bool
lineWrapMode QPlainTextEdit::LineWrapMode
readOnly bool
plainText QString
overwriteMode bool
tabStopDistance double
cursorWidth int
textInteractionFlags QFlags
blockCount int
maximumBlockCount int
backgroundVisible bool
centerOnScroll bool
placeholderText QString
current_line_color QColor Color to use for current line highlighting
validation_color QColor Color to use for invalid text