src/eric7/UI/PixmapCache.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
15 15
16 class PixmapCache: 16 class PixmapCache:
17 """ 17 """
18 Class implementing a pixmap cache for icons. 18 Class implementing a pixmap cache for icons.
19 """ 19 """
20
20 SupportedExtensions = [".svgz", ".svg", ".png"] 21 SupportedExtensions = [".svgz", ".svg", ".png"]
21 22
22 def __init__(self): 23 def __init__(self):
23 """ 24 """
24 Constructor 25 Constructor
25 """ 26 """
26 self.pixmapCache = {} 27 self.pixmapCache = {}
38 @rtype QPixmap 39 @rtype QPixmap
39 """ 40 """
40 if key: 41 if key:
41 basename, ext = os.path.splitext(key) 42 basename, ext = os.path.splitext(key)
42 if size and not size.isEmpty(): 43 if size and not size.isEmpty():
43 key = "{0}_{1}_{2}".format( 44 key = "{0}_{1}_{2}".format(basename, size.width(), size.height())
44 basename, size.width(), size.height())
45 else: 45 else:
46 key = basename 46 key = basename
47 47
48 try: 48 try:
49 return self.pixmapCache[key] 49 return self.pixmapCache[key]
50 except KeyError: 50 except KeyError:
51 pm = QPixmap() 51 pm = QPixmap()
52 for extension in self.SupportedExtensions: 52 for extension in self.SupportedExtensions:
62 if size and not size.isEmpty(): 62 if size and not size.isEmpty():
63 pm = pm.scaled(size) 63 pm = pm.scaled(size)
64 break 64 break
65 else: 65 else:
66 pm = QPixmap() 66 pm = QPixmap()
67 67
68 self.pixmapCache[key] = pm 68 self.pixmapCache[key] = pm
69 return self.pixmapCache[key] 69 return self.pixmapCache[key]
70 70
71 return QPixmap() 71 return QPixmap()
72 72
73 def addSearchPath(self, path): 73 def addSearchPath(self, path):
74 """ 74 """
75 Public method to add a path to the search path. 75 Public method to add a path to the search path.
76 76
77 @param path path to add 77 @param path path to add
78 @type str 78 @type str
79 """ 79 """
80 if path not in self.searchPath: 80 if path not in self.searchPath:
81 self.searchPath.append(path) 81 self.searchPath.append(path)
82 82
83 def removeSearchPath(self, path): 83 def removeSearchPath(self, path):
84 """ 84 """
85 Public method to remove a path from the search path. 85 Public method to remove a path from the search path.
86 86
87 @param path path to remove 87 @param path path to remove
88 @type str 88 @type str
89 """ 89 """
90 if path in self.searchPath: 90 if path in self.searchPath:
91 self.searchPath.remove(path) 91 self.searchPath.remove(path)
92
92 93
93 pixCache = PixmapCache() 94 pixCache = PixmapCache()
94 95
95 96
96 def getPixmap(key, size=None, cache=pixCache): 97 def getPixmap(key, size=None, cache=pixCache):
195 196
196 197
197 def removeSearchPath(path, cache=pixCache): 198 def removeSearchPath(path, cache=pixCache):
198 """ 199 """
199 Public method to remove a path from the search path. 200 Public method to remove a path from the search path.
200 201
201 @param path path to remove 202 @param path path to remove
202 @type str 203 @type str
203 @param cache reference to the pixmap cache object 204 @param cache reference to the pixmap cache object
204 @type PixmapCache 205 @type PixmapCache
205 """ 206 """

eric ide

mercurial