diff --git a/src/ui/bigtext/bigtext.py b/src/ui/bigtext/bigtext.py index fcb4e8a..eee90d5 100644 --- a/src/ui/bigtext/bigtext.py +++ b/src/ui/bigtext/bigtext.py @@ -1,3 +1,4 @@ +import logging import math import os import time @@ -26,20 +27,31 @@ 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 - time.sleep(0.5) - self.big_text.trigger_update.emit() + 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):