.. 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.Connect`   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`

