eric6/WebBrowser/Tools/DelayedFileWatcher.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8218
7c09585bd960
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4763
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
8ad353f31184 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
6 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
7 Module implementing a file system watcher with a delay.
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
8 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
9
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
10 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QFileSystemWatcher, QTimer
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
11
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
12
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
13 class DelayedFileWatcher(QFileSystemWatcher):
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
14 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
15 Class implementing a file system watcher with a delay.
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
16
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
17 @signal delayedDirectoryChanged(path) emitted to indicate a changed
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
18 directory
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
19 @signal delayedFileChanged(path) emitted to indicate a changed file
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
20 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
21 delayedDirectoryChanged = pyqtSignal(str)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
22 delayedFileChanged = pyqtSignal(str)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
23
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
24 def __init__(self, paths=None, parent=None):
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
25 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
26 Constructor
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
27
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
28 @param paths list of paths to be watched
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
29 @type list of str
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
30 @param parent reference to the parent object
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
31 @type QObject
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
32 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
33 if paths:
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
34 super(DelayedFileWatcher, self).__init__(paths, parent)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
35 else:
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
36 super(DelayedFileWatcher, self).__init__(parent)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
37
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
38 self.__dirQueue = []
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
39 self.__fileQueue = []
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
40
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
41 self.directoryChanged.connect(self.__directoryChanged)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
42 self.fileChanged.connect(self.__fileChanged)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
43
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
44 @pyqtSlot(str)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
45 def __directoryChanged(self, path):
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
46 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
47 Private slot handling a changed directory.
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
48
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
49 @param path name of the changed directory
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
50 @type str
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
51 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
52 self.__dirQueue.append(path)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
53 QTimer.singleShot(500, self.__dequeueDirectory)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
54
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
55 @pyqtSlot(str)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
56 def __fileChanged(self, path):
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
57 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
58 Private slot handling a changed file.
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
59
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
60 @param path name of the changed file
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
61 @type str
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
62 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
63 self.__fileQueue.append(path)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
64 QTimer.singleShot(500, self.__dequeueFile)
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
65
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
66 @pyqtSlot()
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
67 def __dequeueDirectory(self):
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
68 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
69 Private slot to signal a directory change.
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
70 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
71 self.delayedDirectoryChanged.emit(self.__dirQueue.pop(0))
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
72
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
73 @pyqtSlot()
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
74 def __dequeueFile(self):
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
75 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
76 Private slot to signal a file change.
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
77 """
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4763
diff changeset
78 self.delayedFileChanged.emit(self.__fileQueue.pop(0))

eric ide

mercurial