[wxPython-users] Re: a couple of scary moments in wxpython under
win32 under py2exe with a ridiculous deadline thrown in...
Christopher Barker
Chris.Barker at noaa.gov
Mon Aug 20 12:46:00 PDT 2007
Brian Martin wrote:
> How do I safely reference icons and images used in my application... I
> can't seem to find a way to get the directory where my python script is
> actually executed from...
If you do some googling, you'll find a number of discussions about this
topic. The reason there isn't some easy way to do this with Python or wx
is that, in fact, There is no fool-proof, cross platform way to do this.
From that comes the recommendation that you not use the application's
installed dir as a way to find data files, etc.
That being said, at least on Windows, it's used often, and works OK. I'm
sure others here will tell you how. It's a lot more problematic on *nix
systems. In any case, however, I'd highly encourage you to do something
in your applications start-up that sets a "DataDirectory" attribute or
something, and everywhere else in your code you use that. That way, you
can change where you put stuff, and only need to change things in one place.
That being said, why not:
wx.StandardPaths.GetDataDir
Return the location of the applications global, i.e. not
user-specific, data files.
Example return values:
* Unix: prefix/share/appname
* Windows: the directory where the executable file is located
* Mac: appname.app/Contents/SharedSupport bundle subdirectory
or (though I don't recommend it):
wxStandardPaths::GetExecutablePath
Return the directory and the filename for the current executable.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the wxpython-users
mailing list