highlight matches
This commit is contained in:
@@ -250,7 +250,10 @@ class InnerBigText(QWidget):
|
||||
for l in self.lines:
|
||||
self.update_longest_line(len(l.line()))
|
||||
|
||||
highlighters = self.model.highlights + [self.selection_highlight]
|
||||
highlighters = self.model.highlights
|
||||
if self.model.get_query_highlight():
|
||||
highlighters = highlighters + [self.model.get_query_highlight()]
|
||||
highlighters = highlighters + [self.selection_highlight] # selection highlight should be last
|
||||
|
||||
# draw hightlights first - some characters may overlap to the next line
|
||||
# by drawing the background hightlights first we prevent that the hightlight
|
||||
|
||||
@@ -119,11 +119,17 @@ class FilterWidget(QWidget):
|
||||
# print("cancel started ", time.time())
|
||||
self.filter_task.aborted = True
|
||||
|
||||
def reset_filter(self):
|
||||
self.filter_model.truncate()
|
||||
self.source_model.set_query_highlight()
|
||||
self.filter_model.set_query_highlight()
|
||||
self.source_model.settings.callback_update_ui()
|
||||
|
||||
def filter_changed(self):
|
||||
query = self.query_field.text()
|
||||
ignore_case = self.ignore_case.isChecked()
|
||||
if len(query) == 0:
|
||||
self.filter_model.truncate()
|
||||
self.reset_filter()
|
||||
return
|
||||
|
||||
# cancel previous search
|
||||
@@ -140,6 +146,9 @@ class FilterWidget(QWidget):
|
||||
self.filter_model.truncate()
|
||||
return
|
||||
|
||||
self.source_model.set_query_highlight(regex)
|
||||
self.filter_model.set_query_highlight(regex)
|
||||
|
||||
self.filter_task = FilterTask(
|
||||
self.source_model,
|
||||
self.filter_model,
|
||||
|
||||
@@ -14,7 +14,8 @@ import re
|
||||
|
||||
class HighlightRegex(Highlight):
|
||||
|
||||
def __init__(self, regex: str, brush: QBrush = QBrush(), pen: QPen = Qt.PenStyle.NoPen, brush_full_line=QBrush()):
|
||||
def __init__(self, regex: re.Pattern, brush: QBrush = QBrush(), pen: QPen = Qt.PenStyle.NoPen,
|
||||
brush_full_line=QBrush()):
|
||||
self.regex = regex
|
||||
self.brush = brush
|
||||
self.pen = pen
|
||||
@@ -26,10 +27,8 @@ class HighlightRegex(Highlight):
|
||||
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,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import math
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from PyQt6.QtGui import QBrush, QColor
|
||||
from PyQt6.QtGui import QBrush, QColor, QPen
|
||||
|
||||
from highlight_regex import HighlightRegex
|
||||
from line import Line
|
||||
@@ -12,6 +13,7 @@ from settings import Settings
|
||||
|
||||
|
||||
class LogFileModel:
|
||||
_query_highlight: Optional[HighlightRegex] = None
|
||||
|
||||
def __init__(self, file: str, settings: Settings):
|
||||
self.settings = settings
|
||||
@@ -20,8 +22,9 @@ class LogFileModel:
|
||||
|
||||
self.highlights = [
|
||||
HighlightRegex(
|
||||
r"ERROR",
|
||||
re.compile("ERROR"),
|
||||
brush=QBrush(QColor(220, 112, 122)),
|
||||
pen=QPen(QColor(0, 0, 0)),
|
||||
brush_full_line=QBrush(QColor(255, 112, 122))
|
||||
)
|
||||
]
|
||||
@@ -32,6 +35,18 @@ class LogFileModel:
|
||||
def __str__(self):
|
||||
return self._file
|
||||
|
||||
def get_query_highlight(self):
|
||||
return self._query_highlight
|
||||
|
||||
def set_query_highlight(self, regex: Optional[re.Pattern] = None):
|
||||
if regex:
|
||||
self._query_highlight = HighlightRegex(
|
||||
regex,
|
||||
brush=QBrush(QColor(255, 255, 0))
|
||||
)
|
||||
else:
|
||||
self._query_highlight = None
|
||||
|
||||
def get_tab_name(self):
|
||||
file_name = os.path.basename(self._file)
|
||||
if len(file_name) > 35:
|
||||
|
||||
Reference in New Issue
Block a user