replace watchdog with active polling thread
watchdog does not work on windows. For some reason file modification events are not emitted. Fixed by replacing watchdog with a thread that polls the modification date ever 0.5s. Also fixed a bug that the hit view was not properly destructed.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import textwrap
|
||||
|
||||
import PySide6
|
||||
from watchdog import version as watchdog_version
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtGui import QFont, QPalette
|
||||
from PySide6.QtWidgets import *
|
||||
@@ -75,11 +74,9 @@ class AboutDialog(QDialog):
|
||||
<ul>
|
||||
<li>PySide6-Essentials {pyside} (LGPL v3) - <a href="https://doc.qt.io/qtforpython-6/">https://doc.qt.io/qtforpython-6/</a></li>
|
||||
<li>Qt6 {qt} (LGPL v3) - <a href="https://code.qt.io/cgit/qt/qtbase.git/">https://code.qt.io/cgit/qt/qtbase.git/</a></li>
|
||||
<li>watchdog {watchdog} (Apache 2.0) - <a href="https://github.com/gorakhargosh/watchdog">https://github.com/gorakhargosh/watchdog</a></li>
|
||||
</ul>""".format(
|
||||
pyside=PySide6.__version__,
|
||||
qt=PySide6.QtCore.__version__,
|
||||
watchdog=watchdog_version.VERSION_STRING)
|
||||
qt=PySide6.QtCore.__version__)
|
||||
label = textwrap.dedent(dependencies)
|
||||
|
||||
result = QWidget()
|
||||
|
||||
@@ -279,6 +279,7 @@ class FilterWidget(QWidget):
|
||||
|
||||
def destruct(self):
|
||||
self._cancel_search()
|
||||
self.hits_view.destruct()
|
||||
os.remove(self.tmp_filename)
|
||||
|
||||
def _cancel_search(self):
|
||||
|
||||
@@ -23,55 +23,31 @@ from src.ui.icon import Icon
|
||||
from src.ui.rangeslider import RangeSlider
|
||||
from src.util.conversion import humanbytes
|
||||
from src.pluginregistry import PluginRegistry
|
||||
from threading import Event
|
||||
|
||||
from src.settings.settings import Settings
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
from src.i18n import _
|
||||
|
||||
log = logging.getLogger("bigtext")
|
||||
|
||||
|
||||
class FileObserver(FileSystemEventHandler):
|
||||
|
||||
def __init__(self, big_text):
|
||||
super(FileObserver, self).__init__()
|
||||
self.big_text = big_text
|
||||
self._last_mtime = -1
|
||||
|
||||
def on_modified(self, event):
|
||||
# slow down the updates. This is needed, because the file is modified
|
||||
# constantly, which would lead to constant re-rendering, which would
|
||||
# block the UI thread and make the UI unresponsive.
|
||||
# Note: we don't miss events, because they are queued and de-duplicated
|
||||
if not event.is_directory:
|
||||
try:
|
||||
mtime = os.stat(event.src_path).st_mtime
|
||||
if mtime != self._last_mtime:
|
||||
self._last_mtime = mtime
|
||||
time.sleep(0.5)
|
||||
self.big_text.trigger_update.emit()
|
||||
except FileNotFoundError:
|
||||
# ignore: happens when closing the application, because tmp files are deleted,
|
||||
# which triggers a modification event
|
||||
pass
|
||||
|
||||
|
||||
class FileWatchdogThread(QRunnable):
|
||||
|
||||
def __init__(self, big_text, file: str):
|
||||
super(FileWatchdogThread, self).__init__()
|
||||
self.file = file
|
||||
self.big_text = big_text
|
||||
self.observer = Observer()
|
||||
self.stop = Event()
|
||||
|
||||
def run(self) -> None:
|
||||
self.observer.schedule(FileObserver(self.big_text), self.file)
|
||||
self.observer.start()
|
||||
_last_mtime = None
|
||||
while not self.stop.is_set():
|
||||
mtime = os.stat(self.file).st_mtime
|
||||
if mtime != _last_mtime:
|
||||
_last_mtime = mtime
|
||||
self.big_text.trigger_update.emit()
|
||||
self.stop.wait(0.5)
|
||||
|
||||
def destruct(self):
|
||||
self.observer.stop()
|
||||
# self.observer.join(1)
|
||||
self.stop.set()
|
||||
|
||||
|
||||
class BigText(QWidget):
|
||||
|
||||
Reference in New Issue
Block a user