src/eric7/UI/PixmapCache.py

Wed, 13 Jul 2022 14:55:47 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 13 Jul 2022 14:55:47 +0200
branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
permissions
-rw-r--r--

Reformatted the source code using the 'Black' utility.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
3 # Copyright (c) 2004 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a pixmap cache for icons.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
12 from PyQt6.QtCore import Qt, QSize
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
13 from PyQt6.QtGui import QPixmap, QIcon, QPainter
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
15
8207
d359172d11be Applied some more code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
16 class PixmapCache:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 Class implementing a pixmap cache for icons.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
20
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
21 SupportedExtensions = [".svgz", ".svg", ".png"]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
22
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 def __init__(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 self.pixmapCache = {}
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 self.searchPath = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
30 def getPixmap(self, key, size=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Public method to retrieve a pixmap.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
34 @param key name of the wanted pixmap
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
35 @type str
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
36 @param size requested size
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
37 @type QSize
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
38 @return the requested pixmap
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
39 @rtype QPixmap
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 if key:
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
42 basename, ext = os.path.splitext(key)
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
43 if size and not size.isEmpty():
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
44 key = "{0}_{1}_{2}".format(basename, size.width(), size.height())
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
45 else:
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
46 key = basename
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 return self.pixmapCache[key]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 except KeyError:
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
51 pm = QPixmap()
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
52 for extension in self.SupportedExtensions:
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
53 filename = basename + extension
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
54 if not os.path.isabs(filename):
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
55 for path in self.searchPath:
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
56 pm = QPixmap(path + "/" + filename)
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
57 if not pm.isNull():
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
58 break
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 else:
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
60 pm = QPixmap(filename)
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
61 if not pm.isNull():
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
62 if size and not size.isEmpty():
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
63 pm = pm.scaled(size)
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
64 break
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 else:
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
66 pm = QPixmap()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.pixmapCache[key] = pm
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 return self.pixmapCache[key]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
70
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 return QPixmap()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def addSearchPath(self, path):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Public method to add a path to the search path.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
76
7488
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
77 @param path path to add
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
78 @type str
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
3621
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
80 if path not in self.searchPath:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.searchPath.append(path)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
82
7488
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
83 def removeSearchPath(self, path):
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
84 """
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
85 Public method to remove a path from the search path.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
86
7488
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
87 @param path path to remove
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
88 @type str
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
89 """
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
90 if path in self.searchPath:
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
91 self.searchPath.remove(path)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
93
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 pixCache = PixmapCache()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
96
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
97 def getPixmap(key, size=None, cache=pixCache):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 Module function to retrieve a pixmap.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
101 @param key name of the wanted pixmap
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
102 @type str
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
103 @param size requested size
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
104 @type QSize
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
105 @param cache reference to the pixmap cache object
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
106 @type PixmapCache
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
107 @return the requested pixmap
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
108 @rtype QPixmap
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 """
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
110 return cache.getPixmap(key, size=size)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
112
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
113 def getIcon(key, size=None, cache=pixCache):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 Module function to retrieve an icon.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
117 @param key name of the wanted pixmap
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
118 @type str
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
119 @param size requested size
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
120 @type QSize
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
121 @param cache reference to the pixmap cache object
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
122 @type PixmapCache
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
123 @return the requested icon
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
124 @rtype QIcon
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
126 return QIcon(cache.getPixmap(key, size=size))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
128
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
129 def getSymlinkIcon(key, size=None, cache=pixCache):
103
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
130 """
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
131 Module function to retrieve a symbolic link icon.
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
132
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
133 @param key name of the wanted pixmap
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
134 @type str
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
135 @param size requested size
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
136 @type QSize
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
137 @param cache reference to the pixmap cache object
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
138 @type PixmapCache
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
139 @return the requested icon
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
140 @rtype QIcon
103
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
141 """
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
142 pix1 = QPixmap(cache.getPixmap(key, size=size))
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7488
diff changeset
143 pix2 = cache.getPixmap("symlink")
103
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
144 painter = QPainter(pix1)
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
145 painter.drawPixmap(0, 10, pix2)
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
146 painter.end()
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
147 return QIcon(pix1)
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
148
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
149
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
150 def getCombinedIcon(keys, size=None, cache=pixCache):
3270
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
151 """
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
152 Module function to retrieve a symbolic link icon.
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
153
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
154 @param keys list of names of icons
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
155 @type list of str
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
156 @param size requested size of individual icons
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
157 @type QSize
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
158 @param cache reference to the pixmap cache object
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
159 @type PixmapCache
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
160 @return the requested icon
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
161 @rtype QIcon
3270
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
162 """
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
163 height = width = 0
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
164 pixmaps = []
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
165 for key in keys:
6756
7556c951dce8 PixmapCache: prepared the pixmap cache to be able to load SVG files. Order of precedence is .svgz, .svg and .png. The key is calculated from the basename and the size.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
166 pix = cache.getPixmap(key, size=size)
3270
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
167 if not pix.isNull():
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
168 height = max(height, pix.height())
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
169 width = max(width, pix.width())
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
170 pixmaps.append(pix)
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
171 if pixmaps:
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
172 pix = QPixmap(len(pixmaps) * width, height)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
173 pix.fill(Qt.GlobalColor.transparent)
3270
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
174 painter = QPainter(pix)
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
175 x = 0
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
176 for pixmap in pixmaps:
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
177 painter.drawPixmap(x, 0, pixmap.scaled(QSize(width, height)))
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
178 x += width
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
179 painter.end()
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
180 icon = QIcon(pix)
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
181 else:
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
182 icon = QIcon()
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
183 return icon
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
184
d8532d902e76 Extended Tabview and Listview to show an editor's state using two icons (modified, syntax error/warning).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
185
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
186 def addSearchPath(path, cache=pixCache):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 Module function to add a path to the search path.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189
7488
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
190 @param path path to add
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
191 @type str
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
192 @param cache reference to the pixmap cache object
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
193 @type PixmapCache
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 cache.addSearchPath(path)
7488
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
196
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
197
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
198 def removeSearchPath(path, cache=pixCache):
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
199 """
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
200 Public method to remove a path from the search path.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
201
7488
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
202 @param path path to remove
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
203 @type str
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
204 @param cache reference to the pixmap cache object
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
205 @type PixmapCache
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
206 """
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
207 cache.removeSearchPath(path)

eric ide

mercurial