eric6/UI/PixmapCache.py

Sun, 12 Apr 2020 19:07:49 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 12 Apr 2020 19:07:49 +0200
changeset 7533
88261c96484b
parent 7488
36ec7469f492
child 7781
607a6098cb44
permissions
-rw-r--r--

Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
3 # Copyright (c) 2004 - 2020 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
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
10
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import os
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3621
diff changeset
13 from PyQt5.QtCore import Qt, QSize
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3621
diff changeset
14 from PyQt5.QtGui import QPixmap, QIcon, QPainter
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
16
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class PixmapCache(object):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Class implementing a pixmap cache for icons.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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"]
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
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():
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
44 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
45 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
46 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
47 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
48
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 return self.pixmapCache[key]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 break
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 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
61 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
62 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
63 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
64 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
65 break
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 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
67 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
68
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.pixmapCache[key] = pm
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 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
71
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 return QPixmap()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 def addSearchPath(self, path):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 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
77
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 @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
79 @type str
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
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
81 if path not in self.searchPath:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83
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 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
85 """
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 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
87
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 @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
89 @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
90 """
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 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
92 self.searchPath.remove(path)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
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)
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 pix.fill(Qt.transparent)
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.
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
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