]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/FileDialog.py
better __docfilter__ and other epydoc tweaks
[wxWidgets.git] / wxPython / demo / FileDialog.py
CommitLineData
cf694132 1
8fa876ca
RD
2import os
3import wx
cf694132
RD
4
5#---------------------------------------------------------------------------
6
8fa876ca 7# This is how you pre-establish a file filter so that the dialog
95bfd958 8# only shows the extension(s) you want it to.
eb0f373c
RD
9wildcard = "Python source (*.py)|*.py|" \
10 "Compiled Python (*.pyc)|*.pyc|" \
11 "All files (*.*)|*.*"
12
cf694132 13def runTest(frame, nb, log):
1fded56b 14 log.WriteText("CWD: %s\n" % os.getcwd())
8fa876ca
RD
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.
1e4a197e 32 paths = dlg.GetPaths()
8fa876ca 33
1e4a197e 34 log.WriteText('You selected %d files:' % len(paths))
8fa876ca 35
1e4a197e
RD
36 for path in paths:
37 log.WriteText(' %s\n' % path)
8fa876ca
RD
38
39 # Compare this with the debug above; did we change working dirs?
1fded56b 40 log.WriteText("CWD: %s\n" % os.getcwd())
8fa876ca
RD
41
42 # Destroy the dialog. Don't do this until you are done with it!
43 # BAD things can happen otherwise!
cf694132
RD
44 dlg.Destroy()
45
46#---------------------------------------------------------------------------
47
48
1fded56b 49overview = """\
8fa876ca
RD
50This class provides the file selection dialog. It incorporates OS-native features
51depending on the OS in use, and can be used both for open and save operations.
52The files displayed can be filtered by setting up a wildcard filter, multiple files
53can be selected (open only), and files can be forced in a read-only mode.
54
55There are two ways to get the results back from the dialog. GetFiles() returns only
56the file names themselves, in a Python list. GetPaths() returns the full path and
57filenames combined as a Python list.
cf694132 58
1fded56b 59"""
cf694132
RD
60
61
1fded56b
RD
62if __name__ == '__main__':
63 import sys,os
64 import run
8eca4fef 65 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
cf694132 66