[Tutor] finding path to resource files in a GUI application
alan.gauld at freenet.co.uk
Thu Jun 9 18:46:27 CEST 2005
> The class Goals is in a file called Help.py, located in '/gui_lib/'
> seen from my main script.
> class Goals(wx.Frame):
> def __init__(self,parent,frame,title,size,pos=wx.DefaultPosition):
> self.frame = frame
> self.cwd = os.getcwd()
> self.html = HtmlWindow(self,-1)
> Any ideas what I could use instead of os.getcwd to construct a
> path which will work even if I port the script to an other machine?
The normal way to do this on Unix is to use an environment variable.
MYAPPHOME or somesuch that points to te root directory for your data.
An alternative is to use a resource file .mapprc that lives in each
users home directory and can thus be found with ~/.myapprc
Within that file you define any settings you need including folder
Usually a combination of the above techniques is used, and a default
myapprc(no dot) held someplace like /etc/myapp used if no environment
variable is set or no valid local user file exists.
More information about the Tutor