示例#1
0
    def set_sellable(self, sellable):
        self.sellable = sellable
        if not self.sellable or not self.sellable.image:
            self.image.set_from_stock(Gtk.STOCK_MISSING_IMAGE,
                                      Gtk.IconSize.DIALOG)
            return

        if self._use_thumbnail:
            size = (Image.THUMBNAIL_SIZE_WIDTH, Image.THUMBNAIL_SIZE_HEIGHT)

            if not sellable.image.thumbnail:
                # If image came without a thumbnail, generate one for it
                # This should happen only once for each image
                sellable.image.thumbnail = get_thumbnail(
                    sellable.image.image, size)

            pixbuf = get_pixbuf(sellable.image.thumbnail, size)
        else:
            pixbuf = _pixbuf_converter.from_string(sellable.image.image)
            iw, ih = pixbuf.get_width(), pixbuf.get_height()
            image_aspect = float(iw) / ih

            width, height = self._size
            window_aspect = float(width) / height

            if image_aspect < window_aspect:
                width = int(height * image_aspect)
            else:
                height = int(width / image_aspect)

            pixbuf = pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.BILINEAR)

        self.image.set_from_pixbuf(pixbuf)
示例#2
0
    def _setup_thumbnail(self):
        if not self.image_model:
            self._thumbnail = None
            return

        size = (Image.THUMBNAIL_SIZE_WIDTH, Image.THUMBNAIL_SIZE_HEIGHT)
        if not self.image_model.thumbnail:
            # If image came without a thumbnail, generate one for it
            # This should happen only once for each image
            self.image_model.thumbnail = get_thumbnail(
                self.image_model.image, size)

        self._thumbnail = get_pixbuf(self.image_model.thumbnail, fill_image=size)
示例#3
0
    def _setup_thumbnail(self):
        if not self.image_model:
            self._thumbnail = None
            return

        size = (Image.THUMBNAIL_SIZE_WIDTH, Image.THUMBNAIL_SIZE_HEIGHT)
        if not self.image_model.thumbnail:
            # If image came without a thumbnail, generate one for it
            # This should happen only once for each image
            self.image_model.thumbnail = get_thumbnail(self.image_model.image,
                                                       size)

        self._thumbnail = get_pixbuf(self.image_model.thumbnail,
                                     fill_image=size)