skip update of big text if file was not modified
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
@@ -26,20 +27,31 @@ from watchdog.observers import Observer
|
|||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
from src.i18n import _
|
from src.i18n import _
|
||||||
|
|
||||||
|
log = logging.getLogger("bigtext")
|
||||||
|
|
||||||
class FileObserver(FileSystemEventHandler):
|
class FileObserver(FileSystemEventHandler):
|
||||||
|
|
||||||
def __init__(self, big_text):
|
def __init__(self, big_text):
|
||||||
super(FileObserver, self).__init__()
|
super(FileObserver, self).__init__()
|
||||||
self.big_text = big_text
|
self.big_text = big_text
|
||||||
|
self._last_mtime = -1
|
||||||
|
|
||||||
def on_modified(self, event):
|
def on_modified(self, event):
|
||||||
# slow down the updates. This is needed, because the file is modified
|
# slow down the updates. This is needed, because the file is modified
|
||||||
# constantly, which would lead to constant re-rendering, which would
|
# constantly, which would lead to constant re-rendering, which would
|
||||||
# block the UI thread and make the UI unresponsive.
|
# block the UI thread and make the UI unresponsive.
|
||||||
# Note: we don't miss events, because they are queued and de-duplicated
|
# 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)
|
time.sleep(0.5)
|
||||||
self.big_text.trigger_update.emit()
|
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):
|
class FileWatchdogThread(QRunnable):
|
||||||
|
|||||||
Reference in New Issue
Block a user