Example #1
0
    def _no_cover(self):
        """Returns a cairo surface of pixbuf representing a missing cover"""

        cover_size = Album.COVER_SIZE
        scale_factor = get_scale_factor(self)
        pb = get_no_cover_pixbuf(cover_size, cover_size, scale_factor)
        return get_pbosf_for_pixbuf(self, pb)
Example #2
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 * scale_factor) or height < (2 * scale_factor):
                return
            round_thumbs = config.getboolean("albumart", "round")
            pixbuf = scale(
                pixbuf, (width - 2 * scale_factor, height - 2 * scale_factor))
            pixbuf = add_border_widget(pixbuf, self, round_thumbs)
        else:
            pixbuf = 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)
Example #3
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 = scale(
                pixbuf, (width - 2 * scale_factor, height - 2 * scale_factor))
            pixbuf = add_border_widget(pixbuf, self, None, round_thumbs)
        else:
            pixbuf = 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)
Example #4
0
    def _no_cover(self):
        """Returns a cairo surface of pixbuf representing a missing cover"""

        cover_size = Album.COVER_SIZE
        scale_factor = get_scale_factor(self)
        pb = get_no_cover_pixbuf(cover_size, cover_size, scale_factor)
        return get_pbosf_for_pixbuf(self, pb)
Example #5
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 * scale_factor) or height < (2 * scale_factor):
                return
            pixbuf = scale(
                pixbuf, (width - 2 * scale_factor, height - 2 * scale_factor))
            pixbuf = add_border_widget(pixbuf, self)
        else:
            pixbuf = 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)
Example #6
0
 def test_pbosf_get_width_height(self):
     w = Gtk.Button()
     rgb = GdkPixbuf.Colorspace.RGB
     s = get_scale_factor(w)
     newpb = GdkPixbuf.Pixbuf.new(rgb, True, 8, 10 * s, 15 * s)
     pbosf = get_pbosf_for_pixbuf(w, newpb)
     self.assertEqual(pbosf_get_width(pbosf), 10)
     self.assertEqual(pbosf_get_height(pbosf), 15)
Example #7
0
 def test_pbosf_get_width_height(self):
     w = Gtk.Button()
     rgb = GdkPixbuf.Colorspace.RGB
     s = get_scale_factor(w)
     newpb = GdkPixbuf.Pixbuf.new(rgb, True, 8, 10 * s, 15 * s)
     pbosf = get_pbosf_for_pixbuf(w, newpb)
     self.assertEqual(pbosf_get_width(pbosf), 10)
     self.assertEqual(pbosf_get_height(pbosf), 15)
Example #8
0
 def cell_data_pb(column, cell, model, iter_, data):
     album = model.get_album(iter_)
     if album is None:
         cell.set_property('stock_id', Gtk.STOCK_DIRECTORY)
     else:
         cover = get_scaled_cover(album)
         if cover:
             pbosf = get_pbosf_for_pixbuf(self, cover)
             prop_name = pbosf_get_property_name(pbosf)
             cell.set_property(prop_name, pbosf)
         else:
             cell.set_property('stock_id', Gtk.STOCK_CDROM)
Example #9
0
 def cell_data_pb(column, cell, model, iter_, data):
     album = model.get_album(iter_)
     if album is None:
         cell.set_property('icon-name', Icons.FOLDER)
     else:
         cover = get_scaled_cover(album)
         if cover:
             cover = add_border_widget(cover, view)
             pbosf = get_pbosf_for_pixbuf(self, cover)
             set_renderer_from_pbosf(cell, pbosf)
         else:
             cell.set_property('icon-name', Icons.MEDIA_OPTICAL)
Example #10
0
 def cell_data_pb(column, cell, model, iter_, data):
     album = model.get_album(iter_)
     if album is None:
         cell.set_property("icon-name", Icons.FOLDER)
     else:
         cover = get_scaled_cover(album)
         if cover:
             cover = add_border_widget(cover, view)
             pbosf = get_pbosf_for_pixbuf(self, cover)
             set_renderer_from_pbosf(cell, pbosf)
         else:
             cell.set_property("icon-name", Icons.MEDIA_OPTICAL)
Example #11
0
 def cell_data_pb(column, cell, model, iter_, no_cover):
     album = model.get_album(iter_)
     if album is None:
         pixbuf = None
     elif album.cover:
         pixbuf = get_pbosf_for_pixbuf(self, album.cover)
     else:
         pixbuf = no_cover
     if self.__last_render_pb == pixbuf:
         return
     self.__last_render_pb = pixbuf
     set_renderer_from_pbosf(cell, pixbuf)
