move highlights to model
makes it easier to manage highlights
This commit is contained in:
11
bigtext.py
11
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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user