comparison orpg/mapper/images.py @ 19:78407d627cba traipse_dev

Beginning of Code Clean-up. Some code untested, may break!
author sirebral
date Sat, 25 Jul 2009 17:24:40 -0500
parents 83fb9a73a30f
children 072ffc1d466f
comparison
equal deleted inserted replaced
18:67b900deb35c 19:78407d627cba
73 # it was an image that we got back. 73 # it was an image that we got back.
74 if d[0] and d[1].getmaintype() == "image": 74 if d[0] and d[1].getmaintype() == "image":
75 self.__cache[path] = (path, d[0], d[1].gettype(), None) 75 self.__cache[path] = (path, d[0], d[1].gettype(), None)
76 return wx.ImageFromMime(self.__cache[path][1], self.__cache[path][2]).ConvertToBitmap() 76 return wx.ImageFromMime(self.__cache[path][1], self.__cache[path][2]).ConvertToBitmap()
77 else: 77 else:
78 open_rpg.get_component('log').log("Image refused to load or URI did not reference a valid image: " + path, ORPG_GENERAL, True) 78 open_rpg.get_component('log').log("Image refused to load or URI did not reference a valid image: " + path,
79 ORPG_GENERAL, True)
79 return None 80 return None
80 except IOError: 81 except IOError:
81 open_rpg.get_component('log').log("Unable to resolve/open the specified URI; image was NOT loaded: " + path, ORPG_GENERAL, True) 82 open_rpg.get_component('log').log("Unable to resolve/open the specified URI; image was NOT loaded: " + path,
83 ORPG_GENERAL, True)
82 return None 84 return None
83 85
84 def cleanCache(self): 86 def cleanCache(self):
85 # Shrinks the Cache down to the proper size 87 # Shrinks the Cache down to the proper size
86 try: 88 try:
115 self.__cache[path] = (path, d[0], d[1].gettype(), imageId) 117 self.__cache[path] = (path, d[0], d[1].gettype(), imageId)
116 self.__queue.put((self.__cache[path], image_type, imageId)) 118 self.__queue.put((self.__cache[path], image_type, imageId))
117 if self.__fetching.has_key(path): 119 if self.__fetching.has_key(path):
118 del self.__fetching[path] 120 del self.__fetching[path]
119 else: 121 else:
120 open_rpg.get_component('log').log("Image refused to load or URI did not reference a valid image: " + path, ORPG_GENERAL, True) 122 open_rpg.get_component('log').log("Image refused to load or URI did not reference a valid image: " + path,
123 ORPG_GENERAL, True)
121 del self.__fetching[path] 124 del self.__fetching[path]
122 except IOError: 125 except IOError:
123 del self.__fetching[path] 126 del self.__fetching[path]
124 open_rpg.get_component('log').log("Unable to resolve/open the specified URI; image was NOT laoded: " + path, ORPG_GENERAL, True) 127 open_rpg.get_component('log').log("Unable to resolve/open the specified URI; image was NOT laoded: " + path,
128 ORPG_GENERAL, True)
125 finally: 129 finally:
126 self.__lock.release() 130 self.__lock.release()
127 131
128 def __loadCacheThread(self, path, image_type, imageId): 132 def __loadCacheThread(self, path, image_type, imageId):
129 try: 133 try:
133 if (time.time()-st) > 120: 137 if (time.time()-st) > 120:
134 open_rpg.get_component('log').log("Timeout: " + path, ORPG_GENERAL, True) 138 open_rpg.get_component('log').log("Timeout: " + path, ORPG_GENERAL, True)
135 break 139 break
136 except: 140 except:
137 self.__fetching[path] = False 141 self.__fetching[path] = False
138 open_rpg.get_component('log').log("Unable to resolve/open the specified URI; image was NOT loaded: " + path, ORPG_GENERAL, True) 142 open_rpg.get_component('log').log("Unable to resolve/open the specified URI; image was NOT loaded: " + path,
143 ORPG_GENERAL, True)
139 return 144 return
140 self.__lock.acquire() 145 self.__lock.acquire()
141 try: 146 try:
142 open_rpg.get_component('log').log("Adding Image to Queue from Cache: " + str(self.__cache[path]), ORPG_DEBUG) 147 open_rpg.get_component('log').log("Adding Image to Queue from Cache: " + str(self.__cache[path]), ORPG_DEBUG)
143 self.__queue.put((self.__cache[path], image_type, imageId)) 148 self.__queue.put((self.__cache[path], image_type, imageId))