Skip to content

RegexMatchHighlighter

Qt Base Class: QSyntaxHighlighter

Signature: QSyntaxHighlighter(self, parent: PySide6.QtCore.QObject) -> None QSyntaxHighlighter(self, parent: PySide6.QtGui.QTextDocument) -> None

Base classes

Name Children Inherits
SyntaxHighlighter
prettyqt.gui.syntaxhighlighter

⋔ Inheritance diagram

graph TD
  1473296311520["syntaxhighlighters.RegexMatchHighlighter"]
  1473245668528["gui.SyntaxHighlighter"]
  1473245664624["gui.SyntaxHighlighterMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289231040["QtGui.QSyntaxHighlighter"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473245668528 --> 1473296311520
  1473245664624 --> 1473245668528
  1473299815024 --> 1473245664624
  140713234304496 --> 1473299815024
  1473289231040 --> 1473245668528
  1473288842240 --> 1473289231040
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: SyntaxHighlighter

Source code in prettyqt\syntaxhighlighters\regexmatchhighlighter.py
class RegexMatchHighlighter(gui.SyntaxHighlighter):
    def __init__(self, document=None):
        super().__init__(document)
        self.spans: list[tuple[int, int]] | None = []

    def set_spans(self, spans: list[tuple[int, int]] | None):
        self.spans = spans
        # print(self.spans)
        self.rehighlight()

    def _colorize(self, line_pos: int, match_len: int, match_num: int):
        fmt = FORMAT_1 if match_num % 2 == 0 else FORMAT_2
        self.setFormat(line_pos, match_len, fmt)

    def highlightBlock(self, text: str):
        block = self.currentBlock()
        # line_no = block.blockNumber()
        # if line_no == 0:
        #     self.setCurrentBlockState(-1)
        start_char = block.position()
        end_char = start_char + block.length()
        if not self.spans or not text:
            return None
        for i, (start, end) in enumerate(self.spans):
            if end < start_char:
                continue
            if start > end_char:
                break
            starts_in_line = start_char <= start <= end_char
            ends_in_line = start_char <= end <= end_char
            if starts_in_line and ends_in_line or not ends_in_line and starts_in_line:
                # print(f"in line: {line_pos} - {line_pos + match_len}")
                self._colorize(start - start_char, end - start, i)
            elif ends_in_line:
                # if self.previousBlockState() == 1:
                # print(f"ends: {end}")
                self._colorize(0, end - start, i)

⌗ Property table

Qt Property Type Doc
objectName QString