]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FileDialog.py
   5 #--------------------------------------------------------------------------- 
   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|" \
 
  13 def runTest(frame
, nb
, log
): 
  14     log
.WriteText("CWD: %s\n" % os
.getcwd()) 
  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. 
  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. 
  24         frame
, message
="Choose a file", defaultDir
=os
.getcwd(),  
  25         defaultFile
="", wildcard
=wildcard
, style
=wx
.OPEN | wx
.MULTIPLE | wx
.CHANGE_DIR
 
  28     # Show the dialog and retrieve the user response. If it is the OK response,  
  30     if dlg
.ShowModal() == wx
.ID_OK
: 
  31         # This returns a Python list of files that were selected. 
  32         paths 
= dlg
.GetPaths() 
  34         log
.WriteText('You selected %d files:' % len(paths
)) 
  37             log
.WriteText('           %s\n' % path
) 
  39     # Compare this with the debug above; did we change working dirs? 
  40     log
.WriteText("CWD: %s\n" % os
.getcwd()) 
  42     # Destroy the dialog. Don't do this until you are done with it! 
  43     # BAD things can happen otherwise! 
  46 #--------------------------------------------------------------------------- 
  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. 
  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. 
  62 if __name__ 
== '__main__': 
  65     run
.main(['', os
.path
.basename(sys
.argv
[0])])