add regex highlight
This commit is contained in:
82
bigtext.py
82
bigtext.py
@@ -1,31 +1,43 @@
|
|||||||
import math
|
import math
|
||||||
from typing import Optional
|
import re
|
||||||
|
from typing import Optional, List
|
||||||
import PyQt6.QtGui
|
import PyQt6.QtGui
|
||||||
from PyQt6.QtCore import *
|
from PyQt6.QtCore import *
|
||||||
from PyQt6.QtGui import *
|
from PyQt6.QtGui import *
|
||||||
from PyQt6.QtWidgets import *
|
from PyQt6.QtWidgets import *
|
||||||
|
|
||||||
from highlight import Highlight
|
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 highlighted_range import HighlightedRange
|
||||||
from line import Line
|
from line import Line
|
||||||
from logFileModel import LogFileModel
|
from logFileModel import LogFileModel
|
||||||
|
import re
|
||||||
|
|
||||||
|
from settings import Settings
|
||||||
|
|
||||||
|
|
||||||
class BigText(QWidget):
|
class BigText(QWidget):
|
||||||
_byte_offset = 0
|
_byte_offset = 0
|
||||||
_left_offset = 0
|
_left_offset = 0
|
||||||
|
|
||||||
highlights : [Highlight] = []
|
highlights: [Highlight] = []
|
||||||
|
|
||||||
def __init__(self, model: LogFileModel):
|
def __init__(self, model: LogFileModel):
|
||||||
super(BigText, self).__init__()
|
super(BigText, self).__init__()
|
||||||
self.model = model
|
self.model = model
|
||||||
self.font = QFont("monospace", 20)
|
self.font = QFont("monospace", 12)
|
||||||
self.update_font_metrics(QPainter(self))
|
self.update_font_metrics(QPainter(self))
|
||||||
self.lines = []
|
self.lines = []
|
||||||
self.selection_highlight= HightlightSelection(0,0)
|
self.selection_highlight = HighlightSelection(0, 0)
|
||||||
self.highlights = [self.selection_highlight]
|
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:
|
def paintEvent(self, event: QPaintEvent) -> None:
|
||||||
self.draw()
|
self.draw()
|
||||||
@@ -43,7 +55,7 @@ class BigText(QWidget):
|
|||||||
if self.selection_highlight.end_byte != current_byte:
|
if self.selection_highlight.end_byte != current_byte:
|
||||||
self.selection_highlight.set_end_byte(current_byte)
|
self.selection_highlight.set_end_byte(current_byte)
|
||||||
self.update()
|
self.update()
|
||||||
#print("-> %s,%s" %(self._selection_start_byte, self._selection_end_byte))
|
# print("-> %s,%s" %(self._selection_start_byte, self._selection_end_byte))
|
||||||
|
|
||||||
def to_byte_offset(self, e: QMouseEvent) -> int:
|
def to_byte_offset(self, e: QMouseEvent) -> int:
|
||||||
line_number = int(e.pos().y() / self.char_height)
|
line_number = int(e.pos().y() / self.char_height)
|
||||||
@@ -52,10 +64,10 @@ class BigText(QWidget):
|
|||||||
line = self.lines[line_number]
|
line = self.lines[line_number]
|
||||||
char_in_line = round(e.pos().x() / self.char_width) + self._left_offset
|
char_in_line = round(e.pos().x() / self.char_width) + self._left_offset
|
||||||
char_in_line = min(char_in_line, line.length())
|
char_in_line = min(char_in_line, line.length())
|
||||||
#print("%s in line %s" % (char_in_line, line_number))
|
# print("%s in line %s" % (char_in_line, line_number))
|
||||||
|
|
||||||
current_byte = line.byte_offset() + char_in_line
|
current_byte = line.byte_offset() + char_in_line
|
||||||
#print("%s + %s = %s" % (line.byte_offset(), char_in_line, current_byte))
|
# print("%s + %s = %s" % (line.byte_offset(), char_in_line, current_byte))
|
||||||
else:
|
else:
|
||||||
current_byte = self.model.byte_count()
|
current_byte = self.model.byte_count()
|
||||||
return current_byte
|
return current_byte
|
||||||
@@ -75,12 +87,11 @@ class BigText(QWidget):
|
|||||||
# draws over a character
|
# draws over a character
|
||||||
y_line_offset = self.char_height;
|
y_line_offset = self.char_height;
|
||||||
for l in self.lines:
|
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:
|
for h in self.highlights:
|
||||||
optional_highlight_range = h.compute_highlight(l)
|
optional_highlight_range = h.compute_highlight(l)
|
||||||
if optional_highlight_range:
|
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 = y_line_offset + self.char_height
|
||||||
|
|
||||||
y_line_offset = self.char_height;
|
y_line_offset = self.char_height;
|
||||||
@@ -90,41 +101,26 @@ class BigText(QWidget):
|
|||||||
|
|
||||||
painter.end()
|
painter.end()
|
||||||
|
|
||||||
def draw_selection(self, painter: QPainter, line: Line, y_line_offset: int):
|
def draw_highlight(self, highlight: HighlightedRange, painter: QPainter, y_line_offset: int):
|
||||||
hightlight_color = QColor(255, 255, 0)
|
x1 = highlight.get_start() * self.char_width
|
||||||
|
width = highlight.get_width() * self.char_width
|
||||||
|
|
||||||
if line.includes_byte(self._selection_start_byte):
|
y1 = y_line_offset - self.char_height + self.char_height / 7
|
||||||
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
|
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):
|
if highlight.is_highlight_full_line():
|
||||||
x1 = highlight.get_start()*self.char_width
|
full_width = Settings.max_line_length() * self.char_width
|
||||||
width = highlight.get_width()*self.char_width
|
rect = QRect(0, y1, full_width, height)
|
||||||
|
self.highlight_background(painter, rect, highlight.get_brush_full_line())
|
||||||
|
|
||||||
y1 = y_line_offset- self.char_height + self.char_height / 7
|
rect = QRect(x1, y1, width, height)
|
||||||
height = self.char_height
|
self.highlight_background(painter, rect, highlight.get_brush())
|
||||||
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):
|
def highlight_background(self, painter: QPainter, rect: QRect, brush: QBrush):
|
||||||
old_brush = painter.brush()
|
old_brush = painter.brush()
|
||||||
old_pen = painter.pen()
|
old_pen = painter.pen()
|
||||||
painter.setBrush(brush)
|
painter.setBrush(brush)
|
||||||
painter.setPen(pen)
|
painter.setPen(Qt.PenStyle.NoPen)
|
||||||
painter.drawRoundedRect(rect, 3.0, 3.0)
|
painter.drawRoundedRect(rect, 3.0, 3.0)
|
||||||
painter.setBrush(old_brush)
|
painter.setBrush(old_brush)
|
||||||
painter.setPen(old_pen)
|
painter.setPen(old_pen)
|
||||||
@@ -132,8 +128,8 @@ class BigText(QWidget):
|
|||||||
def update_font_metrics(self, painter: QPainter):
|
def update_font_metrics(self, painter: QPainter):
|
||||||
fm: QFontMetrics = painter.fontMetrics()
|
fm: QFontMetrics = painter.fontMetrics()
|
||||||
self.char_height = fm.height()
|
self.char_height = fm.height()
|
||||||
self.char_width = fm.averageCharWidth()# all chars have same with for monospace font
|
self.char_width = fm.averageCharWidth() # all chars have same with for monospace font
|
||||||
text = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
text = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
||||||
self.char_width = fm.horizontalAdvance(text)/float(len(text))
|
self.char_width = fm.horizontalAdvance(text) / float(len(text))
|
||||||
#print("bounding rect: %s"%(boundingRect))
|
# print("bounding rect: %s"%(boundingRect))
|
||||||
#print("font width=%s height=%s" % (self.char_width, self.char_height))
|
# print("font width=%s height=%s" % (self.char_width, self.char_height))
|
||||||
|
|||||||
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: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: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
|
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 line import Line
|
||||||
from highlighted_range import HighlightedRange
|
from highlighted_range import HighlightedRange
|
||||||
@@ -8,5 +8,5 @@ class Highlight:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def compute_highlight(self, line: Line) -> Optional[HighlightedRange]:
|
def compute_highlight(self, line: Line) -> Optional[List[HighlightedRange]]:
|
||||||
return None
|
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 highlight import Highlight
|
||||||
from highlighted_range import HighlightedRange
|
from highlighted_range import HighlightedRange
|
||||||
@@ -10,7 +10,7 @@ from PyQt6.QtWidgets import *
|
|||||||
from settings import Settings
|
from settings import Settings
|
||||||
|
|
||||||
|
|
||||||
class HightlightSelection(Highlight):
|
class HighlightSelection(Highlight):
|
||||||
|
|
||||||
def __init__(self, start_byte: int, end_byte: int):
|
def __init__(self, start_byte: int, end_byte: int):
|
||||||
self.start_byte = start_byte
|
self.start_byte = start_byte
|
||||||
@@ -22,7 +22,7 @@ class HightlightSelection(Highlight):
|
|||||||
def set_end_byte(self, end_byte):
|
def set_end_byte(self, end_byte):
|
||||||
self.end_byte = 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)
|
begin = min(self.start_byte, self.end_byte)
|
||||||
end = max(self.start_byte, self.end_byte)
|
end = max(self.start_byte, self.end_byte)
|
||||||
|
|
||||||
@@ -37,6 +37,6 @@ class HightlightSelection(Highlight):
|
|||||||
else:
|
else:
|
||||||
length = Settings.max_line_length() -start
|
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:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -4,11 +4,24 @@ from PyQt6.QtWidgets import *
|
|||||||
|
|
||||||
|
|
||||||
class HighlightedRange:
|
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.start = start
|
||||||
self.width = width
|
self.width = width
|
||||||
self.brush = brush
|
self.brush = brush
|
||||||
self.pen = pen
|
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):
|
def get_start(self):
|
||||||
return self.start
|
return self.start
|
||||||
@@ -21,3 +34,6 @@ class HighlightedRange:
|
|||||||
|
|
||||||
def get_pen(self):
|
def get_pen(self):
|
||||||
return self.pen
|
return self.pen
|
||||||
|
|
||||||
|
def get_brush_full_line(self):
|
||||||
|
return self.brush_full_line
|
||||||
|
|||||||
Reference in New Issue
Block a user