def do_own_render(self, ctx, widget, cell_area, size): surface = None if self.rowid in self.__surfaces.keys(): surface = self.__surfaces[self.rowid] if surface is None: for suffix in ["lastfm", "deezer", "spotify", "wikipedia"]: uri = InfoCache.get_artwork(self.artist, suffix, size) if uri is not None: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( uri, size, size) surface = Gdk.cairo_surface_create_from_pixbuf( pixbuf, self.__scale_factor, None) del pixbuf self.__surfaces[self.rowid] = surface break if surface is None: surface = Gtk.IconTheme.get_default().load_surface( 'avatar-default-symbolic', ArtSize.ARTIST_SMALL, 1, widget.get_window(), 0) ctx.translate(cell_area.x, cell_area.y) ctx.new_sub_path() radius = ArtSize.ARTIST_SMALL / 2 ctx.arc(ArtSize.ARTIST_SMALL / 2, ArtSize.ARTIST_SMALL / 2, radius, 0, 2 * pi) ctx.set_source_rgb(1, 1, 1) ctx.fill_preserve() ctx.set_line_width(2) ctx.set_source_rgba(0, 0, 0, 0.3) ctx.stroke_preserve() ctx.set_source_surface(surface, 0, 0) del surface ctx.clip() ctx.paint()
def __set_artwork(self): """ Set artist artwork """ artwork_height = 0 if Lp().settings.get_value("artist-artwork"): if len(self._artist_ids) == 1 and\ Lp().settings.get_value("artist-artwork"): artist = Lp().artists.get_name(self._artist_ids[0]) size = ArtSize.ARTIST_SMALL * 2 * self.__scale_factor for suffix in ["lastfm", "spotify", "wikipedia"]: uri = InfoCache.get_artwork(artist, suffix, size) if uri is not None: f = Gio.File.new_for_path(uri) (status, data, tag) = f.load_contents(None) if not status: continue bytes = GLib.Bytes(data) stream = Gio.MemoryInputStream.new_from_bytes(bytes) bytes.unref() pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale( stream, size, size, True, None) stream.close() surface = Gdk.cairo_surface_create_from_pixbuf( pixbuf, self.__scale_factor, None) self.__artwork.set_from_surface(surface) artwork_height = ArtSize.ARTIST_SMALL * 2 self.__artwork.get_style_context().remove_class( "artwork-icon") self.__artwork.show() self.__artwork_box.show() break # Add a default icon if len(self._artist_ids) == 1 and artwork_height == 0: self.__artwork.set_from_icon_name( "avatar-default-symbolic", Gtk.IconSize.DND) artwork_height = 32 self.__artwork.get_style_context().add_class("artwork-icon") self.__artwork.show() self.__artwork_box.show() # Create an self.__empty widget with header height ctx = self.__label.get_pango_context() layout = Pango.Layout.new(ctx) layout.set_text("a", 1) # Font scale 2 font_height = int(layout.get_pixel_size()[1]) * 2 if artwork_height > font_height: self.__empty.set_property("height-request", artwork_height) else: self.__empty.set_property("height-request", font_height)
def __set_artwork(self): """ Set artist artwork """ artwork_height = 0 if Lp().settings.get_value('artist-artwork'): if len(self._artist_ids) == 1 and\ Lp().settings.get_value('artist-artwork'): artist = Lp().artists.get_name(self._artist_ids[0]) size = ArtSize.ARTIST_SMALL * 2 * self.__scale_factor for suffix in ["lastfm", "spotify", "wikipedia"]: uri = InfoCache.get_artwork(artist, suffix, size) if uri is not None: f = Lio.File.new_for_path(uri) (status, data, tag) = f.load_contents(None) stream = Gio.MemoryInputStream.new_from_data(data, None) pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale( stream, size, size, True, None) stream.close() surface = Gdk.cairo_surface_create_from_pixbuf( pixbuf, self.__scale_factor, None) del pixbuf self.__artwork.set_from_surface(surface) del surface artwork_height = ArtSize.ARTIST_SMALL * 2 self.__artwork.get_style_context().remove_class( 'artwork-icon') self.__artwork.show() self.__artwork_box.show() break # Add a default icon if len(self._artist_ids) == 1 and artwork_height == 0: self.__artwork.set_from_icon_name( 'avatar-default-symbolic', Gtk.IconSize.DND) artwork_height = 32 self.__artwork.get_style_context().add_class('artwork-icon') self.__artwork.show() self.__artwork_box.show() # Create an self.__empty widget with header height ctx = self.__label.get_pango_context() layout = Pango.Layout.new(ctx) layout.set_text("a", 1) # Font scale 2 font_height = int(layout.get_pixel_size()[1]) * 2 if artwork_height > font_height: self.__empty.set_property('height-request', artwork_height) else: self.__empty.set_property('height-request', font_height)
def _set_artwork(self): """ Set artist artwork """ artwork_height = 0 if Lp().settings.get_value('artist-artwork'): if len(self._artist_ids) == 1 and\ Lp().settings.get_value('artist-artwork'): artist = Lp().artists.get_name(self._artist_ids[0]) for suffix in ["lastfm", "spotify", "wikipedia"]: uri = InfoCache.get_artwork( artist, suffix, ArtSize.ARTIST_SMALL * 2 * self._artwork.get_scale_factor()) if uri is not None: self._artwork.set_from_file(uri) artwork_height = ArtSize.ARTIST_SMALL * 2 self._artwork.get_style_context().remove_class( 'artwork-icon') self._artwork.show() self._artwork_box.show() break # Add a default icon if len(self._artist_ids) == 1 and artwork_height == 0: self._artwork.set_from_icon_name( 'avatar-default-symbolic', Gtk.IconSize.DND) artwork_height = 32 self._artwork.get_style_context().add_class('artwork-icon') self._artwork.show() self._artwork_box.show() # Create an self._empty widget with header height ctx = self._label.get_pango_context() layout = Pango.Layout.new(ctx) layout.set_text("a", 1) # Font scale 2 font_height = int(layout.get_pixel_size()[1]) * 2 if artwork_height > font_height: self._empty.set_property('height-request', artwork_height) else: self._empty.set_property('height-request', font_height)
def do_own_render(self, ctx, widget, cell_area, size): surface = None alpha = False if self.rowid in self._surfaces.keys(): surface = self._surfaces[self.rowid] if surface is None: for suffix in ["lastfm", "spotify", "wikipedia"]: uri = InfoCache.get_artwork(self.artist, suffix, size) if uri is not None: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(uri, size, size) surface = Gdk.cairo_surface_create_from_pixbuf( pixbuf, widget.get_scale_factor(), None) self._surfaces[self.rowid] = surface del pixbuf break if surface is None: alpha = True surface = Gtk.IconTheme.get_default().load_surface( 'media-optical-cd-audio-symbolic', ArtSize.ARTIST_SMALL, 1, widget.get_window(), 0) ctx.translate(cell_area.x, cell_area.y) ctx.new_sub_path() radius = ArtSize.ARTIST_SMALL / 2 ctx.arc(ArtSize.ARTIST_SMALL/2, ArtSize.ARTIST_SMALL/2, radius, 0, 2 * pi) ctx.set_source_rgb(1, 1, 1) ctx.fill_preserve() ctx.set_line_width(2) ctx.set_source_rgba(0, 0, 0, 0.3) ctx.stroke_preserve() ctx.set_source_surface(surface, 0, 0) ctx.clip() if alpha: ctx.paint_with_alpha(0.5) else: ctx.paint()
def __set_artwork(self): """ Set artist artwork """ artwork_height = 0 if Lp().settings.get_value('artist-artwork'): if len(self._artist_ids) == 1 and\ Lp().settings.get_value('artist-artwork'): artist = Lp().artists.get_name(self._artist_ids[0]) for suffix in ["lastfm", "spotify", "wikipedia"]: uri = InfoCache.get_artwork( artist, suffix, ArtSize.ARTIST_SMALL * 2 * self.__artwork.get_scale_factor()) if uri is not None: self.__artwork.set_from_file(uri) artwork_height = ArtSize.ARTIST_SMALL * 2 self.__artwork.get_style_context().remove_class( 'artwork-icon') self.__artwork.show() self.__artwork_box.show() break # Add a default icon if len(self._artist_ids) == 1 and artwork_height == 0: self.__artwork.set_from_icon_name('avatar-default-symbolic', Gtk.IconSize.DND) artwork_height = 32 self.__artwork.get_style_context().add_class('artwork-icon') self.__artwork.show() self.__artwork_box.show() # Create an self.__empty widget with header height ctx = self.__label.get_pango_context() layout = Pango.Layout.new(ctx) layout.set_text("a", 1) # Font scale 2 font_height = int(layout.get_pixel_size()[1]) * 2 if artwork_height > font_height: self.__empty.set_property('height-request', artwork_height) else: self.__empty.set_property('height-request', font_height)
def __init__(self, artist_ids, genre_ids): """ Init ArtistView @param artist id as int (Current if None) @param genre id as int """ ArtistAlbumsView.__init__(self, artist_ids, genre_ids) self._signal_id = None self._artist_ids = artist_ids empty = Gtk.Grid() empty.set_property('height-request', ArtSize.ARTIST_SMALL * 2) empty.show() self._albumbox.add(empty) builder = Gtk.Builder() builder.add_from_resource('/org/gnome/Lollypop/ArtistView.ui') builder.connect_signals(self) self._artwork = builder.get_object('artwork') self._jump_button = builder.get_object('jump-button') self._jump_button.set_tooltip_text(_("Go to current track")) self._spinner = builder.get_object('spinner') header = builder.get_object('header') header.set_property('valign', Gtk.Align.START) self._overlay.add_overlay(header) self._overlay.set_overlay_pass_through(header, True) if len(artist_ids) == 1 and Lp().settings.get_value('artist-artwork'): artist = Lp().artists.get_name(artist_ids[0]) for suffix in ["lastfm", "spotify", "wikipedia"]: uri = InfoCache.get_artwork(artist, suffix, ArtSize.ARTIST_SMALL * 2 * self._artwork.get_scale_factor()) if uri is not None: self._artwork.set_from_file(uri) self._artwork.show() break artists = [] for artist_id in artist_ids: artists.append(Lp().artists.get_name(artist_id)) builder.get_object('artist').set_label(", ".join(artists))