Default directory in wx.FileDialog, using Windows7

378 views
Skip to first unread message

Raphael Mayoraz

unread,
Sep 2, 2010, 5:34:10 AM9/2/10
to wxPytho...@googlegroups.com
Hello,

I'm having a problem with the default directory of a wx.FileDialog when
being on Windows7.
Let's say you are in a directory C:\myDir that has a sub-directory 'mySub'.
I run the dialog using os.getcwd() as the default directory argument.
The first time is open the dialog, I'm proprely in C:\myDir. Now, in the
dialog, I go to C:\myDir\mySub and select a file there.
Quit the application, run it again from C:\myDir, open the file dialog
again, the default directory is now C:\myDir\mySub, even though
os.getcwd() is passed as the directory argument (and os.getcwd()
properly returns C:\myDir). It looks like the last visited directory is
'recorded' in the Windows7 file dialog and there is no way to overwrite it.

I also tried to use dlg.SetDirectory(os.getcwd()) without success.

Thanks.

Raphael


Mike Driscoll

unread,
Sep 2, 2010, 9:17:51 AM9/2/10
to wxPython-users
Hi,
If you print out os.getcwd(), does it return what you expect?
Personally, I use a class attribute to store my last path. In the
init, I do something like this:

self.currentPath = r'C:\myDir'

Then in the FileDialog, I would reset it as necessary when the user
pressed the dialog's OK button:

self.currentPath = dlg.GetPath()

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Raphael Mayoraz

unread,
Sep 2, 2010, 9:27:03 AM9/2/10
to wxpytho...@googlegroups.com
Well, os.getcwd() remains the same even after the dialog is closed. In
my example, it returns

'C:\myDir'


all the time, even if the file dialog is opened in

'C:\myDir\mySub'


It looks like keeping track of the last visited directory from an
application is recorded in the application registry and the directory
argument of the wx.FileDialog constructor cannot overwrite it.

Raphael

Robin Dunn

unread,
Sep 2, 2010, 2:13:59 PM9/2/10
to wxpytho...@googlegroups.com

What style flags are you passing to wx.FileDialog?

--
Robin Dunn
Software Craftsman
http://wxPython.org

Mike Driscoll

unread,
Sep 2, 2010, 3:02:00 PM9/2/10
to wxPython-users
As I recall, os.getcwd() gets it path from the location that the
script is running from. If you need to change it, then call
os.chdir(dlg.GetPath())

- Mike

Raphael Mayoraz

unread,
Sep 6, 2010, 11:26:28 AM9/6/10
to wxpytho...@googlegroups.com
I'm using wx.OPEN. As you pointing to style flags, I just tried
wx.FD_OPEN and wx.FD_CHANGE_DIR (both together), but this didn't make
SetDirectory() work either.

Raphael

Robin Dunn

unread,
Sep 6, 2010, 6:38:58 PM9/6/10
to wxpytho...@googlegroups.com

Ok, create a ticket for it with the component set to wxMSW.

Reply all
Reply to author
Forward
0 new messages