Exemplo n.º 1
0
    def do_draw(self, cairo_context):
        pixbuf = self._get_pixbuf()
        if not pixbuf:
            return

        alloc = self.get_allocation()
        width, height = alloc.width, alloc.height

        scale_factor = get_scale_factor(self)

        width *= scale_factor
        height *= scale_factor

        if self._path:
            if width < 2 or height < 2:
                return
            round_thumbs = config.getboolean("albumart", "round")
            pixbuf = thumbnails.scale(
                pixbuf, (width - 2 * scale_factor, height - 2 * scale_factor))
            pixbuf = thumbnails.add_border(pixbuf,
                                           80,
                                           round=round_thumbs,
                                           width=scale_factor)
        else:
            pixbuf = thumbnails.scale(pixbuf, (width, height))

        style_context = self.get_style_context()

        pbosf = get_pbosf_for_pixbuf(self, pixbuf)
        pbosf_render(style_context, cairo_context, pbosf, 0, 0)
Exemplo n.º 2
0
    def test_scale(s):
        nw = thumbnails.scale(s.wide, (50, 30))
        s.failUnlessEqual((nw.get_width(), nw.get_height()), (50, 3))

        nh = thumbnails.scale(s.high, (100, 20))
        s.failUnlessEqual((nh.get_width(), nh.get_height()), (2, 20))

        ns = thumbnails.scale(s.small, (500, 300))
        s.failUnlessEqual((ns.get_width(), ns.get_height()), (150, 300))

        ns = thumbnails.scale(s.small, (500, 300), scale_up=False)
        s.failUnlessEqual((ns.get_width(), ns.get_height()), (10, 20))
Exemplo n.º 3
0
    def test_scale(s):
        nw = thumbnails.scale(s.wide, (50, 30))
        s.failUnlessEqual((nw.get_width(), nw.get_height()), (50, 3))

        nh = thumbnails.scale(s.high, (100, 20))
        s.failUnlessEqual((nh.get_width(), nh.get_height()), (2, 20))

        ns = thumbnails.scale(s.small, (500, 300))
        s.failUnlessEqual((ns.get_width(), ns.get_height()), (150, 300))

        ns = thumbnails.scale(s.small, (500, 300), scale_up=False)
        s.failUnlessEqual((ns.get_width(), ns.get_height()), (10, 20))
Exemplo n.º 4
0
def get_paused_pixbuf(boundary, diff):
    """Returns a pixbuf for a paused icon from the current theme.
    The returned pixbuf can have a size of size->size+diff

    size needs to be > 0
    """

    size = min(boundary)

    if size <= 0:
        raise ValueError("size has to be > 0")

    if diff < 0:
        raise ValueError("diff has to be >= 0")

    names = (Icons.MEDIA_PLAYBACK_PAUSE, )
    theme = Gtk.IconTheme.get_default()

    # Get the suggested icon
    info = theme.choose_icon(names, size, Gtk.IconLookupFlags.USE_BUILTIN)
    if not info:
        return

    try:
        pixbuf = info.load_icon()
    except GLib.GError:
        pass
    else:
        # In case it is too big, rescale
        pb_size = min(pixbuf.get_height(), pixbuf.get_width())
        if abs(pb_size - size) > diff:
            return scale(pixbuf, boundary)
        return pixbuf
Exemplo n.º 5
0
def get_paused_pixbuf(boundary, diff):
    """Returns a pixbuf for a paused icon from the current theme.
    The returned pixbuf can have a size of size->size+diff

    size needs to be > 0
    """

    size = min(boundary)

    if size <= 0:
        raise ValueError("size has to be > 0")

    if diff < 0:
        raise ValueError("diff has to be >= 0")

    names = (Icons.MEDIA_PLAYBACK_PAUSE,)
    theme = Gtk.IconTheme.get_default()

    # Get the suggested icon
    info = theme.choose_icon(names, size, Gtk.IconLookupFlags.USE_BUILTIN)
    if not info:
        return

    try:
        pixbuf = info.load_icon()
    except GLib.GError:
        pass
    else:
        # In case it is too big, rescale
        pb_size = min(pixbuf.get_height(), pixbuf.get_width())
        if abs(pb_size - size) > diff:
            return scale(pixbuf, boundary)
        return pixbuf
Exemplo n.º 6
0
    def do_draw(self, cairo_context):
        pixbuf = self._get_pixbuf()
        if not pixbuf:
            return

        alloc = self.get_allocation()
        width, height = alloc.width, alloc.height
        if self._path:
            if width < 2 or height < 2:
                return
            round_thumbs = config.getboolean("albumart", "round")
            pixbuf = thumbnails.scale(pixbuf, (width - 2, height - 2))
            pixbuf = thumbnails.add_border(pixbuf, 80, round_thumbs)
        else:
            pixbuf = thumbnails.scale(pixbuf, (width, height))

        style_context = self.get_style_context()
        Gtk.render_icon(style_context, cairo_context, pixbuf, 0, 0)
