comparison orpg/mapper/images.py @ 3:28ad6bd3ac71 grumpy-goblin

Images fix did not work. Needs further testing. Moving test over to a RC trac.
author sirebral
date Tue, 14 Jul 2009 21:25:00 -0500
parents d5e81dac98ff
children cab94a90f9dc
comparison
equal deleted inserted replaced
2:d5e81dac98ff 3:28ad6bd3ac71
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 self.bad_url(path) 78 open_rpg.get_component('log').log("Image refused to load or URI did not reference a valid image: " + path, ORPG_GENERAL, True)
79 return None 79 return None
80 except IOError: 80 except IOError:
81 self.bad_url(path) 81 open_rpg.get_component('log').log("Unable to resolve/open the specified URI; image was NOT loaded: " + path, ORPG_GENERAL, True)
82 return None 82 return None
83 83
84 def cleanCache(self): 84 def cleanCache(self):
85 # Shrinks the Cache down to the proper size 85 # Shrinks the Cache down to the proper size
86 try: 86 try:
115 self.__cache[path] = (path, d[0], d[1].gettype(), imageId) 115 self.__cache[path] = (path, d[0], d[1].gettype(), imageId)
116 self.__queue.put((self.__cache[path], image_type, imageId)) 116 self.__queue.put((self.__cache[path], image_type, imageId))
117 if self.__fetching.has_key(path): 117 if self.__fetching.has_key(path):
118 del self.__fetching[path] 118 del self.__fetching[path]
119 else: 119 else:
120 open_rpg.get_component('log').log("Image refused to load or URI did not reference a valid image: " + path, ORPG_GENERAL, True)
120 self.__fetching[path] = False 121 self.__fetching[path] = False
121 self.bad_url(path)
122 except IOError: 122 except IOError:
123 self.__fetching[path] = False 123 self.__fetching[path] = False
124 self.bad_url(path) 124 open_rpg.get_component('log').log("Unable to resolve/open the specified URI; image was NOT laoded: " + path, ORPG_GENERAL, True)
125 finally: 125 finally:
126 self.__lock.release() 126 self.__lock.release()
127 127
128 def __loadCacheThread(self, path, image_type, imageId): 128 def __loadCacheThread(self, path, image_type, imageId):
129 try: 129 try:
133 if (time.time()-st) > 120: 133 if (time.time()-st) > 120:
134 open_rpg.get_component('log').log("Timeout: " + path, ORPG_GENERAL, True) 134 open_rpg.get_component('log').log("Timeout: " + path, ORPG_GENERAL, True)
135 break 135 break
136 except: 136 except:
137 self.__fetching[path] = False 137 self.__fetching[path] = False
138 self.bad_url(path) 138 open_rpg.get_component('log').log("Unable to resolve/open the specified URI; image was NOT loaded: " + path, ORPG_GENERAL, True)
139 return 139 return
140 self.__lock.acquire() 140 self.__lock.acquire()
141 try: 141 try:
142 open_rpg.get_component('log').log("Adding Image to Queue from Cache: " + str(self.__cache[path]), ORPG_DEBUG) 142 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)) 143 self.__queue.put((self.__cache[path], image_type, imageId))
149 return self.__cache 149 return self.__cache
150 150
151 def _getQueue(self): 151 def _getQueue(self):
152 return self.__queue 152 return self.__queue
153 153
154 #Error Messages
155 def bad_url(self, path):
156 open_rpg.get_component('log').log("Image refused to load or URL did not reference a valid image: " + path, ORPG_GENERAL, True)
157 wx.MessageBox("Image refused to load or URL did not reference a valid image: " + path)
158 return
159
160
161 #Properties 154 #Properties
162 Cache = property(_getCache) 155 Cache = property(_getCache)
163 Queue = property(_getQueue) 156 Queue = property(_getQueue)
164 157
165 ImageHandler = singleton(ImageHandlerClass) 158 ImageHandler = singleton(ImageHandlerClass)