148 @signal fileCreated(path: str) emitted when a file is created |
148 @signal fileCreated(path: str) emitted when a file is created |
149 @signal fileDeleted(path: str) emitted when a file is removed from disk |
149 @signal fileDeleted(path: str) emitted when a file is removed from disk |
150 @signal fileModified(path: str) emitted when a file is modified |
150 @signal fileModified(path: str) emitted when a file is modified |
151 @signal fileMoved(srcPath: str, dstPath: str) emitted when the file at a |
151 @signal fileMoved(srcPath: str, dstPath: str) emitted when the file at a |
152 given source path is renamed or moved to destination path |
152 given source path is renamed or moved to destination path |
|
153 @signal error(errno: int, errmsg: str) emitted to indicate an OS error |
153 """ |
154 """ |
154 |
155 |
155 directoryChanged = pyqtSignal(str) # compatibility with QFileSystemWatcher |
156 directoryChanged = pyqtSignal(str) # compatibility with QFileSystemWatcher |
156 directoryCreated = pyqtSignal(str) |
157 directoryCreated = pyqtSignal(str) |
157 directoryDeleted = pyqtSignal(str) |
158 directoryDeleted = pyqtSignal(str) |
161 fileChanged = pyqtSignal(str) # compatibility with QFileSystemWatcher |
162 fileChanged = pyqtSignal(str) # compatibility with QFileSystemWatcher |
162 fileCreated = pyqtSignal(str) |
163 fileCreated = pyqtSignal(str) |
163 fileDeleted = pyqtSignal(str) |
164 fileDeleted = pyqtSignal(str) |
164 fileModified = pyqtSignal(str) |
165 fileModified = pyqtSignal(str) |
165 fileMoved = pyqtSignal(str, str) |
166 fileMoved = pyqtSignal(str, str) |
|
167 |
|
168 error = pyqtSignal(int, str) |
166 |
169 |
167 def __init__(self, parent=None): |
170 def __init__(self, parent=None): |
168 """ |
171 """ |
169 Constructor |
172 Constructor |
170 |
173 |
249 if os.path.exists(path): |
252 if os.path.exists(path): |
250 try: |
253 try: |
251 self.__paths[path][1] += 1 |
254 self.__paths[path][1] += 1 |
252 return True |
255 return True |
253 except KeyError: |
256 except KeyError: |
254 watch = self.__observer.schedule( |
257 try: |
255 self.__eventHandler, |
258 watch = self.__observer.schedule( |
256 path, |
259 self.__eventHandler, |
257 recursive=recursive and os.path.isdir(path), |
260 path, |
258 ) |
261 recursive=recursive and os.path.isdir(path), |
259 if watch is not None: |
262 ) |
260 self.__paths[watch.path] = [watch, 1] |
263 if watch is not None: |
261 return True |
264 self.__paths[watch.path] = [watch, 1] |
|
265 return True |
|
266 except OSError as err: |
|
267 self.error.emit(err.errno, err.strerror) |
262 |
268 |
263 return False |
269 return False |
264 |
270 |
265 def addPaths(self, paths, recursive=False): |
271 def addPaths(self, paths, recursive=False): |
266 """ |
272 """ |