from typing import Optional from highlight import Highlight from highlighted_range import HighlightedRange from line import Line from PyQt6.QtCore import * from PyQt6.QtGui import * from PyQt6.QtWidgets import * from settings import Settings from typing import List import re class HighlightRegex(Highlight): def __init__(self, regex: str, brush: QBrush = QBrush(), pen: QPen = Qt.PenStyle.NoPen, brush_full_line=QBrush()): self.regex = regex self.brush = brush self.pen = pen self.brush_full_line = brush_full_line def compute_highlight(self, line: Line) -> Optional[List[HighlightedRange]]: result = [] #print("execute regex: %s in %s" % (self.regex, line.line())) match_iter = re.finditer(self.regex, line.line()) for match in match_iter: #print("%s" % match) group0 = match.group(0) start = match.start(0) end = match.end(0) #print("regex: %s" % (group0)) result.append(HighlightedRange( start, end-start, highlight_full_line=True, brush=self.brush, pen=self.pen, brush_full_line=self.brush_full_line )) return result