link result view and source view
This commit is contained in:
@@ -22,6 +22,7 @@ class FilterTask(QRunnable):
|
||||
filter_model: LogFileModel,
|
||||
regex: re.Pattern,
|
||||
lock: threading.RLock,
|
||||
filter_match_found_listeners: Callable[[int], None],
|
||||
on_before: Callable[[], None],
|
||||
on_finish: Callable[[], None]
|
||||
):
|
||||
@@ -32,14 +33,19 @@ class FilterTask(QRunnable):
|
||||
self.on_before = on_before
|
||||
self.on_finish = on_finish
|
||||
self.lock = lock
|
||||
self.filter_match_found_listeners = filter_match_found_listeners
|
||||
|
||||
def run(self):
|
||||
# print("writing to tmp file", self.filter_model.get_file())
|
||||
|
||||
# the lock ensures that we only start a new search when the previous search already ended
|
||||
with self.lock:
|
||||
#print("starting thread ", threading.currentThread())
|
||||
# print("starting thread ", threading.currentThread())
|
||||
self.on_before()
|
||||
|
||||
for listener in self.filter_match_found_listeners:
|
||||
listener(-1, -1) # notify listeners that a new search started
|
||||
|
||||
try:
|
||||
with open(self.source_model.get_file(), "rb") as source:
|
||||
with open(self.filter_model.get_file(), "w+b") as target:
|
||||
@@ -50,9 +56,13 @@ class FilterTask(QRunnable):
|
||||
line = l.decode("utf8", errors="ignore")
|
||||
|
||||
if self.regex.findall(line):
|
||||
#time.sleep(0.5)
|
||||
lines_written = lines_written +1
|
||||
target.write(line.encode("utf8"))
|
||||
# time.sleep(0.5)
|
||||
lines_written = lines_written + 1
|
||||
source_line_offset = source.tell() - len(l)
|
||||
target_line_offset = target.tell()
|
||||
for listener in self.filter_match_found_listeners:
|
||||
listener(target_line_offset, source_line_offset)
|
||||
target.write(l)
|
||||
|
||||
# sometime buffering can hide results for a while
|
||||
# We force a flush periodically.
|
||||
@@ -112,6 +122,14 @@ class FilterWidget(QWidget):
|
||||
self.layout.addWidget(filter_bar)
|
||||
self.layout.addWidget(self.hits_view)
|
||||
|
||||
self.filter_match_found_listeners: [Callable[[int], None]] = []
|
||||
|
||||
def add_line_click_listener(self, listener: Callable[[int], None]):
|
||||
self.hits_view.add_line_click_listener(listener)
|
||||
|
||||
def add_filter_match_found_listener(self, listener: Callable[[int], None]):
|
||||
self.filter_match_found_listeners.append(listener)
|
||||
|
||||
def destruct(self):
|
||||
# print("cleanup: ", self.tmpfilename)
|
||||
os.remove(self.tmpfilename)
|
||||
@@ -157,6 +175,7 @@ class FilterWidget(QWidget):
|
||||
self.filter_model,
|
||||
regex,
|
||||
self._lock,
|
||||
self.filter_match_found_listeners,
|
||||
lambda: self.btn_cancel_search.setVisible(True),
|
||||
lambda: self.btn_cancel_search.setVisible(False)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user