Exemplo n.º 1
0
 def load(self, size):
     ""
     if not self._original:
         try:
             self._original = pb_new(self.get_filename())
         except gobject.GError:
             exposong.log.error('Could not find "%s".', self.src)
             return False
     
     size[:] = get_size(self._original, size, self.aspect)
     skey = 'x'.join(map(str, size))
     if skey not in self._cache:
         self._cache[skey] = scale_image(self._original, size, self.aspect)
     return self._cache[skey]
Exemplo n.º 2
0
 def load(self, size):
     "Loads an image based on a requested size [width, height]."
     if not self.src or not os.path.isfile(self.src):
         return False
     if not self._original:
         try:
             self._original = pb_new(self.src)
         except gobject.GError:
             exposong.log.error('Could not find "%s".', self.src)
             return False
     
     skey = 'x'.join(map(str, get_size(self._original, size, self.aspect)))
     if skey not in self._cache:
         self._cache[skey] = scale_image(self._original, size, self.aspect)
     return self._cache[skey]
Exemplo n.º 3
0
 def _get_pixmap(self, window, size, cache=True):
     "Render to an offscreen pixmap."
     cache = cache and self.can_cache
     if not cache:
         self._delete_pixmap(size)
     fname = self._get_pixmap_name(size)
     if not fname:
         return None
     if cache and fname in self._pm:
         return self._pm[fname]
     
     width, height = size
     
     self._pm[fname] = gtk.gdk.Pixmap(window, width, height)
     
     cache_dir = os.path.join(DATA_PATH, ".cache", "theme")
     if not os.path.exists(cache_dir):
         os.makedirs(cache_dir)
     cpath = os.path.join(cache_dir, fname)
     
     ccontext = self._pm[fname].cairo_create()
     if cache and os.path.exists(cpath):
         # Load the image from memory, or disk if available
         exposong.log.debug('Loading theme thumbnail "%s".', fname)
         pb = pb_new(cpath)
         ccontext.set_source_pixbuf(pb, 0, 0)
         ccontext.paint()
     else:
         exposong.log.debug('Generating theme thumbnail "%s".', fname)
         bounds = (0, 0, SCALED_HEIGHT * CELL_ASPECT, SCALED_HEIGHT)
         ccontext.scale(float(width) / bounds[2],
                        float(height) / bounds[3])
         self.theme.render(ccontext, bounds, self.slide)
         if self.can_cache:
             # Save the rendered image to cache
             pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width,
                                 height)
             pb.get_from_drawable(self._pm[fname],
                                  self._pm[fname].get_colormap(), 0, 0, 0, 0,
                                  width, height)
             pb.save(cpath, "png")
     return self._pm[fname]