11 |
11 |
12 |
12 |
13 class DelayedFileWatcher(QFileSystemWatcher): |
13 class DelayedFileWatcher(QFileSystemWatcher): |
14 """ |
14 """ |
15 Class implementing a file system watcher with a delay. |
15 Class implementing a file system watcher with a delay. |
16 |
16 |
17 @signal delayedDirectoryChanged(path) emitted to indicate a changed |
17 @signal delayedDirectoryChanged(path) emitted to indicate a changed |
18 directory |
18 directory |
19 @signal delayedFileChanged(path) emitted to indicate a changed file |
19 @signal delayedFileChanged(path) emitted to indicate a changed file |
20 """ |
20 """ |
|
21 |
21 delayedDirectoryChanged = pyqtSignal(str) |
22 delayedDirectoryChanged = pyqtSignal(str) |
22 delayedFileChanged = pyqtSignal(str) |
23 delayedFileChanged = pyqtSignal(str) |
23 |
24 |
24 def __init__(self, paths=None, parent=None): |
25 def __init__(self, paths=None, parent=None): |
25 """ |
26 """ |
26 Constructor |
27 Constructor |
27 |
28 |
28 @param paths list of paths to be watched |
29 @param paths list of paths to be watched |
29 @type list of str |
30 @type list of str |
30 @param parent reference to the parent object |
31 @param parent reference to the parent object |
31 @type QObject |
32 @type QObject |
32 """ |
33 """ |
33 if paths: |
34 if paths: |
34 super().__init__(paths, parent) |
35 super().__init__(paths, parent) |
35 else: |
36 else: |
36 super().__init__(parent) |
37 super().__init__(parent) |
37 |
38 |
38 self.__dirQueue = [] |
39 self.__dirQueue = [] |
39 self.__fileQueue = [] |
40 self.__fileQueue = [] |
40 |
41 |
41 self.directoryChanged.connect(self.__directoryChanged) |
42 self.directoryChanged.connect(self.__directoryChanged) |
42 self.fileChanged.connect(self.__fileChanged) |
43 self.fileChanged.connect(self.__fileChanged) |
43 |
44 |
44 @pyqtSlot(str) |
45 @pyqtSlot(str) |
45 def __directoryChanged(self, path): |
46 def __directoryChanged(self, path): |
46 """ |
47 """ |
47 Private slot handling a changed directory. |
48 Private slot handling a changed directory. |
48 |
49 |
49 @param path name of the changed directory |
50 @param path name of the changed directory |
50 @type str |
51 @type str |
51 """ |
52 """ |
52 self.__dirQueue.append(path) |
53 self.__dirQueue.append(path) |
53 QTimer.singleShot(500, self.__dequeueDirectory) |
54 QTimer.singleShot(500, self.__dequeueDirectory) |
54 |
55 |
55 @pyqtSlot(str) |
56 @pyqtSlot(str) |
56 def __fileChanged(self, path): |
57 def __fileChanged(self, path): |
57 """ |
58 """ |
58 Private slot handling a changed file. |
59 Private slot handling a changed file. |
59 |
60 |
60 @param path name of the changed file |
61 @param path name of the changed file |
61 @type str |
62 @type str |
62 """ |
63 """ |
63 self.__fileQueue.append(path) |
64 self.__fileQueue.append(path) |
64 QTimer.singleShot(500, self.__dequeueFile) |
65 QTimer.singleShot(500, self.__dequeueFile) |
65 |
66 |
66 @pyqtSlot() |
67 @pyqtSlot() |
67 def __dequeueDirectory(self): |
68 def __dequeueDirectory(self): |
68 """ |
69 """ |
69 Private slot to signal a directory change. |
70 Private slot to signal a directory change. |
70 """ |
71 """ |
71 self.delayedDirectoryChanged.emit(self.__dirQueue.pop(0)) |
72 self.delayedDirectoryChanged.emit(self.__dirQueue.pop(0)) |
72 |
73 |
73 @pyqtSlot() |
74 @pyqtSlot() |
74 def __dequeueFile(self): |
75 def __dequeueFile(self): |
75 """ |
76 """ |
76 Private slot to signal a file change. |
77 Private slot to signal a file change. |
77 """ |
78 """ |