1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
|
.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2020 by Total Control Software
License: wxWindows License
.. include:: headings.inc
.. _wx.FileSystemWatcher:
==========================================================================================================================================
|phoenix_title| **wx.FileSystemWatcher**
==========================================================================================================================================
The :ref:`wx.FileSystemWatcher` class allows receiving notifications of file system changes.
For the full list of change types that are reported see FSWFlags.
This class notifies the application about the file system changes by sending events of :ref:`wx.FileSystemWatcherEvent` class. By default these events are sent to the :ref:`wx.FileSystemWatcher` object itself so you can derive from it and use the event table ``EVT_FSWATCHER`` macro to handle these events in a derived class method. Alternatively, you can use :meth:`wx.FileSystemWatcher.SetOwner` to send the events to another object. Or you could use :meth:`wx.EvtHandler.Bind` with ``wxEVT_FSWATCHER`` to handle these events in any other object. See the fswatcher sample for an example of the latter approach.
.. versionadded:: 2.9.1
.. note::
Implementation limitations: this class is currently implemented for MSW, macOS and GTK ports but doesn't detect all changes correctly everywhere: under MSW accessing the file is not detected (only modifying it is) and under macOS neither accessing nor modifying is detected (only creating and deleting files is). Moreover, macOS version doesn't currently collapse pairs of create/delete events in a rename event, unlike the other ones.
.. note::
The application's event loop needs to be running before a :ref:`wx.FileSystemWatcher` can be properly created, and that is why one should not be created too early during application startup. If you intend to create a :ref:`wx.FileSystemWatcher` at startup, you can override :meth:`wx.AppConsole.OnEventLoopEnter` to ensure it is not done too early.
|
|class_hierarchy| Class Hierarchy
=================================
.. raw:: html
<div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
<img id="toggleBlock-trigger" src="_static/images/closed.png"/>
Inheritance diagram for class <strong>FileSystemWatcher</strong>:
</div>
<div id="toggleBlock-summary" style="display:block;"></div>
<div id="toggleBlock-content" style="display:none;">
<p class="graphviz">
<center><img src="_static/images/inheritance/wx.FileSystemWatcher_inheritance.png" alt="Inheritance diagram of FileSystemWatcher" usemap="#dummy" class="inheritance"/></center>
<script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
<map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.FileSystemWatcher.html" title="wx.FileSystemWatcher" alt="" coords="24,160,193,189"/> <area shape="rect" id="node2" href="wx.EvtHandler.html" title="wx.EvtHandler" alt="" coords="50,83,167,112"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="5,5,92,35"/> <area shape="rect" id="node4" href="wx.Trackable.html" title="wx.Trackable" alt="" coords="117,5,223,35"/> </map>
</p>
</div>
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.FileSystemWatcher.__init__` Default constructor.
:meth:`~wx.FileSystemWatcher.Add` Adds `path` to currently watched files.
:meth:`~wx.FileSystemWatcher.AddTree` This is the same as :meth:`~FileSystemWatcher.Add` , but also recursively adds every file/directory in the tree rooted at `path`.
:meth:`~wx.FileSystemWatcher.GetWatchedPaths` Retrieves all watched paths and places them in `paths`.
:meth:`~wx.FileSystemWatcher.GetWatchedPathsCount` Returns the number of currently watched paths.
:meth:`~wx.FileSystemWatcher.Remove` Removes `path` from the list of watched paths.
:meth:`~wx.FileSystemWatcher.RemoveAll` Clears the list of currently watched paths.
:meth:`~wx.FileSystemWatcher.RemoveTree` This is the same as :meth:`~FileSystemWatcher.Remove` , but also removes every file/directory belonging to the tree rooted at `path`.
:meth:`~wx.FileSystemWatcher.SetOwner` Associates the file system watcher with the given `handler` object.
================================================================================ ================================================================================
|
|property_summary| Properties Summary
=====================================
================================================================================ ================================================================================
:attr:`~wx.FileSystemWatcher.WatchedPathsCount` See :meth:`~wx.FileSystemWatcher.GetWatchedPathsCount`
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: wx.FileSystemWatcher(EvtHandler)
**Possible constructors**::
FileSystemWatcher()
The FileSystemWatcher class allows receiving notifications of file
system changes.
.. method:: __init__(self)
Default constructor.
.. method:: Add(self, path, events=FSW_EVENT_ALL)
Adds `path` to currently watched files.
The `path` argument can currently only be a directory and any changes to this directory itself or its immediate children will generate the events. Use :meth:`AddTree` to monitor the directory recursively.
Note that on platforms that use symbolic links, you should consider the possibility that `path` is a symlink. To watch the symlink itself and not its target you may call :meth:`FileName.DontFollowLink` on `path`.
:param `path`: The name of the path to watch.
:type `path`: string
:param `events`: An optional filter to receive only events of particular types. This is currently implemented only for GTK.
:type `events`: int
:rtype: `bool`
.. method:: AddTree(self, path, events=FSW_EVENT_ALL, filter=EmptyString)
This is the same as :meth:`Add` , but also recursively adds every file/directory in the tree rooted at `path`.
Additionally a file mask can be specified to include only files matching that particular mask.
This method is implemented efficiently on MSW and macOS, but should be used with care on other platforms for directories with lots of children (e.g. the root directory) as it calls :meth:`Add` for each subdirectory, potentially creating a lot of watches and taking a long time to execute.
Note that on platforms that use symbolic links, you will probably want to have called :meth:`FileName.DontFollowLink` on `path`. This is especially important if the symlink targets may themselves be watched.
:param `path`:
:type `path`: string
:param `events`:
:type `events`: int
:param `filter`:
:type `filter`: string
:rtype: `bool`
.. method:: GetWatchedPaths(self, paths)
Retrieves all watched paths and places them in `paths`.
Returns the number of watched paths, which is also the number of entries added to `paths`.
:param `paths`:
:type `paths`: list of strings
:rtype: `int`
.. method:: GetWatchedPathsCount(self)
Returns the number of currently watched paths.
:rtype: `int`
.. seealso:: :meth:`GetWatchedPaths`
.. method:: Remove(self, path)
Removes `path` from the list of watched paths.
See the comment in :meth:`Add` about symbolic links. `path` should treat symbolic links in the same way as in the original :meth:`Add` call.
:param `path`:
:type `path`: string
:rtype: `bool`
.. method:: RemoveAll(self)
Clears the list of currently watched paths.
:rtype: `bool`
.. method:: RemoveTree(self, path)
This is the same as :meth:`Remove` , but also removes every file/directory belonging to the tree rooted at `path`.
See the comment in :meth:`AddTree` about symbolic links. `path` should treat symbolic links in the same way as in the original :meth:`AddTree` call.
:param `path`:
:type `path`: string
:rtype: `bool`
.. method:: SetOwner(self, handler)
Associates the file system watcher with the given `handler` object.
All the events generated by this object will be passed to the specified owner.
:param `handler`:
:type `handler`: wx.EvtHandler
.. attribute:: WatchedPathsCount
See :meth:`~wx.FileSystemWatcher.GetWatchedPathsCount`
|