[Tutor] finding path to resource files in a GUI application

Alan G 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/'
as
> seen from my main script.
>
> class Goals(wx.Frame):
> def __init__(self,parent,frame,title,size,pos=wx.DefaultPosition):
> wx.Frame.__init__(self,parent,
> -1,title,size,style=wx.DEFAULT_FRAME_STYLE)
> self.frame = frame
> self.cwd = os.getcwd()
>
> self.html = HtmlWindow(self,-1)
> self.html.LoadPage(os.path.join(self.cwd,'gui_lib/Goals.html'))

> Any ideas what I could use instead of os.getcwd to construct a
relative
> 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
locations.

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.

Alan G.



More information about the Tutor mailing list