Example #12
0
 def cell_data_pb(column, cell, model, iter_, data):
     album = model.get_album(iter_)
     if album is None:
         cell.set_property('stock_id', Gtk.STOCK_DIRECTORY)
     else:
         cover = get_scaled_cover(album)
         if cover:
             round_ = config.getboolean("albumart", "round")
             cover = add_border_widget(cover, view, cell, round=round_)
             pbosf = get_pbosf_for_pixbuf(self, cover)
             set_renderer_from_pbosf(cell, pbosf)
         else:
             cell.set_property('stock_id', Gtk.STOCK_CDROM)
Example #13
0
 def cell_data_pb(column, cell, model, iter_, data):
     album = model.get_album(iter_)
     if album is None:
         cell.set_property('icon-name', Icons.FOLDER)
     else:
         cover = get_scaled_cover(album)
         if cover:
             round_ = config.getboolean("albumart", "round")
             cover = add_border_widget(cover, view, round=round_)
             pbosf = get_pbosf_for_pixbuf(self, cover)
             set_renderer_from_pbosf(cell, pbosf)
         else:
             cell.set_property('icon-name', Icons.MEDIA_OPTICAL)
Example #14
0
 def cell_data_pb(column, cell, model, iter_, data):
     album = model.get_album(iter_)
     if album is None:
         cell.set_property('stock_id', Gtk.STOCK_DIRECTORY)
     else:
         cover = get_scaled_cover(album)
         if cover:
             round_ = config.getboolean("albumart", "round")
             cover = add_border_widget(
                 cover, view, cell, round=round_)
             pbosf = get_pbosf_for_pixbuf(self, cover)
             set_renderer_from_pbosf(cell, pbosf)
         else:
             cell.set_property('stock_id', Gtk.STOCK_CDROM)
Example #15
0
    def __init__(self, title, fileobj, parent):
        super(BigCenteredImage, self).__init__(type=Gtk.WindowType.POPUP)
        self.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)

        assert parent
        parent = qltk.get_top_parent(parent)
        self.set_transient_for(parent)

        if qltk.is_wayland():
            # no screen size with wayland, the parent window is
            # the next best thing..
            width, height = parent.get_size()
            width = int(width / 1.1)
            height = int(height / 1.1)
        else:
            width = int(Gdk.Screen.width() / 1.75)
            height = int(Gdk.Screen.height() / 1.75)

        self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

        scale_factor = get_scale_factor(self)

        pixbuf = None
        try:
            pixbuf = pixbuf_from_file(fileobj, (width, height), scale_factor)
        except GLib.GError:
            pass

        # failed to load, abort
        if not pixbuf:
            self.destroy()
            return

        image = Gtk.Image()
        set_image_from_pbosf(image, get_pbosf_for_pixbuf(self, pixbuf))

        event_box = Gtk.EventBox()
        event_box.add(image)

        frame = Gtk.Frame()
        frame.set_shadow_type(Gtk.ShadowType.OUT)
        frame.add(event_box)

        self.add(frame)

        event_box.connect('button-press-event', self.__destroy)
        event_box.connect('key-press-event', self.__destroy)
        self.get_child().show_all()
Example #16
0
    def __init__(self, title, fileobj, parent):
        super(BigCenteredImage, self).__init__(type=Gtk.WindowType.POPUP)
        self.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)

        assert parent
        parent = qltk.get_top_parent(parent)
        self.set_transient_for(parent)

        if qltk.is_wayland():
            # no screen size with wayland, the parent window is
            # the next best thing..
            width, height = parent.get_size()
            width = int(width / 1.1)
            height = int(height / 1.1)
        else:
            width = int(Gdk.Screen.width() / 1.75)
            height = int(Gdk.Screen.height() / 1.75)

        self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

        scale_factor = get_scale_factor(self)

        pixbuf = None
        try:
            pixbuf = pixbuf_from_file(fileobj, (width, height), scale_factor)
        except GLib.GError:
            pass

        # failed to load, abort
        if not pixbuf:
            self.destroy()
            return

        image = Gtk.Image()
        set_image_from_pbosf(image, get_pbosf_for_pixbuf(self, pixbuf))

        event_box = Gtk.EventBox()
        event_box.add(image)

        frame = Gtk.Frame()
        frame.set_shadow_type(Gtk.ShadowType.OUT)
        frame.add(event_box)

        self.add(frame)

        event_box.connect('button-press-event', self.__destroy)
        event_box.connect('key-press-event', self.__destroy)
        self.get_child().show_all()
Example #17
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 = scale(pixbuf, boundary, scale_up=False)
            pbosf = get_pbosf_for_pixbuf(self, pixbuf)

        set_image_from_pbosf(self.image, pbosf)
Example #18
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 = scale(pixbuf, boundary, scale_up=False)
            pbosf = get_pbosf_for_pixbuf(self, pixbuf)

        set_image_from_pbosf(self.image, pbosf)
