16 class EricPixmapCache: |
16 class EricPixmapCache: |
17 """ |
17 """ |
18 Class implementing a pixmap cache for icons. |
18 Class implementing a pixmap cache for icons. |
19 """ |
19 """ |
20 |
20 |
21 SupportedExtensions = [".svgz", ".svg", ".png"] |
21 SupportedExtensionsVector = [".svgz", ".svg"] |
|
22 SupportedExtensionsPixel = [".png"] |
22 |
23 |
23 def __init__(self): |
24 def __init__(self): |
24 """ |
25 """ |
25 Constructor |
26 Constructor |
26 """ |
27 """ |
27 self.EricPixmapCache = {} |
28 self.EricPixmapCache = {} |
28 self.searchPath = [] |
29 self.searchPath = [] |
|
30 self.__extensions = ( |
|
31 EricPixmapCache.SupportedExtensionsVector |
|
32 + EricPixmapCache.SupportedExtensionsPixel |
|
33 ) |
29 |
34 |
30 def getPixmap(self, key, size=None): |
35 def getPixmap(self, key, size=None): |
31 """ |
36 """ |
32 Public method to retrieve a pixmap. |
37 Public method to retrieve a pixmap. |
33 |
38 |
47 |
52 |
48 try: |
53 try: |
49 return self.EricPixmapCache[key] |
54 return self.EricPixmapCache[key] |
50 except KeyError: |
55 except KeyError: |
51 pm = QPixmap() |
56 pm = QPixmap() |
52 for extension in self.SupportedExtensions: |
57 for extension in self.__extensions: |
53 filename = basename + extension |
58 filename = basename + extension |
54 if not os.path.isabs(filename): |
59 if not os.path.isabs(filename): |
55 for path in self.searchPath: |
60 for path in self.searchPath: |
56 pm = QPixmap(path + "/" + filename) |
61 pm = QPixmap(path + "/" + filename) |
57 if not pm.isNull(): |
62 if not pm.isNull(): |
87 @param path path to remove |
92 @param path path to remove |
88 @type str |
93 @type str |
89 """ |
94 """ |
90 if path in self.searchPath: |
95 if path in self.searchPath: |
91 self.searchPath.remove(path) |
96 self.searchPath.remove(path) |
|
97 |
|
98 def setPreferVectorIcons(self, vectorFirst=True): |
|
99 """ |
|
100 Public method to set the preference of vector based icons. |
|
101 |
|
102 @param vectorFirst flag indicating the preference of vector icons |
|
103 (defaults to True) |
|
104 @type bool (optional) |
|
105 """ |
|
106 self.__extensions = ( |
|
107 EricPixmapCache.SupportedExtensionsVector |
|
108 + EricPixmapCache.SupportedExtensionsPixel |
|
109 if vectorFirst |
|
110 else EricPixmapCache.SupportedExtensionsPixel |
|
111 + EricPixmapCache.SupportedExtensionsVector |
|
112 ) |
92 |
113 |
93 |
114 |
94 pixCache = EricPixmapCache() |
115 pixCache = EricPixmapCache() |
95 |
116 |
96 |
117 |
203 @type str |
224 @type str |
204 @param cache reference to the pixmap cache object |
225 @param cache reference to the pixmap cache object |
205 @type EricPixmapCache |
226 @type EricPixmapCache |
206 """ |
227 """ |
207 cache.removeSearchPath(path) |
228 cache.removeSearchPath(path) |
|
229 |
|
230 |
|
231 def setPreferVectorIcons(vectorFirst=True, cache=pixCache): |
|
232 """ |
|
233 Function to set the preference of vector based icons. |
|
234 |
|
235 @param vectorFirst flag indicating the preference of vector icons |
|
236 (defaults to True) |
|
237 @type bool (optional) |
|
238 """ |
|
239 cache.setPreferVectorIcons(vectorFirst) |