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): |