make it possible to disable highlighters
This commit is contained in:
@@ -12,7 +12,8 @@ import re
|
|||||||
class HighlightRegex(Highlight):
|
class HighlightRegex(Highlight):
|
||||||
|
|
||||||
def __init__(self, query: str, ignore_case: bool, is_regex: bool, hit_background_color: str = "None",
|
def __init__(self, query: str, ignore_case: bool, is_regex: bool, hit_background_color: str = "None",
|
||||||
line_background_color: str = "None"):
|
line_background_color: str = "None", active: bool = True):
|
||||||
|
self.active = active
|
||||||
self.query = query
|
self.query = query
|
||||||
self.ignore_case = ignore_case
|
self.ignore_case = ignore_case
|
||||||
self.is_regex = is_regex
|
self.is_regex = is_regex
|
||||||
@@ -29,6 +30,12 @@ class HighlightRegex(Highlight):
|
|||||||
else:
|
else:
|
||||||
return re.compile(re.escape(self.query), flags=flags)
|
return re.compile(re.escape(self.query), flags=flags)
|
||||||
|
|
||||||
|
def is_active(self) -> bool:
|
||||||
|
return self.active
|
||||||
|
|
||||||
|
def set_active(self, active: bool):
|
||||||
|
self.active = active
|
||||||
|
|
||||||
def set_query(self, query: str) -> None:
|
def set_query(self, query: str) -> None:
|
||||||
self.query = query
|
self.query = query
|
||||||
self.regex = self._get_regex()
|
self.regex = self._get_regex()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class Highlighting:
|
|||||||
if not section.startswith("highlighting."):
|
if not section.startswith("highlighting."):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
active = session.getboolean(section, "active", fallback=True)
|
||||||
query = session.get(section, "query", fallback="")
|
query = session.get(section, "query", fallback="")
|
||||||
if len(query) == 0:
|
if len(query) == 0:
|
||||||
continue
|
continue
|
||||||
@@ -31,7 +32,8 @@ class Highlighting:
|
|||||||
ignore_case=ignore_case,
|
ignore_case=ignore_case,
|
||||||
is_regex=is_regex,
|
is_regex=is_regex,
|
||||||
hit_background_color=hit_background_color,
|
hit_background_color=hit_background_color,
|
||||||
line_background_color=line_background_color
|
line_background_color=line_background_color,
|
||||||
|
active=active
|
||||||
)
|
)
|
||||||
result.append(highlight)
|
result.append(highlight)
|
||||||
except:
|
except:
|
||||||
@@ -49,6 +51,7 @@ class Highlighting:
|
|||||||
section = "highlighting.%d" % section_counter
|
section = "highlighting.%d" % section_counter
|
||||||
section_counter = section_counter + 1
|
section_counter = section_counter + 1
|
||||||
settings.session.add_section(section)
|
settings.session.add_section(section)
|
||||||
|
settings.session.set(section, "active", str(highlighter.active))
|
||||||
settings.session.set(section, "query", highlighter.query)
|
settings.session.set(section, "query", highlighter.query)
|
||||||
settings.session.set(section, "ignore-case", str(highlighter.ignore_case))
|
settings.session.set(section, "ignore-case", str(highlighter.ignore_case))
|
||||||
settings.session.set(section, "is-regex", str(highlighter.is_regex))
|
settings.session.set(section, "is-regex", str(highlighter.is_regex))
|
||||||
|
|||||||
@@ -26,7 +26,12 @@ class LogFileModel:
|
|||||||
self._file = os.path.realpath(file)
|
self._file = os.path.realpath(file)
|
||||||
|
|
||||||
def highlighters(self):
|
def highlighters(self):
|
||||||
return Highlighting.read_config(self.settings)
|
all_highlighters = Highlighting.read_config(self.settings)
|
||||||
|
active_highlighters = []
|
||||||
|
for h in all_highlighters:
|
||||||
|
if h.is_active():
|
||||||
|
active_highlighters.append(h)
|
||||||
|
return active_highlighters
|
||||||
|
|
||||||
def get_file(self):
|
def get_file(self):
|
||||||
return self._file
|
return self._file
|
||||||
|
|||||||
@@ -133,35 +133,57 @@ class HighlightListItemWidget(QWidget):
|
|||||||
super(HighlightListItemWidget, self).__init__()
|
super(HighlightListItemWidget, self).__init__()
|
||||||
self.highlight_regex = highlight_regex
|
self.highlight_regex = highlight_regex
|
||||||
self.layout = QGridLayout(self)
|
self.layout = QGridLayout(self)
|
||||||
|
self.layout.setColumnStretch(4, 1)
|
||||||
|
|
||||||
row = 0
|
row = 0
|
||||||
|
self.active = QCheckBox("")
|
||||||
|
self.active.setChecked(highlight_regex.is_active())
|
||||||
|
self.active.stateChanged.connect(self._change_active_state)
|
||||||
|
self.layout.addWidget(self.active, row, 0, 3, 1, alignment=QtCore.Qt.AlignmentFlag.AlignVCenter)
|
||||||
|
|
||||||
query = QLineEdit(self)
|
query = QLineEdit(self)
|
||||||
query.setText(highlight_regex.query)
|
query.setText(highlight_regex.query)
|
||||||
query.textChanged[str].connect(lambda: highlight_regex.set_query(query.text()))
|
query.textChanged[str].connect(lambda: highlight_regex.set_query(query.text()))
|
||||||
self.layout.addWidget(query, row, 0, 1, 3)
|
query.setEnabled(highlight_regex.is_active())
|
||||||
|
self.layout.addWidget(query, row, 1, 1, 4)
|
||||||
|
|
||||||
row = row + 1
|
row = row + 1
|
||||||
self.layout.addWidget(QLabel(_("Hit Background:")), row, 0)
|
hit_background_label = QLabel(_("Hit Background:"))
|
||||||
|
hit_background_label.setEnabled(highlight_regex.is_active())
|
||||||
|
self.layout.addWidget(hit_background_label, row, 1)
|
||||||
hit_background_color = ColorButton(highlight_regex.hit_background_color)
|
hit_background_color = ColorButton(highlight_regex.hit_background_color)
|
||||||
hit_background_color.setToolTip(_("Hit Background"))
|
hit_background_color.setToolTip(_("Hit Background"))
|
||||||
|
hit_background_color.setEnabled(highlight_regex.is_active())
|
||||||
hit_background_color.color_drop_down.currentIndexChanged.connect(
|
hit_background_color.color_drop_down.currentIndexChanged.connect(
|
||||||
lambda: highlight_regex.set_hit_background_color(hit_background_color.color))
|
lambda: highlight_regex.set_hit_background_color(hit_background_color.color))
|
||||||
self.layout.addWidget(hit_background_color, row, 1)
|
self.layout.addWidget(hit_background_color, row, 2)
|
||||||
|
|
||||||
ignore_case = QCheckBox(_("Ignore Case"))
|
ignore_case = QCheckBox(_("Ignore Case"))
|
||||||
ignore_case.setChecked(highlight_regex.ignore_case)
|
ignore_case.setChecked(highlight_regex.ignore_case)
|
||||||
ignore_case.stateChanged.connect(lambda: highlight_regex.set_is_ignore_case(ignore_case.isChecked()))
|
ignore_case.stateChanged.connect(lambda: highlight_regex.set_is_ignore_case(ignore_case.isChecked()))
|
||||||
self.layout.addWidget(ignore_case, row, 2)
|
ignore_case.setEnabled(highlight_regex.is_active())
|
||||||
|
self.layout.addWidget(ignore_case, row, 3)
|
||||||
|
|
||||||
row = row + 1
|
row = row + 1
|
||||||
self.layout.addWidget(QLabel(_("Line Background:")), row, 0)
|
line_background_label = QLabel(_("Line Background:"))
|
||||||
|
line_background_label.setEnabled(highlight_regex.is_active())
|
||||||
|
self.layout.addWidget(line_background_label, row, 1)
|
||||||
line_background_color = ColorButton(highlight_regex.line_background_color)
|
line_background_color = ColorButton(highlight_regex.line_background_color)
|
||||||
line_background_color.setToolTip(_("Line Background"))
|
line_background_color.setToolTip(_("Line Background"))
|
||||||
line_background_color.color_drop_down.currentIndexChanged.connect(
|
line_background_color.color_drop_down.currentIndexChanged.connect(
|
||||||
lambda: highlight_regex.set_line_background_color(line_background_color.color))
|
lambda: highlight_regex.set_line_background_color(line_background_color.color))
|
||||||
self.layout.addWidget(line_background_color, row, 1)
|
line_background_color.setEnabled(highlight_regex.is_active())
|
||||||
|
self.layout.addWidget(line_background_color, row, 2)
|
||||||
|
|
||||||
is_regex = QCheckBox(_("Regular Expression"))
|
is_regex = QCheckBox(_("Regular Expression"))
|
||||||
is_regex.setChecked(highlight_regex.is_regex)
|
is_regex.setChecked(highlight_regex.is_regex)
|
||||||
is_regex.stateChanged.connect(lambda: highlight_regex.set_is_regex(is_regex.isChecked()))
|
is_regex.stateChanged.connect(lambda: highlight_regex.set_is_regex(is_regex.isChecked()))
|
||||||
self.layout.addWidget(is_regex, row, 2)
|
is_regex.setEnabled(highlight_regex.is_active())
|
||||||
|
self.layout.addWidget(is_regex, row, 3)
|
||||||
|
|
||||||
|
def _change_active_state(self):
|
||||||
|
active = self.active.isChecked()
|
||||||
|
self.highlight_regex.set_active(active)
|
||||||
|
for child in self.children():
|
||||||
|
if child is not self.active:
|
||||||
|
child.setEnabled(active)
|
||||||
|
|||||||
Reference in New Issue
Block a user