Exemplo n.º 7
0
 def cell_data_pb(column, cell, model, iter_):
     album = StoreUtils.get_album(model, iter_)
     if album is None:
         cell.set_property('stock_id', gtk.STOCK_DIRECTORY)
     else:
         album.scan_cover()
         if album.cover:
             cell.set_property('pixbuf', scale(album.cover, (25, 25)))
         else:
             cell.set_property('stock_id', gtk.STOCK_CDROM)
Exemplo n.º 8
0
 def __get_no_cover(self, width, height):
     size = min(width, height)
     if self.__no_cover is None or min(self.__no_cover.get_width(),
         self.__no_cover.get_height()) != size:
         theme = gtk.icon_theme_get_default()
         try:
             self.__no_cover = theme.load_icon(
                 "quodlibet-missing-cover", size, 0)
         except gobject.GError: pass
         else:
             self.__no_cover = thumbnails.scale(
                 self.__no_cover, (size, size))
     return self.__no_cover
Exemplo n.º 9
0
 def get_scaled_cover(album):
     # XXX: Cache this somewhere else
     cover = None
     if not hasattr(album, "_scaled_cover"):
         scale_factor = get_scale_factor(self)
         album.scan_cover(scale_factor=scale_factor)
         if album.cover:
             s = 25 * scale_factor
             cover = scale(album.cover, (s, s))
             album._scaled_cover = cover
     else:
         cover = album._scaled_cover
     return cover
Exemplo n.º 10
0
    def __scale_pixbuf(self, *data):
        if not self.current_pixbuf:
            return
        pixbuf = self.current_pixbuf

        if not self.window_fit.get_active():
            pbosf = pixbuf
        else:
            alloc = self.scrolled.get_allocation()
            width = alloc.width
            height = alloc.height
            scale_factor = get_scale_factor(self)
            boundary = (width * scale_factor, height * scale_factor)
            pixbuf = thumbnails.scale(pixbuf, boundary, scale_up=False)
            pbosf = get_pbosf_for_pixbuf(self, pixbuf)

        set_image_from_pbosf(self.image, pbosf)
Exemplo n.º 11
0
def pixbuf_from_file(fileobj, boundary):
    """Returns a pixbuf with the maximum size defined by boundary.

    Can raise GLib.GError and return None
    """

    try:
        pixbuf = GdkPixbuf.Pixbuf.new_from_file(fileobj.name)
    except GLib.GError:
        try:
            loader = GdkPixbuf.PixbufLoader()
            loader.write(fileobj.read())
            loader.close()
            fileobj.seek(0, 0)
            pixbuf = loader.get_pixbuf()
        except EnvironmentError:
            return

    return thumbnails.scale(pixbuf, boundary, scale_up=False)
Exemplo n.º 12
0
    def init(klass, library):
        try:
            text = file(PATTERN_FN).read().rstrip()
            #Migrate <=2.2 pattern.
            #This breaks people, title.. so remove it someday.
            text = text.replace("<people", "<~people")
            text = text.replace("<title", "<album")
            klass._pattern_text = text
        except EnvironmentError:
            klass._pattern_text = PATTERN

        theme = gtk.icon_theme_get_default()
        try:
            klass.__no_cover = theme.load_icon(
                "quodlibet-missing-cover", 48, 0)
        except gobject.GError: pass
        else:
            klass.__no_cover = thumbnails.scale(
                klass.__no_cover, (48, 48))

        klass._pattern = XMLFromPattern(klass._pattern_text)
Exemplo n.º 13
0
    def __get_paused_pixbuf(self, size, diff):
        """Returns a pixbuf for a paused icon from the current theme.
        The returned pixbuf can have a size of size->size+diff"""

        names = ('media-playback-pause', Gtk.STOCK_MEDIA_PAUSE)
        theme = Gtk.IconTheme.get_default()

        # Get the suggested icon
        info = theme.choose_icon(names, size, Gtk.IconLookupFlags.USE_BUILTIN)
        if not info:
            return

        try:
            pixbuf = info.load_icon()
        except GLib.GError:
            pass
        else:
            # In case it is too big, rescale
            if pixbuf.get_height() - size > diff:
                return scale(pixbuf, (size,) * 2)
            return pixbuf
Exemplo n.º 14
0
    def __init__(self, title, filename, parent=None):
        super(BigCenteredImage, self).__init__()
        self.set_transient_for(qltk.get_top_parent(parent))
        width = gtk.gdk.screen_width() / 2
        height = gtk.gdk.screen_height() / 2

        pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
        pixbuf = thumbnails.scale(pixbuf, (width, height), scale_up=False)

        self.set_title(title)
        self.set_decorated(False)
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_modal(False)
        self.add(gtk.Frame())
        self.child.set_shadow_type(gtk.SHADOW_OUT)
        self.child.add(gtk.EventBox())
        self.child.child.add(gtk.Image())
        self.child.child.child.set_from_pixbuf(pixbuf)

        self.child.child.connect('button-press-event', self.__destroy)
        self.child.child.connect('key-press-event', self.__destroy)
        self.show_all()