add time diff plugin
This commit is contained in:
@@ -8,13 +8,17 @@ from typing import Optional, Callable
|
||||
from PySide6.QtCore import QRunnable, QThreadPool, Signal
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QCheckBox, QPushButton, QComboBox, \
|
||||
QSizePolicy, QProgressBar
|
||||
QSizePolicy, QProgressBar, QMenu, QMenuBar
|
||||
|
||||
from src.plugins.domain.raction import RAction
|
||||
from src.plugins.logfile.preprocesslineshook import PreProcessLinesHook
|
||||
from src.ui.bigtext.bigtext import BigText
|
||||
from src.ui.bigtext.logFileModel import LogFileModel
|
||||
|
||||
from src.i18n import _
|
||||
from src.pluginregistry import PluginRegistry
|
||||
from src.ui.hbox import HBox
|
||||
from src.zonedpluginregistry import ZonedPluginRegistry
|
||||
|
||||
|
||||
class FilterTask(QRunnable):
|
||||
@@ -27,6 +31,7 @@ class FilterTask(QRunnable):
|
||||
regex: re.Pattern,
|
||||
lock: threading.RLock,
|
||||
filter_match_found_listeners: Callable[[int], None],
|
||||
pre_process_lines_hooks: [PreProcessLinesHook],
|
||||
progress_handler: Callable[[float], None],
|
||||
on_before: Callable[[], None],
|
||||
on_finish: Callable[[], None]
|
||||
@@ -36,6 +41,7 @@ class FilterTask(QRunnable):
|
||||
self.filter_model = filter_model
|
||||
self.regex = regex
|
||||
self.progress_handler = progress_handler
|
||||
self.pre_process_lines_hooks = pre_process_lines_hooks
|
||||
self.on_before = on_before
|
||||
self.on_finish = on_finish
|
||||
self.lock = lock
|
||||
@@ -71,7 +77,12 @@ class FilterTask(QRunnable):
|
||||
target_line_offset = target.tell()
|
||||
for listener in self.filter_match_found_listeners:
|
||||
listener(target_line_offset, source_line_offset)
|
||||
target.write(l)
|
||||
|
||||
for hook in self.pre_process_lines_hooks:
|
||||
h: PreProcessLinesHook = hook
|
||||
line = h.pre_process_line(line, target)
|
||||
|
||||
target.write(line.encode("utf8"))
|
||||
|
||||
# sometime buffering can hide results for a while
|
||||
# We force a flush periodically.
|
||||
@@ -100,9 +111,10 @@ class FilterWidget(QWidget):
|
||||
search_is_running = Signal(bool)
|
||||
signal_update_progress = Signal(float)
|
||||
|
||||
def __init__(self, source_model: LogFileModel):
|
||||
def __init__(self, source_model: LogFileModel, zoned_plugin_registry: ZonedPluginRegistry):
|
||||
super(FilterWidget, self).__init__()
|
||||
self.source_model = source_model
|
||||
self._zoned_plugin_registry = zoned_plugin_registry
|
||||
|
||||
self._lock = threading.RLock()
|
||||
|
||||
@@ -131,6 +143,8 @@ class FilterWidget(QWidget):
|
||||
self.btn_bookmark.setToolTip(_("save query"))
|
||||
self.btn_bookmark.pressed.connect(self._save_query)
|
||||
|
||||
self.menu = self._create_stuff_menu()
|
||||
|
||||
self.ignore_case = QCheckBox(_("ignore case"))
|
||||
self.ignore_case.setChecked(True)
|
||||
self.ignore_case.stateChanged.connect(self.filter_changed)
|
||||
@@ -146,6 +160,7 @@ class FilterWidget(QWidget):
|
||||
filter_bar.layout.addWidget(self.progress_bar)
|
||||
filter_bar.layout.addWidget(self.btn_cancel_search)
|
||||
filter_bar.layout.addWidget(self.btn_bookmark)
|
||||
filter_bar.layout.addWidget(self.menu)
|
||||
filter_bar.layout.addWidget(self.ignore_case)
|
||||
filter_bar.layout.addWidget(self.is_regex)
|
||||
|
||||
@@ -162,6 +177,16 @@ class FilterWidget(QWidget):
|
||||
def on_reveal(self):
|
||||
self._reload_save_queries()
|
||||
|
||||
def _create_stuff_menu(self):
|
||||
menu = HBox()
|
||||
actions = self._zoned_plugin_registry.execute_flat_map("get_filter_widget_actions")
|
||||
|
||||
for action in actions:
|
||||
raction: RAction = action;
|
||||
button = raction.to_qpushbutton(menu)
|
||||
menu.addWidget(button)
|
||||
return menu
|
||||
|
||||
def _reload_save_queries(self):
|
||||
saved_queries = PluginRegistry.execute_single("saved_queries")
|
||||
for saved_query in saved_queries:
|
||||
@@ -238,12 +263,15 @@ class FilterWidget(QWidget):
|
||||
self.source_model.set_query_highlight(query, ignore_case, is_regex)
|
||||
self.filter_model.set_query_highlight(query, ignore_case, is_regex)
|
||||
|
||||
pre_process_lines_hooks = self._zoned_plugin_registry.execute_remove_falsy("get_pre_process_lines_hook")
|
||||
|
||||
self.filter_task = FilterTask(
|
||||
self.source_model,
|
||||
self.filter_model,
|
||||
regex,
|
||||
self._lock,
|
||||
self.filter_match_found_listeners,
|
||||
pre_process_lines_hooks,
|
||||
self.progress_handler,
|
||||
lambda: self.search_is_running.emit(True),
|
||||
lambda: self.search_is_running.emit(False)
|
||||
|
||||
@@ -7,15 +7,17 @@ from src.plugins.logfile.filterwidget import FilterWidget
|
||||
from src.ui.bigtext.logFileModel import LogFileModel
|
||||
from src.plugins.krowlog.Tab import Tab
|
||||
from src.util.conversion import humanbytes
|
||||
from src.zonedpluginregistry import ZonedPluginRegistry
|
||||
|
||||
|
||||
class FullTabWidget(Tab):
|
||||
|
||||
def __init__(self, model: LogFileModel, unique_id: str, title: str):
|
||||
def __init__(self, model: LogFileModel, unique_id: str, title: str, zoned_plugin_registry: ZonedPluginRegistry):
|
||||
super(FullTabWidget, self).__init__(unique_id, title)
|
||||
self._model = model
|
||||
self._zoned_plugin_registry = zoned_plugin_registry
|
||||
self.file_view = BigText(model)
|
||||
self.filter_hit_view = FilterWidget(self._model)
|
||||
self.filter_hit_view = FilterWidget(self._model, self._zoned_plugin_registry)
|
||||
self.filter_view_syncer = FilterViewSyncer(self.file_view)
|
||||
self.filter_hit_view.add_line_click_listener(self.filter_view_syncer.click_listener)
|
||||
self.filter_hit_view.add_filter_match_found_listener(self.filter_view_syncer.match_found)
|
||||
|
||||
11
src/plugins/logfile/preprocesslineshook.py
Normal file
11
src/plugins/logfile/preprocesslineshook.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from abc import abstractmethod
|
||||
from typing import List, BinaryIO
|
||||
|
||||
from src.ui.bigtext.line import Line
|
||||
|
||||
|
||||
class PreProcessLinesHook:
|
||||
|
||||
@abstractmethod
|
||||
def pre_process_line(self, line: str, file_io: BinaryIO) -> str:
|
||||
return line
|
||||
Reference in New Issue
Block a user