From dbfe0bebf812d1b0120ae8e002fa7ff6df8bf3e3 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Thu, 28 Oct 2021 09:52:00 +0200 Subject: [PATCH] move highlights to model makes it easier to manage highlights --- bigtext.py | 11 +---------- logFileModel.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bigtext.py b/bigtext.py index 3076104..c6b9936 100644 --- a/bigtext.py +++ b/bigtext.py @@ -106,8 +106,6 @@ class InnerBigText(QWidget): scroll_lines = 0 longest_line = 0 - highlights: [Highlight] = [] - def __init__(self, parent: BigText, model: LogFileModel): super(InnerBigText, self).__init__() self.model = model @@ -118,13 +116,6 @@ class InnerBigText(QWidget): self.update_font_metrics(QPainter(self)) self.lines = [] self.selection_highlight = HighlightSelection() - self.highlights = [ - HighlightRegex( - r"ERROR", - brush=QBrush(QColor(220, 112, 122)), - brush_full_line=QBrush(QColor(255, 112, 122)) - ) - ] def keyPressEvent(self, e: QKeyEvent) -> None: @@ -259,7 +250,7 @@ class InnerBigText(QWidget): for l in self.lines: self.update_longest_line(len(l.line())) - highlighters = self.highlights + [self.selection_highlight] + highlighters = self.model.highlights + [self.selection_highlight] # draw hightlights first - some characters may overlap to the next line # by drawing the background hightlights first we prevent that the hightlight diff --git a/logFileModel.py b/logFileModel.py index edd2aa2..5ee5cc4 100644 --- a/logFileModel.py +++ b/logFileModel.py @@ -2,6 +2,10 @@ import math import threading import time from typing import List + +from PyQt6.QtGui import QBrush, QColor + +from highlight_regex import HighlightRegex from line import Line import os from settings import Settings @@ -14,6 +18,14 @@ class LogFileModel: self._file = os.path.realpath(file) self._lock = threading.RLock() + self.highlights = [ + HighlightRegex( + r"ERROR", + brush=QBrush(QColor(220, 112, 122)), + brush_full_line=QBrush(QColor(255, 112, 122)) + ) + ] + def get_file(self): return self._file