annotate orpg/mapper/images.py @ 88:763a04270cf6 alpha

Traipse Alpha 'OpenRPG' {090917-02} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc''s main goal is to offer more advanced features and enhance the productivity of the user. Update Summary: 00: Adds menu changes to draw attention to important updates, errors, or other events. (image info coming soon) Traipse URL is not included in the repos tab and is set as default. 01: Fixes Copy for Windows and Linux (finally!!) users. Fixes incomplete update to Grid and List nodes. Fixes incomplete update to Chat Commands. 02: Fixes problems with Remote Image Upload. Fixes Drop and Drag of Minis to Map CherryPy can now use any image in the webfiles/ folder and sub-folders. CherryPy can now Drop and Drag Minis to the Map.
author sirebral
date Thu, 17 Sep 2009 04:44:37 -0500
parents 6226a5f9a4b3
children a647e0e8f520
rev   line source
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
2 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
3 # openrpg-dev@lists.sourceforge.net
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
4 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
5 # This program is free software; you can redistribute it and/or modify
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
8 # (at your option) any later version.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
9 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
13 # GNU General Public License for more details.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
14 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
16 # along with this program; if not, write to the Free Software
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
18 # --
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
19 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
20 # File: mapper/images.py
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
21 # Author: OpenRPG
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
22 # Maintainer:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
23 # Version:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
24 # $Id: images.py,v 1.21 2007/12/11 04:07:15 digitalxero Exp $
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
25 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
26 # Description:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
27 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
28 __version__ = "$Id: images.py,v 1.21 2007/12/11 04:07:15 digitalxero Exp $"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
29
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
30 import urllib
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
31 import Queue
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
32 import thread
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
33 from threading import Lock
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
34 import time
76
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
35
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
36 from orpg.orpg_wx import *
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
37 from orpg.orpgCore import component
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 22
diff changeset
38 from orpg.dirpath import dir_struct
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
39 from orpg.tools.orpg_log import logger
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
40
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
41 def singleton(cls):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
42 instances = {}
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
43 def getinstance():
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
44 if cls not in instances:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
45 instances[cls] = cls()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
46 return instances[cls]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
47 return getinstance()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
48
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
49 class ImageHandlerClass(object):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
50 __cache = {}
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
51 __fetching = {}
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
52 __queue = Queue.Queue(0)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
53 __lock = Lock()
76
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
54 chat = component.get("chat")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
55
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
56 def load(self, path, image_type, imageId):
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
57 """Load an image, with a intermideary fetching image shown while it loads in a background thread"""
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
58 if self.__cache.has_key(path): return wx.ImageFromMime(self.__cache[path][1],
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
59 self.__cache[path][2]).ConvertToBitmap()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
60 if not self.__fetching.has_key(path):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
61 self.__fetching[path] = True
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
62 """Start Image Loading Thread"""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
63 thread.start_new_thread(self.__loadThread, (path, image_type, imageId))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
64 else:
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
65 if self.__fetching[path] is True: thread.start_new_thread(self.__loadCacheThread, (path, image_type, imageId))
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 22
diff changeset
66 return wx.Bitmap(dir_struct["icon"] + "fetching.png", wx.BITMAP_TYPE_PNG)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
67
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
68 def directLoad(self, path):
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
69 """Directly load an image, no threads"""
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
70 if self.__cache.has_key(path): return wx.ImageFromMime(self.__cache[path][1],
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
71 self.__cache[path][2]).ConvertToBitmap()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
72 uriPath = urllib.unquote(path)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
73 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
74 d = urllib.urlretrieve(uriPath)
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
75 """We have to make sure that not only did we fetch something, but that
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
76 it was an image that we got back."""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
77 if d[0] and d[1].getmaintype() == "image":
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
78 self.__cache[path] = (path, d[0], d[1].gettype(), None)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
79 return wx.ImageFromMime(self.__cache[path][1], self.__cache[path][2]).ConvertToBitmap()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
80 else:
76
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
81 logger.general("Image refused to load or URI did not reference a valid image: " + path)
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
82 component.get('chat').InfoPost("<font color='#FF0000'>Image refused to load or URI did not reference a valid image: " + path + "</font>")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
83 return None
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
84 except IOError:
76
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
85 logger.general("Unable to resolve/open the specified URI; image was NOT loaded: " + path)
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
86 component.get('chat').InfoPost("<font color='#FF0000'>Unable to resolve/open the specified URI; image was NOT loaded: " + path + "</font>")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
87 return None
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
88
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
89 def cleanCache(self):
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
90 """Shrinks the Cache down to the proper size"""
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 22
diff changeset
91 try: cacheSize = int(component.get('settings').get_setting("ImageCacheSize"))
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
92 except: cacheSize = 32
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
93 cache = self.__cache.keys()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
94 cache.sort()
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
95 for key in cache[cacheSize:]: del self.__cache[key]
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
96
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
97 def flushCache(self):
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
98 """This function will flush all images contained within the image cache."""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
99 self.__lock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
100 try:
88
763a04270cf6 Traipse Alpha 'OpenRPG' {090917-02}
sirebral
parents: 77
diff changeset
101 self.__cache = {}
763a04270cf6 Traipse Alpha 'OpenRPG' {090917-02}
sirebral
parents: 77
diff changeset
102 self.__fetching = {}
763a04270cf6 Traipse Alpha 'OpenRPG' {090917-02}
sirebral
parents: 77
diff changeset
103 finally:
763a04270cf6 Traipse Alpha 'OpenRPG' {090917-02}
sirebral
parents: 77
diff changeset
104 self.__lock.release()
763a04270cf6 Traipse Alpha 'OpenRPG' {090917-02}
sirebral
parents: 77
diff changeset
105 urllib.urlcleanup()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
106
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
107 """Private Methods"""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
108 def __loadThread(self, path, image_type, imageId):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
109 uriPath = urllib.unquote(path)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
110 self.__lock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
111 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
112 d = urllib.urlretrieve(uriPath)
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
113 """We have to make sure that not only did we fetch something, but that
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
114 it was an image that we got back."""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
115 if d[0] and d[1].getmaintype() == "image":
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
116 self.__cache[path] = (path, d[0], d[1].gettype(), imageId)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
117 self.__queue.put((self.__cache[path], image_type, imageId))
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
118 if self.__fetching.has_key(path): self.__fetching[path] = False #Fix for failed multi-load?
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
119 else:
76
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
120 logger.general("Image refused to load or URI did not reference a valid image: " + path)
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
121 component.get('chat').InfoPost("<font color='#FF0000'>Image refused to load or URI did not reference a valid image: " + path +"</font>")
15
cab94a90f9dc Added 1.8.0 fix to log. Fixed problem with images that do not load the first
sirebral
parents: 3
diff changeset
122 del self.__fetching[path]
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
123 except IOError:
15
cab94a90f9dc Added 1.8.0 fix to log. Fixed problem with images that do not load the first
sirebral
parents: 3
diff changeset
124 del self.__fetching[path]
76
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
125 logger.general("Unable to resolve/open the specified URI; image was NOT loaded: " + path)
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
126 component.get('chat').InfoPost("<font color='#FF0000'> Unable to resolve/open the specified URI; image was NOT loaded: " + path + "</font>")
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
127 finally: self.__lock.release()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
128
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
129 def __loadCacheThread(self, path, image_type, imageId):
22
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
130 if self.__cache.has_key(path):
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
131 try:
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
132 st = time.time()
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
133 while self.__fetching.has_key(path) and self.__fetching[path] is not False:
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
134 time.sleep(0.025)
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
135 if (time.time()-st) > 120:
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
136 logger.general("Timeout: " + path)
22
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
137 break
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
138 except:
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
139 del self.__fetching[path]
76
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
140 logger.general("Unable to resolve/open the specified URI; image was NOT loaded: " + path)
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 71
diff changeset
141 component.get('chat').InfoPost("<font color='#FF0000'>Unable to resolve/open the specified URI; image was NOT loaded: " + path + "</font>")
22
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
142 return
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
143 self.__lock.acquire()
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
144 try:
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
145 logger.debug("Adding Image to Queue from Cache: " + str(self.__cache[path]))
77
6226a5f9a4b3 Fixing images from last push
sirebral
parents: 76
diff changeset
146 component.debug('chat').InfoPost("<font color='#FF0000'>Adding Image to Queue from Cache: " + str(self.__cache[path]) + "</font>")
22
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
147 self.__queue.put((self.__cache[path], image_type, imageId))
88cea66228d6 Should fix Image Chache problem, does not fix memory leak.
sirebral
parents: 20
diff changeset
148 finally: self.__lock.release()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
149
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
150 """Property Methods"""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
151 def _getCache(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
152 return self.__cache
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
153
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
154 def _getQueue(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
155 return self.__queue
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
156
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
157 """Properties"""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
158 Cache = property(_getCache)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
159 Queue = property(_getQueue)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
160
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
161 ImageHandler = singleton(ImageHandlerClass)
88
763a04270cf6 Traipse Alpha 'OpenRPG' {090917-02}
sirebral
parents: 77
diff changeset
162 component.add('ImageHandler', ImageHandler)