blob: af4e1bbd5af573c6a7912ef1d64d7187853268a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk
import logging
logger = logging.getLogger(__name__)
class PictureCache:
def __init__(self):
self._cache = {}
def get(self, path):
if path in self._cache:
logger.debug('Loading from cache: %s', path)
return self._cache[path]
else:
picture = Gtk.Picture.new_for_filename(path)
logger.debug('Adding in cache: %s', path)
self._cache[path] = picture
return picture
def invalidate(self, path):
logger.debug('Invalidating: %s', path)
if path in self._cache:
del self._cache[path]
|