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