Example #1
0
 def init_info(self, info):
     if info is self.info:
         return
     fallback, fallback_active = self.default_icon_path()
     if info.favicon:
         thumb_path = info.favicon
     else:
         thumb_path = fallback
     # we don't use the ImagePool because 'favicon.ico' is a name with too
     # many hits (#16573).
     try:
         image = widgetset.Image(thumb_path)
         if image.width > 16 or image.height > 16:
             image = imagepool.resize_image(image, 16, 16)
         info.icon = widgetset.ImageSurface(image)
         if not info.favicon:
             info.active_icon = imagepool.get_surface(fallback_active,
                                                      size=(16, 16))
     except ValueError:
         # 16842 - if we ever get sent an invalid icon - don't crash with
         # ValueError.
         info.icon = imagepool.get_surface(fallback, size=(16, 16))
         info.active_icon = imagepool.get_surface(fallback_active,
                                                  size=(16, 16))
     info.unwatched = info.available = 0
     info.type = self.type
Example #2
0
    def create_new_value(self, (path, size), invalidator=None):
        try:
            image = widgetset.Image(path)
        except StandardError:
            logging.warn("error loading image %s:\n%s", path,
                         traceback.format_exc())
            image = broken_image
        if size is not None:
            image = resize_image(image, *size)
        return image


class ImageSurfacePool(util.Cache):
    def create_new_value(self, (path, size), invalidator=None):
        image = _imagepool.get((path, size), invalidator=invalidator)
        return widgetset.ImageSurface(image)


_imagepool = ImagePool(CACHE_SIZE)
_image_surface_pool = ImageSurfacePool(CACHE_SIZE)


def get(path, size=None, invalidator=None):
    """Returns an Image for path.

    :param path: the filename for the image
    :param size: if the image needs to fit into a specified sized
                 space, then specify this and get will return a
                 scaled image; if size is not specified, then this
                 returns the default sized image
    :param invalidator: an optional functions which returns True if
Example #3
0
class ImageSurfacePool(util.Cache):
    def create_new_value(self, (path, size)):
        image = _imagepool.get((path, size))
        return widgetset.ImageSurface(image)