[wxPython-users] a couple of scary moments in wxpython under
win32 under py2exe with a ridiculous deadline thrown in...
Nitro
nitro at dr-code.org
Tue Aug 14 13:26:34 PDT 2007
Am 14.08.2007, 22:11 Uhr, schrieb Brian Martin <thebrianmartin at gmail.com>:
> Just some weird things that happened during my project that I wanted to
> share....
>
> 1) For simplicity sake (and because my installer knowledge was minimal),
> I was just putting icons and logos for my application in the root
> directory
> of the source folder. When I would refer
> to them when creating an image for example i could just exclude any path
> information (ie. 'foo.img' vs 'c:\Program Files\proj\foo.img') and
> wxpython (or python) would know how to get them. Then, when adding a
> feature
> to allow someone to add a custom graphic to the application I make a
> call to
> shutil.copy to move the image from a user location into the source tree.
> As
> soon as I do this, wxpython could not find any of my images or icons. I
> had
> to explicitly point to them or it would barf. Now this is probably the
> best
> way to do it and I just made a global constant which used sys.path[0].
> Regardless, it was interesting. Mid-application, references to these
> images
> were broken when i called the shutil.copy command.
Well, this has probably nothing to do with the shutil.copy command. I
suspect you've shown some FileDialog thing. This changes the cwd
sometimes. Since you did not specify absolute pathnames for your images (I
do this always in my app, imo the concept of a cwd should be completely
eliminated from all OSes. It's just an excuse for being lazy imo) wxPython
can suddenly not find them anymore. Never rely on the cwd! For example if
you start your application from "c:\" (by typing "c:\program files\my
app\myapp.exe") then your cwd will be c:\ and *not* the path where your
.exe resides in. Thus everything stops working.
Moral of the story: Never rely on the cwd.
-Matthias
More information about the wxpython-users
mailing list