feat: Add caching for icons and pixbufs (#1609)

This commit is contained in:
Andrew Sun authored and GitHub committed 2025-08-17 08:14:00 -06:00
1 parent c8a3a15c02
commit d287e762c6
1 file changed
+9 -2
+9 -2
View File
@@ -2,6 +2,7 @@
import logging
import os
import pathlib
from functools import lru_cache
import gi
@@ -126,15 +127,21 @@ class KlippyGtk:
def PixbufFromIcon(self, filename, width=None, height=None):
width = width if width is not None else self.img_width
height = height if height is not None else self.img_height
filename = os.path.join(self.themedir, filename)
return self._PixbufFromIcon(filename, self.themedir, int(width), int(height))
@staticmethod
@lru_cache(maxsize=500)
def _PixbufFromIcon(filename, themedir, width, height):
filename = os.path.join(themedir, filename)
for ext in ["svg", "png"]:
file = f"{filename}.{ext}"
pixbuf = self.PixbufFromFile(file, int(width), int(height)) if os.path.exists(file) else None
pixbuf = KlippyGtk.PixbufFromFile(file, width, height) if os.path.exists(file) else None
if pixbuf is not None:
return pixbuf
return None
@staticmethod
@lru_cache(maxsize=500)
def PixbufFromFile(filename, width=-1, height=-1):
try:
return GdkPixbuf.Pixbuf.new_from_file_at_size(filename, int(width), int(height))