示例#1
0
    def __set_file(self, val):

        self.__uri = val
        try:
            self.__fd = vfs.open(self.__uri, OPEN_READ)
        except:
            raise IOError("Could not open file %s." % (self.__uri))

        self._update("uri")
示例#2
0
    def preview(self, filename):

        loader = gtk.gdk.PixbufLoader()
        try:
            fd = vfs.open(filename)
            data = fd.read(3 * 1024 * 1024)  # read a maximum of 3 MB
            fd.close()
            loader.write(data, len(data))

        except:
            try:
                loader.close()
            except:
                pass
            return False

        try:
            loader.close()
        except:
            return False

        pbuf = loader.get_pixbuf()
        if pbuf == None:
            return False

        # scale image down while preserving aspect ratio
        width = pbuf.get_width()
        height = pbuf.get_height()
        if width > 180:
            scale = 180 / float(width)
            height *= scale
            height = max(1, height)
            if abs(scale - 1.0) > 0.001:
                pbuf = pbuf.scale_simple(180, int(height), 3)

        self.__img.set_size_request(180, -1)
        self.__img.set_from_pixbuf(pbuf)
        self.__img.set_size_request(180, -1)
        del pbuf
        import gc

        gc.collect()

        return True