- dlg = wxFileDialog(frame, "Choose a file", ".", "", "*.*", wxOPEN|wxMULTIPLE)
- if dlg.ShowModal() == wxID_OK:
- for path in dlg.GetPaths():
- log.WriteText('You selected: %s\n' % path)
+ log.WriteText("CWD: %s\n" % os.getcwd())
+
+ # 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.
+ paths = dlg.GetPaths()
+
+ log.WriteText('You selected %d files:' % len(paths))
+
+ for path in paths:
+ log.WriteText(' %s\n' % path)
+
+ # Compare this with the debug above; did we change working dirs?
+ log.WriteText("CWD: %s\n" % os.getcwd())
+
+ # Destroy the dialog. Don't do this until you are done with it!
+ # BAD things can happen otherwise!