import wx
import os.path, sys

class FooApp (wx.App):
	def OnInit(self):
		print wx.version()
		self._bar = BarFrame(None, -1, 'fswatcher')
		self._bar.Show(True)
		return True
		
	def OnEventLoopEnter(self, loop):
		self._bar.CreateWatcher()	# Needs an event loop to be created, see fswatcher.cpp
		
class BarFrame (wx.Frame):
	def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name=wx.FrameNameStr):
		wx.Frame.__init__(self, parent, id, title, pos, size, style, name)
		self._watcher = None
		
	def CreateWatcher(self):
		if self._watcher:
			return
		self._watcher = wx.FileSystemWatcher()
		self._watcher.Bind(wx.EVT_FSWATCHER, self.OnFSEvent)
		
		# We'll just monitor the directory of the script
		cwd = os.path.dirname(sys.argv[0])
		
		self._watcher.Add(cwd)
		
	def OnFSEvent(self, event):
		print 'OnFSEvent'
		print type(event), '\n'
		#print event.GetChangeType()	# Can't access this, because event is not a wx.FileSystemWatcherEvent type
		
if __name__ == '__main__':
	app = FooApp()
	app.MainLoop()