Example #1
0
    def update(self, width = None, height = None):
        """
        Redraws the widget from scratch.
        """
        self.total_border = self.border_visible + self.spacing_inside + self.spacing_outside
        self.total_w = self.item_w + 2*self.total_border
        self.total_h = self.item_h + 2*self.total_border

        if width is None:
            if not self.pixbuf: return
            width = self.pixbuf.get_width()
            height = self.pixbuf.get_height()
        width = max(width, self.total_w)
        self.tiles_w = max(1, int( width / self.total_w ))
        self.tiles_h = max(1, int( ceil( float(len(self.itemlist)) / self.tiles_w ) ))

        height = self.tiles_h * self.total_h
        self.set_size_request(self.total_w, height)

        self.pixbuf = pygtkcompat.gdk.pixbuf.new(gdk.COLORSPACE_RGB, True,
                                                 8, width, height)
        self.pixbuf.fill(0xffffff00) # transparent
        for i, item in enumerate(self.itemlist):
            x = (i % self.tiles_w) * self.total_w
            y = (i / self.tiles_w) * self.total_h
            x += self.total_border
            y += self.total_border

            pixbuf = self.pixbuffunc(item)
            if pixbuf not in self.thumbnails:
                self.thumbnails[pixbuf] = helpers.pixbuf_thumbnail(pixbuf, self.item_w, self.item_h)
            pixbuf = self.thumbnails[pixbuf]
            pixbuf.composite(self.pixbuf, x, y, self.item_w, self.item_h, x, y, 1, 1, gdk.INTERP_BILINEAR, 255)

        self.queue_draw()
Example #2
0
    def pixbuf_scaler(self, pixbuf):
        w, h = pixbuf.get_width(), pixbuf.get_height()
        if w == N and h == N:
            return pixbuf
        if pixbuf not in self.pixbufs_scaled:
            scaled = helpers.pixbuf_thumbnail(pixbuf, N, N)
            # add plus sign
            self.app.pixmaps.plus.composite(scaled, 0, 0, N, N, 0, 0, 1.0, 1.0, gdk.INTERP_BILINEAR, 255)

            self.pixbufs_scaled[pixbuf] = scaled

        return self.pixbufs_scaled[pixbuf]
Example #3
0
    def pixbuf_scaler(self, pixbuf):
        w, h = pixbuf.get_width(), pixbuf.get_height()
        if w == N and h == N:
            return pixbuf
        if pixbuf not in self.pixbufs_scaled:
            scaled = helpers.pixbuf_thumbnail(pixbuf, N, N)
            # add plus sign
            self.app.pixmaps.plus.composite(scaled, 0, 0, N, N, 0, 0, 1.0, 1.0, gdk.INTERP_BILINEAR, 255)

            self.pixbufs_scaled[pixbuf] = scaled

        return self.pixbufs_scaled[pixbuf]
Example #4
0
 def update_preview_cb(self, file_chooser, preview):
     filename = file_chooser.get_preview_filename()
     if filename:
         filename = filename.decode('utf-8')
         pixbuf = helpers.freedesktop_thumbnail(filename)
         if pixbuf:
             # if pixbuf is smaller than 256px in width, copy it onto a transparent 256x256 pixbuf
             pixbuf = helpers.pixbuf_thumbnail(pixbuf, 256, 256, True)
             preview.set_from_pixbuf(pixbuf)
             file_chooser.set_preview_widget_active(True)
         else:
             #TODO display "no preview available" image
             pass
Example #5
0
 def update_preview_cb(self, file_chooser, preview):
     filename = file_chooser.get_preview_filename()
     if filename:
         filename = filename.decode('utf-8')
         pixbuf = helpers.freedesktop_thumbnail(filename)
         if pixbuf:
             # if pixbuf is smaller than 256px in width, copy it onto a transparent 256x256 pixbuf
             pixbuf = helpers.pixbuf_thumbnail(pixbuf, 256, 256, True)
             preview.set_from_pixbuf(pixbuf)
             file_chooser.set_preview_widget_active(True)
         else:
             #TODO display "no preview available" image
             pass
