1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import os
|
|
|
|
import wx
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# This is how you pre-establish a file filter so that the dialog
|
2004-01-12 22:17:17 -05:00
|
|
|
# only shows the extension(s) you want it to.
|
2002-08-13 19:59:08 -04:00
|
|
|
wildcard = "Python source (*.py)|*.py|" \
|
|
|
|
"Compiled Python (*.pyc)|*.pyc|" \
|
|
|
|
"All files (*.*)|*.*"
|
|
|
|
|
1999-04-29 23:29:54 -04:00
|
|
|
def runTest(frame, nb, log):
|
2003-07-02 19:13:10 -04:00
|
|
|
log.WriteText("CWD: %s\n" % os.getcwd())
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
# Create the dialog. In this case the current directory is forced as the starting
|
|
|
|
# directory for the dialog, and no default file name is forced. This can easilly
|
|
|
|
# be changed in your program. This is an 'open' dialog, and allows multitple
|
|
|
|
# file selection to boot.
|
|
|
|
#
|
|
|
|
# Finally, of the directory is changed in the process of getting files, this
|
|
|
|
# dialog is set up to change the current working directory to the path chosen.
|
|
|
|
dlg = wx.FileDialog(
|
|
|
|
frame, message="Choose a file", defaultDir=os.getcwd(),
|
|
|
|
defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
|
|
|
|
)
|
|
|
|
|
|
|
|
# Show the dialog and retrieve the user response. If it is the OK response,
|
|
|
|
# process the data.
|
|
|
|
if dlg.ShowModal() == wx.ID_OK:
|
|
|
|
# This returns a Python list of files that were selected.
|
2003-03-25 01:35:27 -05:00
|
|
|
paths = dlg.GetPaths()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
log.WriteText('You selected %d files:' % len(paths))
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
for path in paths:
|
|
|
|
log.WriteText(' %s\n' % path)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
# Compare this with the debug above; did we change working dirs?
|
2003-07-02 19:13:10 -04:00
|
|
|
log.WriteText("CWD: %s\n" % os.getcwd())
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
# Destroy the dialog. Don't do this until you are done with it!
|
|
|
|
# BAD things can happen otherwise!
|
1999-04-29 23:29:54 -04:00
|
|
|
dlg.Destroy()
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
overview = """\
|
2003-12-08 20:23:28 -05:00
|
|
|
This class provides the file selection dialog. It incorporates OS-native features
|
|
|
|
depending on the OS in use, and can be used both for open and save operations.
|
|
|
|
The files displayed can be filtered by setting up a wildcard filter, multiple files
|
|
|
|
can be selected (open only), and files can be forced in a read-only mode.
|
|
|
|
|
|
|
|
There are two ways to get the results back from the dialog. GetFiles() returns only
|
|
|
|
the file names themselves, in a Python list. GetPaths() returns the full path and
|
|
|
|
filenames combined as a Python list.
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
"""
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|
1999-04-29 23:29:54 -04:00
|
|
|
|