]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxFileDialog.py
New wxDesigner-less version of the MimeTypesManager demo
[wxWidgets.git] / wxPython / demo / wxFileDialog.py
1 # 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2 #
3 # o Updated for wx namespace
4 #
5
6 import os
7 import wx
8
9 #---------------------------------------------------------------------------
10
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|" \
15 "All files (*.*)|*.*"
16
17 def runTest(frame, nb, log):
18 log.WriteText("CWD: %s\n" % os.getcwd())
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.
36 paths = dlg.GetPaths()
37
38 log.WriteText('You selected %d files:' % len(paths))
39
40 for path in paths:
41 log.WriteText(' %s\n' % path)
42
43 # Compare this with the debug above; did we change working dirs?
44 log.WriteText("CWD: %s\n" % os.getcwd())
45
46 # Destroy the dialog. Don't do this until you are done with it!
47 # BAD things can happen otherwise!
48 dlg.Destroy()
49
50 #---------------------------------------------------------------------------
51
52
53 overview = """\
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.
62
63 """
64
65
66 if __name__ == '__main__':
67 import sys,os
68 import run
69 run.main(['', os.path.basename(sys.argv[0])])
70