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

Christian Meesters meesters at uni-mainz.de
Thu Jun 9 08:52:59 CEST 2005


Hi

Currently I'm writing a GUI application with wxPython (on OS X, but I  
guess the problem is the same, regardless of the UNIX derivative one is  
using). When I start the main script where it is located the  
application finds all resource files (non-Python files like images and  
html files for html windows) without any problem. However, if a put a  
link in /usr/local/bin and start the script using the link the  
application cannot find those resource files - unless, of course, I  
will use full absolute paths to point to those files. One brief example  
to illustrate the problem:

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'))  
#this, of course, won't work
		#if the main script is called from somewhere else and not the  
directory where the main script
		#is located

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?

Cheers
Christian



More information about the Tutor mailing list