UI/PixmapCache.py

changeset 3270
d8532d902e76
parent 3160
209a07d7e401
child 3484
645c12de6b0c
equal deleted inserted replaced
3269:866c3a2f5380 3270:d8532d902e76
7 Module implementing a pixmap cache for icons. 7 Module implementing a pixmap cache for icons.
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import Qt, QSize
12 from PyQt4.QtGui import QPixmap, QIcon, QPainter 13 from PyQt4.QtGui import QPixmap, QIcon, QPainter
13 14
14 15
15 class PixmapCache(object): 16 class PixmapCache(object):
16 """ 17 """
95 painter.drawPixmap(0, 10, pix2) 96 painter.drawPixmap(0, 10, pix2)
96 painter.end() 97 painter.end()
97 return QIcon(pix1) 98 return QIcon(pix1)
98 99
99 100
101 def getCombinedIcon(keys, cache=pixCache):
102 """
103 Module function to retrieve a symbolic link icon.
104
105 @param keys list of names of icons (string)
106 @param cache reference to the pixmap cache object (PixmapCache)
107 @return the requested icon (QIcon)
108 """
109 height = width = 0
110 pixmaps = []
111 for key in keys:
112 pix = cache.getPixmap(key)
113 if not pix.isNull():
114 height = max(height, pix.height())
115 width = max(width, pix.width())
116 pixmaps.append(pix)
117 if pixmaps:
118 pix = QPixmap(len(pixmaps) * width, height)
119 pix.fill(Qt.transparent)
120 painter = QPainter(pix)
121 x = 0
122 for pixmap in pixmaps:
123 painter.drawPixmap(x, 0, pixmap.scaled(QSize(width, height)))
124 x += width
125 painter.end()
126 icon = QIcon(pix)
127 else:
128 icon = QIcon()
129 return icon
130
131
100 def addSearchPath(path, cache=pixCache): 132 def addSearchPath(path, cache=pixCache):
101 """ 133 """
102 Module function to add a path to the search path. 134 Module function to add a path to the search path.
103 135
104 @param path path to add (string) 136 @param path path to add (string)

eric ide

mercurial