add regex highlight
This commit is contained in:
62
bigtext.py
62
bigtext.py
@@ -1,15 +1,20 @@
|
||||
import math
|
||||
from typing import Optional
|
||||
import re
|
||||
from typing import Optional, List
|
||||
import PyQt6.QtGui
|
||||
from PyQt6.QtCore import *
|
||||
from PyQt6.QtGui import *
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from highlight import Highlight
|
||||
from highlight_selection import HightlightSelection
|
||||
from highlight_regex import HighlightRegex
|
||||
from highlight_selection import HighlightSelection
|
||||
from highlighted_range import HighlightedRange
|
||||
from line import Line
|
||||
from logFileModel import LogFileModel
|
||||
import re
|
||||
|
||||
from settings import Settings
|
||||
|
||||
|
||||
class BigText(QWidget):
|
||||
@@ -21,11 +26,18 @@ class BigText(QWidget):
|
||||
def __init__(self, model: LogFileModel):
|
||||
super(BigText, self).__init__()
|
||||
self.model = model
|
||||
self.font = QFont("monospace", 20)
|
||||
self.font = QFont("monospace", 12)
|
||||
self.update_font_metrics(QPainter(self))
|
||||
self.lines = []
|
||||
self.selection_highlight= HightlightSelection(0,0)
|
||||
self.highlights = [self.selection_highlight]
|
||||
self.selection_highlight = HighlightSelection(0, 0)
|
||||
self.highlights = [
|
||||
HighlightRegex(
|
||||
r"INFO",
|
||||
brush=QBrush(QColor(220, 112, 122)),
|
||||
brush_full_line=QBrush(QColor(255, 112, 122))
|
||||
),
|
||||
self.selection_highlight,
|
||||
]
|
||||
|
||||
def paintEvent(self, event: QPaintEvent) -> None:
|
||||
self.draw()
|
||||
@@ -75,12 +87,11 @@ class BigText(QWidget):
|
||||
# draws over a character
|
||||
y_line_offset = self.char_height;
|
||||
for l in self.lines:
|
||||
#if l.intersects(self._selection_start_byte, self._selection_end_byte):
|
||||
# self.draw_selection(painter, l, y_line_offset)
|
||||
for h in self.highlights:
|
||||
optional_highlight_range = h.compute_highlight(l)
|
||||
if optional_highlight_range:
|
||||
self.draw_highlight(optional_highlight_range, painter, y_line_offset)
|
||||
for highlight in optional_highlight_range:
|
||||
self.draw_highlight(highlight, painter, y_line_offset)
|
||||
y_line_offset = y_line_offset + self.char_height
|
||||
|
||||
y_line_offset = self.char_height;
|
||||
@@ -90,41 +101,26 @@ class BigText(QWidget):
|
||||
|
||||
painter.end()
|
||||
|
||||
def draw_selection(self, painter: QPainter, line: Line, y_line_offset: int):
|
||||
hightlight_color = QColor(255, 255, 0)
|
||||
|
||||
if line.includes_byte(self._selection_start_byte):
|
||||
x1 = (self._selection_start_byte - line.byte_offset() - self._left_offset) * self.char_width
|
||||
else:
|
||||
x1 = 0
|
||||
|
||||
if line.includes_byte(self._selection_end_byte):
|
||||
width = (self._selection_end_byte - line.byte_offset() - self._left_offset) * self.char_width - x1
|
||||
#print("char in line: %d -> width: %d" % (self._selection_end_byte - line.byte_offset() - self._left_offset, width))
|
||||
else:
|
||||
width = len(line.line().rstrip()) * self.char_width -x1
|
||||
|
||||
y1 = y_line_offset- self.char_height + self.char_height / 7
|
||||
height = self.char_height
|
||||
rect = QRect(x1,y1,width,height)
|
||||
#print(rect)
|
||||
self.hightlight(painter,rect , hightlight_color)
|
||||
|
||||
def draw_highlight(self, highlight: HighlightedRange, painter: QPainter, y_line_offset: int):
|
||||
x1 = highlight.get_start() * self.char_width
|
||||
width = highlight.get_width() * self.char_width
|
||||
|
||||
y1 = y_line_offset - self.char_height + self.char_height / 7
|
||||
height = self.char_height
|
||||
rect = QRect(x1,y1,width,height)
|
||||
#print(rect)
|
||||
self.hightlight(painter,rect , highlight.get_brush(), highlight.get_pen())
|
||||
|
||||
def hightlight(self, painter: QPainter,rect: QRect, brush: QBrush, pen:QPen):
|
||||
if highlight.is_highlight_full_line():
|
||||
full_width = Settings.max_line_length() * self.char_width
|
||||
rect = QRect(0, y1, full_width, height)
|
||||
self.highlight_background(painter, rect, highlight.get_brush_full_line())
|
||||
|
||||
rect = QRect(x1, y1, width, height)
|
||||
self.highlight_background(painter, rect, highlight.get_brush())
|
||||
|
||||
def highlight_background(self, painter: QPainter, rect: QRect, brush: QBrush):
|
||||
old_brush = painter.brush()
|
||||
old_pen = painter.pen()
|
||||
painter.setBrush(brush)
|
||||
painter.setPen(pen)
|
||||
painter.setPen(Qt.PenStyle.NoPen)
|
||||
painter.drawRoundedRect(rect, 3.0, 3.0)
|
||||
painter.setBrush(old_brush)
|
||||
painter.setPen(old_pen)
|
||||
|
||||
10
example.log
10
example.log
@@ -9,6 +9,16 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
|
||||
...............................|
|
||||
|
|
||||
äääääääääääääääääääääääääääääää|
|
||||
2019-08-07 00:00:10,391 [catalina-exec-40] INFO c.r.c.u.l.PerformancePointcut - Executed HealthCheckController.checkOperativeness in 1 ms successful. [jv3fw7r2.m1u5]
|
||||
2019-08-07 00:00:16,377 [catalina-exec-56] INFO c.r.c.u.l.PerformancePointcut - Executed HealthCheckController.checkOperativeness in 1 ms successful. [jv3fw7r2.m1u6]
|
||||
2019-08-07 00:00:40,403 [catalina-exec-26] INFO c.r.c.u.l.PerformancePointcut - Executed HealthCheckController.checkOperativeness in 1 ms successful. [jv3fw7r2.m1ud]
|
||||
2019-08-07 00:02:10,598 [catalina-exec-16] INFO c.r.c.u.l.PerformancePointcut - Executed SecurityController.loginIndex in 0 ms successful. [jv3fw7r2.m1uf]
|
||||
2019-08-07 00:02:16,467 [catalina-exec-36] INFO c.r.c.u.l.PerformancePointcut - Executed HealthCheckController.checkOperativeness in 1 ms successful. [jv3fw7r2.m1ug]
|
||||
2019-08-07 00:02:23,519 [catalina-exec-53] INFO c.r.c.u.l.PerformancePointcut - Executed AuthenticationProvider.authenticate in 224 ms successful. [jv3fw7r2.m1uh]
|
||||
2019-08-07 00:02:24,195 [catalina-exec-43] INFO c.r.c.u.l.PerformancePointcut - Executed SecurityController.accessDenied in 0 ms successful. [jv3fw7r2.m1uj]
|
||||
2019-08-07 00:02:24,937 [catalina-exec-74] INFO c.r.c.u.l.PerformancePointcut - Executed RedirectController.redirect in 1159 ms successful. [jv3fw7r2.m1ui]
|
||||
2019-08-07 00:02:25,674 [catalina-exec-29] INFO c.r.c.u.l.PerformancePointcut - Executed AssignmentsController.index in 683 ms successful. [jv3fw7r2.m1uk]
|
||||
2019-08-07 00:02:26,825 [catalina-exec-20] INFO c.r.c.u.l.PerformancePointcut - Executed I18NController.getI18NKeyValues in 1 ms successful. [jv3fw7r2.m1ul]
|
||||
2018-09-06T00:00:16.381Z,0,vapfacbk01,HealthCheckService.isOperable,AXC_5.14_526,,successful
|
||||
2018-09-06T00:00:18.096Z,0,vapfacbk01,HealthCheckService.isOperable,AXC_5.14_526,,successful
|
||||
2018-09-06T00:00:27.114Z,64,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Optional
|
||||
from typing import Optional, List
|
||||
|
||||
from line import Line
|
||||
from highlighted_range import HighlightedRange
|
||||
@@ -8,5 +8,5 @@ class Highlight:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def compute_highlight(self, line: Line) -> Optional[HighlightedRange]:
|
||||
def compute_highlight(self, line: Line) -> Optional[List[HighlightedRange]]:
|
||||
return None
|
||||
|
||||
42
highlight_regex.py
Normal file
42
highlight_regex.py
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Optional
|
||||
from typing import Optional, List
|
||||
|
||||
from highlight import Highlight
|
||||
from highlighted_range import HighlightedRange
|
||||
@@ -10,7 +10,7 @@ from PyQt6.QtWidgets import *
|
||||
from settings import Settings
|
||||
|
||||
|
||||
class HightlightSelection(Highlight):
|
||||
class HighlightSelection(Highlight):
|
||||
|
||||
def __init__(self, start_byte: int, end_byte: int):
|
||||
self.start_byte = start_byte
|
||||
@@ -22,7 +22,7 @@ class HightlightSelection(Highlight):
|
||||
def set_end_byte(self, end_byte):
|
||||
self.end_byte = end_byte
|
||||
|
||||
def compute_highlight(self, line: Line) -> Optional[HighlightedRange]:
|
||||
def compute_highlight(self, line: Line) -> Optional[List[HighlightedRange]]:
|
||||
begin = min(self.start_byte, self.end_byte)
|
||||
end = max(self.start_byte, self.end_byte)
|
||||
|
||||
@@ -37,6 +37,6 @@ class HightlightSelection(Highlight):
|
||||
else:
|
||||
length = Settings.max_line_length() -start
|
||||
|
||||
return HighlightedRange(start, length, QBrush(QColor(255, 255, 0)), Qt.PenStyle.NoPen)
|
||||
return [HighlightedRange(start, length, brush=QBrush(QColor(255, 255, 0)), pen=Qt.PenStyle.NoPen)]
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -4,11 +4,24 @@ from PyQt6.QtWidgets import *
|
||||
|
||||
|
||||
class HighlightedRange:
|
||||
def __init__(self, start: int, width: int, brush: QBrush = QBrush(), pen: QPen = Qt.PenStyle.NoPen):
|
||||
def __init__(
|
||||
self,
|
||||
start: int,
|
||||
width: int,
|
||||
highlight_full_line=False,
|
||||
brush: QBrush = QBrush(),
|
||||
pen: QPen = Qt.PenStyle.NoPen,
|
||||
brush_full_line: QBrush = QBrush()
|
||||
):
|
||||
self.start = start
|
||||
self.width = width
|
||||
self.brush = brush
|
||||
self.pen = pen
|
||||
self.highlight_full_line = highlight_full_line
|
||||
self.brush_full_line = brush_full_line
|
||||
|
||||
def is_highlight_full_line(self):
|
||||
return self.highlight_full_line
|
||||
|
||||
def get_start(self):
|
||||
return self.start
|
||||
@@ -21,3 +34,6 @@ class HighlightedRange:
|
||||
|
||||
def get_pen(self):
|
||||
return self.pen
|
||||
|
||||
def get_brush_full_line(self):
|
||||
return self.brush_full_line
|
||||
|
||||
Reference in New Issue
Block a user