Package teamwork :: Package widgets :: Module images
[hide private]
[frames] | no frames]

Source Code for Module teamwork.widgets.images

 1  import os 
 2  import os.path 
 3   
 4  imageDirectory = None 
 5   
6 -def getImageDirectory():
7 global imageDirectory 8 if not imageDirectory: 9 imageDirectory = os.path.dirname(__file__) 10 if len(imageDirectory) == 0: 11 imageDirectory = os.getcwd() 12 elements = os.path.split(imageDirectory) 13 imageDirectory = apply(os.path.join,elements[:-1]+('images',)) 14 return imageDirectory
15
16 -def getImage(name):
17 """Returns the OS-appropriate absolute path for the named image""" 18 import os 19 path = os.path.join(getImageDirectory(),name) 20 return path
21
22 -def getAgentImage(filename):
23 if len(filename) > 0: 24 import Tkinter 25 return Tkinter.PhotoImage(file=filename) 26 else: 27 return None
28
29 -def getPILImage(filename):
30 try: 31 from PIL import Image,ImageTk 32 return ImageTk.PhotoImage(Image.open(getImage(filename))) 33 except: 34 return getImage(filename)
35
36 -def loadImages(mapping):
37 """Loads a series of images and returns a table 38 @param mapping: a mapping of keys to file names 39 @type mapping: dict 40 @return: a table mapping keys to C{PhotoImage} objects 41 @rtype: dict 42 """ 43 result = {} 44 for key,filename in mapping.items(): 45 try: 46 result[key] = getPILImage(filename) 47 except: 48 pass 49 return result
50 51 if __name__ == '__main__': 52 print getImage('nobody.gif') 53