Example #19
0
    def __add_cover_to_list(self, cover):
        try:
            pbloader = GdkPixbuf.PixbufLoader()
            pbloader.write(get_url(cover['thumbnail'])[0])
            pbloader.close()

            scale_factor = get_scale_factor(self)
            size = self.THUMB_SIZE * scale_factor - scale_factor * 2
            pixbuf = pbloader.get_pixbuf().scale_simple(size, size,
                GdkPixbuf.InterpType.BILINEAR)
            pixbuf = add_border_widget(pixbuf, self, None, round=True)
            thumb = get_pbosf_for_pixbuf(self, pixbuf)
        except (GLib.GError, IOError):
            pass
        else:
            def append(data):
                self.liststore.append(data)
            GLib.idle_add(append, [thumb, cover])
Example #20
0
        def cell_data_pb(column, cell, model, iter_, no_cover):
            album = model.get_album(iter_)

            if album is None:
                pixbuf = None
            elif album.cover:
                pixbuf = album.cover
                round_ = config.getboolean("albumart", "round")
                pixbuf = add_border_widget(pixbuf, self.view, round_)
                pixbuf = get_pbosf_for_pixbuf(self, pixbuf)
                # don't cache, too much state has an effect on the result
                self.__last_render_pb = None
            else:
                pixbuf = no_cover

            if self.__last_render_pb == pixbuf:
                return
            self.__last_render_pb = pixbuf
            set_renderer_from_pbosf(cell, pixbuf)
Example #21
0
    def __add_cover_to_list(self, cover):
        try:
            pbloader = GdkPixbuf.PixbufLoader()
            pbloader.write(get_url(cover['thumbnail'])[0])
            pbloader.close()

            scale_factor = get_scale_factor(self)
            size = self.THUMB_SIZE * scale_factor - scale_factor * 2
            pixbuf = pbloader.get_pixbuf().scale_simple(size, size,
                GdkPixbuf.InterpType.BILINEAR)
            pixbuf = thumbnails.add_border(
                pixbuf, 80, round=True, width=scale_factor)
            thumb = get_pbosf_for_pixbuf(self, pixbuf)
        except (GLib.GError, IOError):
            pass
        else:
            def append(data):
                self.liststore.append(data)
            GLib.idle_add(append, [thumb, cover])
Example #22
0
        def cell_data_pb(column, cell, model, iter_, no_cover):
            album = model.get_album(iter_)

            if album is None:
                pixbuf = None
            elif album.cover:
                pixbuf = album.cover
                round_ = config.getboolean("albumart", "round")
                pixbuf = add_border_widget(pixbuf, self.view, cell, round_)
                pixbuf = get_pbosf_for_pixbuf(self, pixbuf)
                # don't cache, too much state has an effect on the result
                self.__last_render_pb = None
            else:
                pixbuf = no_cover

            if self.__last_render_pb == pixbuf:
                return
            self.__last_render_pb = pixbuf
            set_renderer_from_pbosf(cell, pixbuf)
Example #23
0
    def __init__(self, conf, song):
        Gtk.Window.__init__(self, Gtk.WindowType.POPUP)
        self.set_type_hint(Gdk.WindowTypeHint.NOTIFICATION)

        screen = self.get_screen()
        rgba = screen.get_rgba_visual()
        if rgba is not None:
            self.set_visual(rgba)

        self.conf = conf
        self.iteration_source = None
        self.fading_in = False
        self.fade_start_time = 0

        mgeo = screen.get_monitor_geometry(conf.monitor)
        textwidth = mgeo.width - 2 * (self.BORDER + self.MARGIN)

        scale_factor = get_scale_factor(self)
        self.cover_pixbuf = app.cover_manager.get_pixbuf(
            song, conf.coversize * scale_factor, conf.coversize * scale_factor)
        coverheight = 0
        coverwidth = 0
        if self.cover_pixbuf:
            self.cover_pixbuf = get_pbosf_for_pixbuf(self, self.cover_pixbuf)
            coverwidth = self.cover_pixbuf.get_width() // scale_factor
            coverheight = self.cover_pixbuf.get_height() // scale_factor
            textwidth -= coverwidth + self.BORDER

        layout = self.create_pango_layout('')
        layout.set_alignment((Pango.Alignment.LEFT, Pango.Alignment.CENTER,
                              Pango.Alignment.RIGHT)[conf.align])
        layout.set_spacing(Pango.SCALE * 7)
        layout.set_font_description(Pango.FontDescription(conf.font))
        try:
            layout.set_markup(pattern.XMLFromMarkupPattern(conf.string) % song)
        except pattern.error:
            layout.set_markup("")
        layout.set_width(Pango.SCALE * textwidth)
        layoutsize = layout.get_pixel_size()
        if layoutsize[0] < textwidth:
            layout.set_width(Pango.SCALE * layoutsize[0])
            layoutsize = layout.get_pixel_size()
        self.title_layout = layout

        winw = layoutsize[0] + 2 * self.BORDER
        if coverwidth:
            winw += coverwidth + self.BORDER
        winh = max(coverheight, layoutsize[1]) + 2 * self.BORDER
        self.set_default_size(winw, winh)

        rect = namedtuple("Rect", ["x", "y", "width", "height"])
        rect.x = self.BORDER
        rect.y = (winh - coverheight) // 2
        rect.width = coverwidth
        rect.height = coverheight

        self.cover_rectangle = rect

        winx = int((mgeo.width - winw) * self.POS_X)
        winx = max(self.MARGIN, min(mgeo.width - self.MARGIN - winw, winx))
        winy = int((mgeo.height - winh) * conf.pos_y)
        winy = max(self.MARGIN, min(mgeo.height - self.MARGIN - winh, winy))
        self.move(winx + mgeo.x, winy + mgeo.y)
