[python-win32] EasyDialogs - how to set initial path

Jimmy Retzlaff jimmy at retzlaff.com
Thu Jun 30 18:45:42 CEST 2005


John Machin wrote:
> 
> Radovan Grznarik wrote:
> 
> >Hi,
> >
> >I am using EasyDialogs (AskFileForOpen) and I am not able to set the
> >initial open path. I found in Python help
> >
> Python help describes the *Mac* version; EasyDialogs for Windows by
> Jimmy Retzlaff has slightly different arguments; there is a readme.txt
> in .....\site-packages\EasyDialogs -- take a hint :-)
> 
> > that it should be 3rd
> >parameter,
> >
> *should* be [you reading this, Jimmy???]. Here's another hint - this
is
> _open source_ software, Luke :-)

I'm reading this now. :) Thanks for copying me. Actually on the Mac it
is not the 3rd parameter either. It is expected that keyword arguments
will be used in all but the most basic cases. The Mac docs actually
refer you to the source more than once just because of things like this.
For the parameters supported, EasyDialogs for Windows uses the same
order as the current Mac version.

For reference you can see the Mac EasyDialogs sources at:

http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Lib/plat-ma
c/EasyDialogs.py?view=auto

> > then I tried this
> >
> >filename = EasyDialogs.AskFileForOpen("title","*.*","d:\\")
> >
> >but it does not work, and opens dialog in actual directory of running
> script.
> >
> >os.chdir("d:\\") before AskFileForOpen also does not work.
> >
> >
> It works, it just doesn't do what you think it should do. WinDOS has a
> current directory on *each* drive. Fire up a DOS box, unless you've
> meddled, the prompt will show C:\something> ... this means the current
> drive is C: and the current directory on C: is \something. If you type
> cd d:\, this sets the current directory on D: to \, but you'll notice
> that your prompt hasn't changed.
> 
> >Does anybody have some idea to solve this situation?
> >
> >
> 
> Yeah. two ideas, actually:
> ONE:
> 
>      try:
>           rtfs()
>      except NoSourceError:
>           trashthesucker()
> 
> TWO:
> Keyword arguments are a thing of beauty and a joy forever, even when
> they're in camelCase -- so bloody well stop counting arguments and use
> them!!

Don't you mean "**especially** when they're in camelCase"? :)

You should definitely use:

filename = EasyDialogs.AskFileForOpen("title","*.*",
defaultLocation="d:\\")

Just reiterating what John was saying... According to the source to both
the Mac and Windows versions, only the order of the first two parameters
to AskFileForOpen can be relied upon. So you don't want to rely on the
fact that it is currently the fourth argument. Also, using keyword
arguments makes the code easier to read. If you aren't familiar with
keyword arguments, here are a few words about them:

http://jefferson.blogs.com/jp/2003/04/more_python_key.html

Jimmy


More information about the Python-win32 mailing list