]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
cf694132 | 5 | |
8fa876ca RD |
6 | import os |
7 | import wx | |
cf694132 RD |
8 | |
9 | #--------------------------------------------------------------------------- | |
10 | ||
8fa876ca RD |
11 | # This is how you pre-establish a file filter so that the dialog |
12 | # only shows the extention(s) you want it to. | |
eb0f373c RD |
13 | wildcard = "Python source (*.py)|*.py|" \ |
14 | "Compiled Python (*.pyc)|*.pyc|" \ | |
15 | "All files (*.*)|*.*" | |
16 | ||
cf694132 | 17 | def runTest(frame, nb, log): |
1fded56b | 18 | log.WriteText("CWD: %s\n" % os.getcwd()) |
8fa876ca RD |
19 | |
20 | # Create the dialog. In this case the current directory is forced as the starting | |
21 | # directory for the dialog, and no default file name is forced. This can easilly | |
22 | # be changed in your program. This is an 'open' dialog, and allows multitple | |
23 | # file selection to boot. | |
24 | # | |
25 | # Finally, of the directory is changed in the process of getting files, this | |
26 | # dialog is set up to change the current working directory to the path chosen. | |
27 | dlg = wx.FileDialog( | |
28 | frame, message="Choose a file", defaultDir=os.getcwd(), | |
29 | defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR | |
30 | ) | |
31 | ||
32 | # Show the dialog and retrieve the user response. If it is the OK response, | |
33 | # process the data. | |
34 | if dlg.ShowModal() == wx.ID_OK: | |
35 | # This returns a Python list of files that were selected. | |
1e4a197e | 36 | paths = dlg.GetPaths() |
8fa876ca | 37 | |
1e4a197e | 38 | log.WriteText('You selected %d files:' % len(paths)) |
8fa876ca | 39 | |
1e4a197e RD |
40 | for path in paths: |
41 | log.WriteText(' %s\n' % path) | |
8fa876ca RD |
42 | |
43 | # Compare this with the debug above; did we change working dirs? | |
1fded56b | 44 | log.WriteText("CWD: %s\n" % os.getcwd()) |
8fa876ca RD |
45 | |
46 | # Destroy the dialog. Don't do this until you are done with it! | |
47 | # BAD things can happen otherwise! | |
cf694132 RD |
48 | dlg.Destroy() |
49 | ||
50 | #--------------------------------------------------------------------------- | |
51 | ||
52 | ||
1fded56b | 53 | overview = """\ |
8fa876ca RD |
54 | This class provides the file selection dialog. It incorporates OS-native features |
55 | depending on the OS in use, and can be used both for open and save operations. | |
56 | The files displayed can be filtered by setting up a wildcard filter, multiple files | |
57 | can be selected (open only), and files can be forced in a read-only mode. | |
58 | ||
59 | There are two ways to get the results back from the dialog. GetFiles() returns only | |
60 | the file names themselves, in a Python list. GetPaths() returns the full path and | |
61 | filenames combined as a Python list. | |
cf694132 | 62 | |
1fded56b | 63 | """ |
cf694132 RD |
64 | |
65 | ||
1fded56b RD |
66 | if __name__ == '__main__': |
67 | import sys,os | |
68 | import run | |
69 | run.main(['', os.path.basename(sys.argv[0])]) | |
cf694132 | 70 |