eric7/UI/PixmapCache.py

Sun, 16 May 2021 20:07:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 16 May 2021 20:07:24 +0200
branch
eric7
changeset 8318
962bce857696
parent 8312
800c432b34c8
child 8881
54e42bc2437a
permissions
-rw-r--r--

Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2004 - 2021 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 """
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
20 SupportedExtensions = [".svgz", ".svg", ".png"]
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
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 def __init__(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 self.pixmapCache = {}
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 self.searchPath = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
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
29 def getPixmap(self, key, size=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Public method to retrieve a pixmap.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
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
33 @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
34 @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
35 @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
36 @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
37 @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
38 @rtype QPixmap
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 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
41 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
42 if size and not size.isEmpty():
6787
3de088ae0782 PixmapCache: fixed a format issue generating the pixmap key when a size was given.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6772
diff changeset
43 key = "{0}_{1}_{2}".format(
3de088ae0782 PixmapCache: fixed a format issue generating the pixmap key when a size was given.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6772
diff changeset
44 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
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
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()
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
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]
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
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.
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
76
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)
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
82
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.
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
86
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
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 pixCache = PixmapCache()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
95
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
96 def getPixmap(key, size=None, cache=pixCache):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 Module function to retrieve a pixmap.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
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
100 @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
101 @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
102 @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
103 @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
104 @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
105 @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
106 @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
107 @rtype QPixmap
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
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
109 return cache.getPixmap(key, size=size)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
111
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
112 def getIcon(key, size=None, cache=pixCache):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 Module function to retrieve an icon.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
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
116 @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
117 @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
118 @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
119 @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
120 @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
121 @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
122 @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
123 @rtype QIcon
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
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
125 return QIcon(cache.getPixmap(key, size=size))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
127
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
128 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
129 """
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
130 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
131
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
132 @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
133 @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
134 @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
135 @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
136 @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
137 @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
138 @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
139 @rtype QIcon
103
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
140 """
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
141 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
142 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
143 painter = QPainter(pix1)
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
144 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
145 painter.end()
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
146 return QIcon(pix1)
59137afca666 Added code to indicate directories and files being symbolic links.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
147
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
148
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
149 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
150 """
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 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
152
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
153 @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
154 @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
155 @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
156 @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
157 @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
158 @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
159 @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
160 @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
161 """
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 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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183
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
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
185 def addSearchPath(path, cache=pixCache):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 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
188
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
189 @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
190 @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
191 @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
192 @type PixmapCache
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 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
195
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 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
198 """
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 Public method to remove a path from the search 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
200
36ec7469f492 PixmapCache: added a method to remove a path from the pixmap search path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
201 @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
202 @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
203 @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
204 @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
205 """
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 cache.removeSearchPath(path)

eric ide

mercurial