UI/PixmapCache.py

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

eric ide

mercurial