UI/PixmapCache.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1509
c0b5e693b0eb
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtGui import QPixmap, QIcon, QPainter 12 from PyQt4.QtGui import QPixmap, QIcon, QPainter
13
13 14
14 class PixmapCache(object): 15 class PixmapCache(object):
15 """ 16 """
16 Class implementing a pixmap cache for icons. 17 Class implementing a pixmap cache for icons.
17 """ 18 """
55 if not path in self.searchPath: 56 if not path in self.searchPath:
56 self.searchPath.append(path) 57 self.searchPath.append(path)
57 58
58 pixCache = PixmapCache() 59 pixCache = PixmapCache()
59 60
60 def getPixmap(key, cache = pixCache): 61
62 def getPixmap(key, cache=pixCache):
61 """ 63 """
62 Module function to retrieve a pixmap. 64 Module function to retrieve a pixmap.
63 65
64 @param key name of the wanted pixmap (string) 66 @param key name of the wanted pixmap (string)
65 @return the requested pixmap (QPixmap) 67 @return the requested pixmap (QPixmap)
66 """ 68 """
67 return cache.getPixmap(key) 69 return cache.getPixmap(key)
68 70
69 def getIcon(key, cache = pixCache): 71
72 def getIcon(key, cache=pixCache):
70 """ 73 """
71 Module function to retrieve an icon. 74 Module function to retrieve an icon.
72 75
73 @param key name of the wanted icon (string) 76 @param key name of the wanted icon (string)
74 @return the requested icon (QIcon) 77 @return the requested icon (QIcon)
75 """ 78 """
76 return QIcon(cache.getPixmap(key)) 79 return QIcon(cache.getPixmap(key))
77 80
78 def getSymlinkIcon(key, cache = pixCache): 81
82 def getSymlinkIcon(key, cache=pixCache):
79 """ 83 """
80 Module function to retrieve a symbolic link icon. 84 Module function to retrieve a symbolic link icon.
81 85
82 @param key name of the wanted icon (string) 86 @param key name of the wanted icon (string)
83 @return the requested icon (QIcon) 87 @return the requested icon (QIcon)
87 painter = QPainter(pix1) 91 painter = QPainter(pix1)
88 painter.drawPixmap(0, 10, pix2) 92 painter.drawPixmap(0, 10, pix2)
89 painter.end() 93 painter.end()
90 return QIcon(pix1) 94 return QIcon(pix1)
91 95
92 def addSearchPath(path, cache = pixCache): 96
97 def addSearchPath(path, cache=pixCache):
93 """ 98 """
94 Module function to add a path to the search path. 99 Module function to add a path to the search path.
95 100
96 @param path path to add (string) 101 @param path path to add (string)
97 """ 102 """

eric ide

mercurial