DirDialog always creates dir if non-existent

27 views
Skip to first unread message

schnepper

unread,
Sep 6, 2017, 4:30:02 PM9/6/17
to wxPython-users
When I use a DirDialog, a new directory is created if the user enters a non-existent name in the Location field.  I'd like to validate the name with app specific criteria and create the directory myself if desired.  This behavior occurs whether or not I specify wx.DD_DEFAULT_STYLE.  Is this correct behavior for this class?  Is there any way I can override it?  Is there a different widget I can use?

I am using python-wxgtk3.0 on Ubuntu 16.4.

Thank you.
Mark

James Scholes

unread,
Sep 6, 2017, 4:47:34 PM9/6/17
to wxpytho...@googlegroups.com
schnepper wrote:
> This behavior occurs whether or not I specify wx.DD_DEFAULT_STYLE.

wx.DD_DEFAULT_STYLE doesn't include the flag you need. Use
wx.DD_DIR_MUST_EXIST.

> wx.DD_DIR_MUST_EXIST: The dialog will allow the user to choose only
an existing folder. When this style is not given, a “Create new
directory” button is added to the dialog (on Windows) or some other way
is provided to the user to type the name of a new folder.

--
James Scholes
http://twitter.com/JamesScholes

schnepper

unread,
Sep 6, 2017, 5:41:06 PM9/6/17
to wxPython-users, ja...@jls-radio.com
Thanks, James.  I tried that and it had no effect.  With or without that flag, the user is able to type a new value into the Location field and a new directory is created.  My guess is that it is a feature of the underlying GTK dialog.  What I want is for the user to be able to select an existing directory or specify a new directory without creating it.  I think I'll have to use a TreeCtl and populate it myself.  I've attached a short program that illustrates the problem.

Mark
dirdi.py

Robin Dunn

unread,
Sep 6, 2017, 7:01:02 PM9/6/17
to wxPython-users
You may want to start with the wx.GenericDirCtrl class.

Robin
Reply all
Reply to author
Forward
0 new messages