Example #24
0
 def test_get_pbosf_for_pixbuf(self):
     w = Gtk.Button()
     rgb = GdkPixbuf.Colorspace.RGB
     newpb = GdkPixbuf.Pixbuf.new(rgb, True, 8, 10, 10)
     pbosf = get_pbosf_for_pixbuf(w, newpb)
     self.assertTrue(isinstance(pbosf, (GdkPixbuf.Pixbuf, cairo.Surface)))
Example #25
0
 def test_get_pbosf_for_pixbuf(self):
     w = Gtk.Button()
     rgb = GdkPixbuf.Colorspace.RGB
     newpb = GdkPixbuf.Pixbuf.new(rgb, True, 8, 10, 10)
     pbosf = get_pbosf_for_pixbuf(w, newpb)
     self.assertTrue(isinstance(pbosf, (GdkPixbuf.Pixbuf, cairo.Surface)))
Example #26
0
    def __init__(self, conf, song):
        Gtk.Window.__init__(self, Gtk.WindowType.POPUP)
        self.set_type_hint(Gdk.WindowTypeHint.NOTIFICATION)

        screen = self.get_screen()
        rgba = screen.get_rgba_visual()
        if rgba is not None:
            self.set_visual(rgba)

        self.conf = conf
        self.iteration_source = None
        self.fading_in = False
        self.fade_start_time = 0

        mgeo = screen.get_monitor_geometry(conf.monitor)
        textwidth = mgeo.width - 2 * (self.BORDER + self.MARGIN)

        scale_factor = get_scale_factor(self)
        self.cover_pixbuf = app.cover_manager.get_pixbuf(
            song, conf.coversize * scale_factor, conf.coversize * scale_factor)
        coverheight = 0
        coverwidth = 0
        if self.cover_pixbuf:
            self.cover_pixbuf = get_pbosf_for_pixbuf(self, self.cover_pixbuf)
            coverwidth = self.cover_pixbuf.get_width() // scale_factor
            coverheight = self.cover_pixbuf.get_height() // scale_factor
            textwidth -= coverwidth + self.BORDER

        layout = self.create_pango_layout('')
        layout.set_alignment((Pango.Alignment.LEFT, Pango.Alignment.CENTER,
                              Pango.Alignment.RIGHT)[conf.align])
        layout.set_spacing(Pango.SCALE * 7)
        layout.set_font_description(Pango.FontDescription(conf.font))
        try:
            layout.set_markup(pattern.XMLFromMarkupPattern(conf.string) % song)
        except pattern.error:
            layout.set_markup("")
        layout.set_width(Pango.SCALE * textwidth)
        layoutsize = layout.get_pixel_size()
        if layoutsize[0] < textwidth:
            layout.set_width(Pango.SCALE * layoutsize[0])
            layoutsize = layout.get_pixel_size()
        self.title_layout = layout

        winw = layoutsize[0] + 2 * self.BORDER
        if coverwidth:
            winw += coverwidth + self.BORDER
        winh = max(coverheight, layoutsize[1]) + 2 * self.BORDER
        self.set_default_size(winw, winh)

        rect = namedtuple("Rect", ["x", "y", "width", "height"])
        rect.x = self.BORDER
        rect.y = (winh - coverheight) // 2
        rect.width = coverwidth
        rect.height = coverheight

        self.cover_rectangle = rect

        winx = int((mgeo.width - winw) * self.POS_X)
        winx = max(self.MARGIN, min(mgeo.width - self.MARGIN - winw, winx))
        winy = int((mgeo.height - winh) * conf.pos_y)
        winy = max(self.MARGIN, min(mgeo.height - self.MARGIN - winh, winy))
        self.move(winx + mgeo.x, winy + mgeo.y)