]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxFileDialog.py
1 # 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
9 #---------------------------------------------------------------------------
11 # This is how you pre-establish a file filter so that the dialog
12 # only shows the extention(s) you want it to.
13 wildcard
= "Python source (*.py)|*.py|" \
14 "Compiled Python (*.pyc)|*.pyc|" \
17 def runTest(frame
, nb
, log
):
18 log
.WriteText("CWD: %s\n" % os
.getcwd())
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.
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.
28 frame
, message
="Choose a file", defaultDir
=os
.getcwd(),
29 defaultFile
="", wildcard
=wildcard
, style
=wx
.OPEN | wx
.MULTIPLE | wx
.CHANGE_DIR
32 # Show the dialog and retrieve the user response. If it is the OK response,
34 if dlg
.ShowModal() == wx
.ID_OK
:
35 # This returns a Python list of files that were selected.
36 paths
= dlg
.GetPaths()
38 log
.WriteText('You selected %d files:' % len(paths
))
41 log
.WriteText(' %s\n' % path
)
43 # Compare this with the debug above; did we change working dirs?
44 log
.WriteText("CWD: %s\n" % os
.getcwd())
46 # Destroy the dialog. Don't do this until you are done with it!
47 # BAD things can happen otherwise!
50 #---------------------------------------------------------------------------
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.
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.
66 if __name__
== '__main__':
69 run
.main(['', os
.path
.basename(sys
.argv
[0])])