]> git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/fs_test.py
New moddef file
[wxWidgets.git] / wxPython / tests / fs_test.py
1
2
3 from wxPython.wx import *
4 import glob
5
6 class File2(wxFileSystemHandler):
7
8 def CanOpen(self,location):
9 return self.GetProtocol(location) == "file2"
10
11 def OpenFile(self,fs,location):
12 return wxFSFile(wxInputStream(open(self.GetRightLocation(location),"rb")),
13 location,"text/plain","",wxDateTime())
14
15 def FindFirst(self,location,flags):
16 # the flags are ignored
17 self.files = glob.glob(self.GetRightLocation(location))
18 if len(self.files) == 0:
19 return ""
20 else:
21 return self.files[0]
22
23 def FindNext(self):
24 self.files = self.files[1:]
25 if len(self.files) == 0:
26 return ""
27 else:
28 return self.files[0]
29
30 # register new handler
31 wxFileSystem_AddHandler(File2())
32 fs = wxFileSystem()
33
34 # cat /etc/passwd
35 print fs.OpenFile("file2:/projects/files.lst").GetStream().read()
36
37 # ls /etc/*
38 fn = fs.FindFirst("file2:/projects/*")
39 while fn:
40 print fn
41 fn = fs.FindNext()