Problems with wx.DirDialog

John,

I don't know about your first question, but to determine if the user
grabbed an invalid directory, I would use the os module.

os.path.isdir(path)

Mike

···

-----Original Message-----
From: John Clark [mailto:john.clark@cabbage-rose.com]
Sent: Sunday, May 06, 2007 11:35 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Problems with wx.DirDialog

I am working through the wxPython In Action book's sample code and noticed
what I think is a bug about the wx.DirDialog class - I am using wxPython -
Unicode 2.8, ActiveState Python 2.5, and Windows XP SP2.

My code is as follows (based on Listing 9.7 from the book):

import wx

if ('__main__' == __name__):
    app = wx.PySimpleApp()
    dialog = wx.DirDialog(None,
                          'Choose a directory:',
                          style = wx.DD_DEFAULT_STYLE |
wx.DD_NEW_DIR_BUTTON)
    result = dialog.ShowModal()
    print result
    if (result == wx.ID_OK):
        print dialog.GetPath()
        
    dialog.Destroy()
    
What I have noticed is that when either dialog is displayed either with no
defaultPath value or with a valid defaultPath value, the dialog lists "My
Documents" in the dialog twice. The dialog tree (with no defaultPath
value
provided) has "My Computer" selected as the default choice and looks like:

  Desktop
  + My Documents
  + My Computer
  + My Documents

However, when an invalid defaultPath is provided (where the value
indicates a path that does not exist), then the dialog when displayed only
lists "My Documents" once - and the "My Documents" folder is selected as
the default choice.

Can someone verify this behavior and let me know if this should be
considered a bug in the implementation of the dialog.

The other thing that I noticed is that if the user selects an invalid
directory (such as "My Computer") and clicks OK, the dialog behaves as if
the user pressed "Cancel" - Is there a way to determine that the user
attempted to select a non-valid directory rather than simply canceling off
the dialog?

Thanks,
-John Clark