Skip to content

Commit

Permalink
Cache loaded background image when load the same file
Browse files Browse the repository at this point in the history
  • Loading branch information
mlouielu committed May 16, 2019
1 parent 8111874 commit f3e4d62
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions guake/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ class BackgroundImageManager:

def __init__(self, window, filename=None, layout_mode=ImageLayoutMode.SCALE):
self.window = window
self.filename = ''
self.bg_surface = self.load_from_file(filename) if filename else None
self.target_surface = None
self.target_info = (-1, -1, -1) # (width, height, model)
Expand All @@ -349,8 +350,16 @@ def load_from_file(self, filename):
self.bg_surface = None
self.window.queue_draw()
return

if not os.path.exists(filename):
raise FileNotFoundError('Background file not found: %s' % (filename))

if self.filename:
# Cached rendered surface
if os.path.samefile(self.filename, filename):
return self.bg_surface

self.filename = filename
img = Gtk.Image.new_from_file(filename)
pixbuf = img.get_pixbuf()
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, pixbuf.get_width(), pixbuf.get_height())
Expand Down

0 comments on commit f3e4d62

Please sign in to comment.