src/eric7/EricGui/EricPixmapCache.py

branch
eric7
changeset 10671
f2d75784e574
parent 10439
21c28b0f9e41
child 10676
d1479a4f1426
--- a/src/eric7/EricGui/EricPixmapCache.py	Sun Apr 07 19:23:30 2024 +0200
+++ b/src/eric7/EricGui/EricPixmapCache.py	Sun Apr 07 19:58:46 2024 +0200
@@ -18,7 +18,8 @@
     Class implementing a pixmap cache for icons.
     """
 
-    SupportedExtensions = [".svgz", ".svg", ".png"]
+    SupportedExtensionsVector = [".svgz", ".svg"]
+    SupportedExtensionsPixel = [".png"]
 
     def __init__(self):
         """
@@ -26,6 +27,10 @@
         """
         self.EricPixmapCache = {}
         self.searchPath = []
+        self.__extensions = (
+            EricPixmapCache.SupportedExtensionsVector
+            + EricPixmapCache.SupportedExtensionsPixel
+        )
 
     def getPixmap(self, key, size=None):
         """
@@ -49,7 +54,7 @@
                 return self.EricPixmapCache[key]
             except KeyError:
                 pm = QPixmap()
-                for extension in self.SupportedExtensions:
+                for extension in self.__extensions:
                     filename = basename + extension
                     if not os.path.isabs(filename):
                         for path in self.searchPath:
@@ -90,6 +95,22 @@
         if path in self.searchPath:
             self.searchPath.remove(path)
 
+    def setPreferVectorIcons(self, vectorFirst=True):
+        """
+        Public method to set the preference of vector based icons.
+
+        @param vectorFirst flag indicating the preference of vector icons
+            (defaults to True)
+        @type bool (optional)
+        """
+        self.__extensions = (
+            EricPixmapCache.SupportedExtensionsVector
+            + EricPixmapCache.SupportedExtensionsPixel
+            if vectorFirst
+            else EricPixmapCache.SupportedExtensionsPixel
+            + EricPixmapCache.SupportedExtensionsVector
+        )
+
 
 pixCache = EricPixmapCache()
 
@@ -205,3 +226,14 @@
     @type EricPixmapCache
     """
     cache.removeSearchPath(path)
+
+
+def setPreferVectorIcons(vectorFirst=True, cache=pixCache):
+    """
+    Function to set the preference of vector based icons.
+
+    @param vectorFirst flag indicating the preference of vector icons
+        (defaults to True)
+    @type bool (optional)
+    """
+    cache.setPreferVectorIcons(vectorFirst)

eric ide

mercurial