Example #6
0
    def update(self, width=None, height=None):
        """
        Redraws the widget from scratch.
        """
        self.total_border = self.border_visible \
            + self.spacing_inside + self.spacing_outside
        self.total_w = self.item_w + 2*self.total_border
        self.total_h = self.item_h + 2*self.total_border

        if width is None:
            if not self.pixbuf:
                return
            width = self.pixbuf.get_width()
            height = self.pixbuf.get_height()
        width = max(width, self.total_w)
        self.tiles_w = max(1, int(width // self.total_w))
        self.tiles_h = max(1, int(ceil(len(self.itemlist) / self.tiles_w)))

        height = self.tiles_h * self.total_h
        # self.set_size_request(-1, -1)
        GLib.idle_add(self.set_size_request, self.total_w, height)

        self.pixbuf = GdkPixbuf.Pixbuf.new(
            GdkPixbuf.Colorspace.RGB, True,
            8, width, height
        )
        self.pixbuf.fill(0xffffff00)  # transparent
        for i, item in enumerate(self.itemlist):
            x = (i % self.tiles_w) * self.total_w
            y = (i // self.tiles_w) * self.total_h
            x += self.total_border
            y += self.total_border

            pixbuf = self.pixbuffunc(item)
            if pixbuf not in self.thumbnails:
                self.thumbnails[pixbuf] = helpers.pixbuf_thumbnail(
                    pixbuf,
                    self.item_w, self.item_h,
                )
            pixbuf = self.thumbnails[pixbuf]
            pixbuf.composite(
                self.pixbuf, x, y, self.item_w, self.item_h, x, y, 1, 1,
                GdkPixbuf.InterpType.BILINEAR, 255)

        self.queue_draw()
Example #7
0
    def update(self, width=None, height=None):
        """
        Redraws the widget from scratch.
        """
        self.total_border = self.border_visible + self.spacing_inside + self.spacing_outside
        self.total_w = self.item_w + 2*self.total_border
        self.total_h = self.item_h + 2*self.total_border

        if width is None:
            if not self.pixbuf:
                return
            width = self.pixbuf.get_width()
            height = self.pixbuf.get_height()
        width = max(width, self.total_w)
        self.tiles_w = max(1, int(width // self.total_w))
        self.tiles_h = max(1, int(ceil(len(self.itemlist) / self.tiles_w)))

        height = self.tiles_h * self.total_h
        #self.set_size_request(-1, -1)
        GLib.idle_add(self.set_size_request, self.total_w, height)

        self.pixbuf = GdkPixbuf.Pixbuf.new(
            GdkPixbuf.Colorspace.RGB, True,
            8, width, height
        )
        self.pixbuf.fill(0xffffff00)  # transparent
        for i, item in enumerate(self.itemlist):
            x = (i % self.tiles_w) * self.total_w
            y = (i // self.tiles_w) * self.total_h
            x += self.total_border
            y += self.total_border

            pixbuf = self.pixbuffunc(item)
            if pixbuf not in self.thumbnails:
                self.thumbnails[pixbuf] = helpers.pixbuf_thumbnail(pixbuf, self.item_w, self.item_h)
            pixbuf = self.thumbnails[pixbuf]
            pixbuf.composite(
                self.pixbuf, x, y, self.item_w, self.item_h, x, y, 1, 1,
                GdkPixbuf.InterpType.BILINEAR, 255)

        self.queue_draw()
Example #8
0
    def update(self, width=None, height=None):
        """
        Redraws the widget from scratch.
        """
        self.total_border = self.border_visible + self.spacing_inside + self.spacing_outside
        self.total_w = self.item_w + 2 * self.total_border
        self.total_h = self.item_h + 2 * self.total_border

        if width is None:
            if not self.pixbuf:
                return
            width = self.pixbuf.get_width()
            height = self.pixbuf.get_height()
        width = max(width, self.total_w)
        self.tiles_w = max(1, int(width / self.total_w))
        self.tiles_h = max(1,
                           int(ceil(float(len(self.itemlist)) / self.tiles_w)))

        height = self.tiles_h * self.total_h
        #self.set_size_request(-1, -1)
        gobject.idle_add(self.set_size_request, self.total_w, height)

        self.pixbuf = gtk2compat.gdk.pixbuf.new(gdk.COLORSPACE_RGB, True, 8,
                                                width, height)
        self.pixbuf.fill(0xffffff00)  # transparent
        for i, item in enumerate(self.itemlist):
            x = (i % self.tiles_w) * self.total_w
            y = (i / self.tiles_w) * self.total_h
            x += self.total_border
            y += self.total_border

            pixbuf = self.pixbuffunc(item)
            if pixbuf not in self.thumbnails:
                self.thumbnails[pixbuf] = helpers.pixbuf_thumbnail(
                    pixbuf, self.item_w, self.item_h)
            pixbuf = self.thumbnails[pixbuf]
            pixbuf.composite(self.pixbuf, x, y, self.item_w, self.item_h, x, y,
                             1, 1, gdk.INTERP_BILINEAR, 255)

        self.queue_draw()