Phoenix Logo

phoenix_title wx.FileSystemWatcher

The wx.FileSystemWatcher class allows to receive 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 wx.FileSystemWatcherEvent class. By default these events are sent to the 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 wx.FileSystemWatcher.SetOwner to send the events to another object. Or you could use 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.

New in version 2.9.1.

Note

Implementation limitations: this class is currently implemented for MSW, OS X 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 OS X neither accessing nor modifying is detected (only creating and deleting files is). Moreover, OS X version doesn’t currently collapse pairs of create/delete events in a rename event, unlike the other ones.


class_hierarchy Class Hierarchy

Inheritance diagram for class FileSystemWatcher:


method_summary Methods Summary

__init__ Default constructor.
Add Adds path to currently watched files.
AddTree This is the same as Add , but also recursively adds every file/directory in the tree rooted at path.
GetWatchedPaths Retrieves all watched paths and places them in paths.
GetWatchedPathsCount Returns the number of currently watched paths.
Remove Removes path from the list of watched paths.
RemoveAll Clears the list of currently watched paths.
RemoveTree This is the same as Remove , but also removes every file/directory belonging to the tree rooted at path.
SetOwner Associates the file system watcher with the given handler object.

property_summary Properties Summary

WatchedPathsCount See GetWatchedPathsCount

api Class API



class wx.FileSystemWatcher(EvtHandler)

Possible constructors:

FileSystemWatcher()

The FileSystemWatcher class allows to receive notifications of file system changes.


Methods



__init__(self)

Default constructor.



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 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 FileName.DontFollowLink on path.

Parameters:
  • path (string) – The name of the path to watch.
  • events (int) – An optional filter to receive only events of particular types. This is currently implemented only for GTK.
Return type:

bool



AddTree(self, path, events=FSW_EVENT_ALL, filter="")

This is the same as 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, but should be used with care on other platforms for directories with lots of children (e.g. the root directory) as it calls 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 FileName.DontFollowLink on path. This is especially important if the symlink targets may themselves be watched.

Parameters:
  • path (string) –
  • events (int) –
  • filter (string) –
Return type:

bool



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.

Parameters:paths (list of strings) –
Return type:int


GetWatchedPathsCount(self)

Returns the number of currently watched paths.

Return type:int

See also

GetWatchedPaths



Remove(self, path)

Removes path from the list of watched paths.

See the comment in Add about symbolic links. path should treat symbolic links in the same way as in the original Add call.

Parameters:path (string) –
Return type:bool


RemoveAll(self)

Clears the list of currently watched paths.

Return type:bool


RemoveTree(self, path)

This is the same as Remove , but also removes every file/directory belonging to the tree rooted at path.

See the comment in AddTree about symbolic links. path should treat symbolic links in the same way as in the original AddTree call.

Parameters:path (string) –
Return type:bool


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.

Parameters:handler (wx.EvtHandler) –

Properties



WatchedPathsCount

See GetWatchedPathsCount