First of all, wxPython is just awesome. Many thanks to the developers and the community. Loving it so much.
I’m writing an IDE using a custom terminal emulator for the editor panels (this way people can use Emacs / Vim / whatever with all their features), and writing a custom 3D OpenGL graph / tree viewer to replace the standard file / directory tree display. (https://github.com/avose/GLShell)
So, I want to be able to detect when files are added / removed so that I can update the 3D graph of all the files / dirs. However, it seems like I’m only getting events for file accesses. I’m sure I’m just using it wrong, but not seeing the issue yet. Any help would be appreciated.
When I do an “ls” in the watched directory, I see the access print. When I open a file, I see the access print. However, when I “touch foo” or “rm foo”, I don’t see any prints for that.
https://docs.wxpython.org/wx.FileSystemWatcher.html
https://docs.wxpython.org/wx.FileSystemWatcherEvent.html
https://docs.wxpython.org/wx.FSWFlags.enumeration.html
The code that’s doing this follows:
class glsDirTree(glsFSObj, wx.FileSystemWatcher):
def __init__(self, path, settings):
path = os.path.abspath(path)
glsFSObj.__init__(self, path)
wx.FileSystemWatcher.__init__(self)
self.settings = settings
self.files = []
self.dirs = []
self.graph = fdpGraph(self.settings)
for root, dirs, files in os.walk(self.path):
root_node = glsDir(root)
for name in files:
node = glsFile(os.path.join(root, name))
self.files.append(node)
self.graph.add_node(node)
self.graph.add_edge( (root_node,node) )
for name in dirs:
node = glsDir(os.path.join(root, name))
self.dirs.append(node)
self.graph.add_node(node)
self.graph.add_edge( (root_node,node) )
self.thread = glsFDPThread(self.settings, self.graph, speed=0.01)
self.Bind(wx.EVT_FSWATCHER, self.OnFSChange)
self.thread.start()
self.AddTree(self.path)
return
def OnFSChange(self, event):
change_type = event.GetChangeType()
if change_type == wx.FSW_EVENT_CREATE:
print('create')
elif change_type == wx.FSW_EVENT_DELETE:
print('delete')
elif change_type == wx.FSW_EVENT_WARNING:
print('warn')
elif change_type == wx.FSW_EVENT_ERROR:
print('error')
elif change_type == wx.FSW_EVENT_ACCESS:
print('access')
else:
print(change_type)
return
wxPython 4.2.1
Python 3.10.12