Hello, the first time that my program runs, I need to let the user choose an
already existing working directory or suggest creating a new one in their My
Documents folder.
I tried using...
... and I noticed that providing a nonexistant default path completely
changes the style of the dialog, and does not work as expected.
The best case scenario would be for the "defaultPath" folder to be displayed
in the dialog, the text control value set to "DefaultName" automatically,
and the "Select Folder" button to create a new folder with the text
control's name at the current location if a nonexistant path was chosen and
set the GetPath value to it, or the normal behavior if an existing path is
chosen.
So I have two questions, how can I intentionally choose the different dialog
style without giving a bad default path? and what is the best way to create
my best case scenario? I think that I need to derive a class from
wx.DirDialog and just bind a function to the "Select Folder" button. Is that
correct, and if so how can I get the ID of that button to rebind it?
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-to-Create-new-Folder-with-wx-DirDialog-tp5716682.html
Sent from the wxPython-users mailing list archive at Nabble.com.
Hi,
Hello, the first time that my program runs, I need to let the user choose an
already existing working directory or suggest creating a new one in their My
Documents folder.
I tried using…
Using what?
… and I noticed that providing a nonexistant default path completely
changes the style of the dialog, and does not work as expected.
The best case scenario would be for the “defaultPath” folder to be displayed
in the dialog, the text control value set to “DefaultName” automatically,
and the “Select Folder” button to create a new folder with the text
control’s name at the current location if a nonexistant path was chosen and
set the GetPath value to it, or the normal behavior if an existing path is
chosen.
So I have two questions, how can I intentionally choose the different dialog
style without giving a bad default path? and what is the best way to create
my best case scenario? I think that I need to derive a class from
wx.DirDialog and just bind a function to the “Select Folder” button. Is that
correct, and if so how can I get the ID of that button to rebind it?
I would use wx’s StandardPaths API to grab the Documents folder. Something like this should suffice:
sp = wx.StandardPaths.Get()
docs_folder = sp.GetDocumentsDir()
See the wxPython demo for additional information.
I’m not seeing a “select” button on my DirDialog on Windows 7. But you definitely need to create an instance of it, although probably not by subclassing it. See again the wxPython demo for an example or you can see my example tutorial: http://www.blog.pythonlibrary.org/2010/06/26/the-dialogs-of-wxpython-part-1-of-2/
Good luck,
Mike
···
On Saturday, March 23, 2013 11:24:04 PM UTC-5, Wilson Omesiete wrote:
I put...
dlg = wx.DirDialog(self, "Choose the main program folder",
defaultPath=os.getenv("USERPROFILE")+"/DefaultName" )
baseDirectory = dlg.GetPath()
dlg.Destroy()
... in my original post inside the code tags, maybe that caused a problem
with displaying it?
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-to-Create-new-Folder-with-wx-DirDialog-tp5716682p5716692.html
Sent from the wxPython-users mailing list archive at Nabble.com.
I put…
dlg = wx.DirDialog(self, “Choose the main program folder”,
defaultPath=os.getenv(“USERPROFILE”)+“/DefaultName” )
baseDirectory = dlg.GetPath()
dlg.Destroy()
… in my original post inside the code tags, maybe that caused a problem
with displaying it?
Yes, that would be the issue. You need a dlg.ShowModal() before the dlg.Destroy()
···
On Monday, March 25, 2013 9:21:52 PM UTC-5, Wilson Omesiete wrote:
–
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-to-Create-new-Folder-with-wx-DirDialog-tp5716682p5716692.html
Sent from the wxPython-users mailing list archive at Nabble.com.
That was an error in copying code, I am not having an issue displaying or
using dialogs.
I was asking for suggestions on the best method to create a custom dialog
with the features that I described, how I can replicate the behavior that
is exhibited by instantiating a DirDialog with an invalid default path
without passing an invalid default path.
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Default-to-Create-new-Folder-with-wx-DirDialog-tp5716682p5716719.html
Sent from the wxPython-users mailing list archive at Nabble.com.
womesiete wrote:
I was asking for suggestions on the best method to create a custom dialog
with the features that I described, how I can replicate the behavior that
is exhibited by instantiating a DirDialog with an invalid default path
without passing an invalid default path.
Perhaps I'm missing something here, but if the default path is always
going to be the same, why not check for its existance and create it if
need be some other way? Then, when you instantiate your dialog, the
default path won't be invalid.
You could even delete the created directory afterwards if the user
selects a different one, but showing a pre-populated folder name field
when the folder in question doesn't exist sounds like a usability
nightmare. I'd prefer my applications to create the folders they need
in the background, rather than modifying a system dialog to have me do
it for them.
···
--
James Scholes
http://twitter.com/JamesScholes