Do not try to convert default icon to GDK pixbuf (close #110)

This commit is contained in:
Olli 2026-01-10 15:42:24 +01:00
commit 9311f9974a
4 changed files with 35 additions and 26 deletions

View file

@ -236,6 +236,7 @@ class CoverPanel(Gtk.Overlay):
pixbuf = self._cover_pixbuf pixbuf = self._cover_pixbuf
# Check pixelbuffer # Check pixelbuffer
if pixbuf is None: if pixbuf is None:
self.cover_default.set_pixel_size(min(size_width, size_height)/2)
return return
# Skalierungswert für Breite und Höhe ermitteln # Skalierungswert für Breite und Höhe ermitteln

View file

@ -293,15 +293,13 @@ class LibraryPanel(Adw.Bin):
def set_albumart(self, album, data): def set_albumart(self, album, data):
if album in self._selected_albums: if album in self._selected_albums:
self._standalone_pixbuf = None
if data: if data:
# Load image and draw it # Load image and draw it
try: try:
self._standalone_pixbuf = Utils.load_pixbuf(data) self._standalone_pixbuf = Utils.load_pixbuf(data)
except Exception: except Exception:
self._logger.exception("Failed to set albumart") self._logger.exception("Failed to set albumart")
self._standalone_pixbuf = self._get_default_image()
else:
self._standalone_pixbuf = self._get_default_image()
# Show image # Show image
GObject.idle_add(self._show_image) GObject.idle_add(self._show_image)
@ -335,6 +333,8 @@ class LibraryPanel(Adw.Bin):
self._grid_pixbufs.clear() self._grid_pixbufs.clear()
for album_id in albums.keys(): for album_id in albums.keys():
album = albums[album_id] album = albums[album_id]
grid_item = GridItem(album)
pixbuf = None pixbuf = None
try: try:
pixbuf = Utils.load_thumbnail(cache, self._client, album, size) pixbuf = Utils.load_thumbnail(cache, self._client, album, size)
@ -344,14 +344,13 @@ class LibraryPanel(Adw.Bin):
except Exception as e: except Exception as e:
self._logger.exception("Failed to load albumart", e) self._logger.exception("Failed to load albumart", e)
if pixbuf is None: if pixbuf is None:
pixbuf = self._icon_theme.lookup_icon( icon = self._get_default_icon(self._item_size, self._item_size)
Utils.STOCK_ICON_DEFAULT, None, self._item_size, grid_item.set_icon(icon)
self._item_size, Gtk.TextDirection.LTR, else:
Gtk.IconLookupFlags.FORCE_SYMBOLIC)
if pixbuf is not None:
self._grid_pixbufs[album.get_id()] = pixbuf self._grid_pixbufs[album.get_id()] = pixbuf
GObject.idle_add(self._library_grid_model.append, grid_item.set_cover(pixbuf)
GridItem(album, pixbuf))
GObject.idle_add(self._library_grid_model.append, grid_item)
i += 1 i += 1
GObject.idle_add(self.progress_bar.set_fraction, i / n) GObject.idle_add(self.progress_bar.set_fraction, i / n)
@ -440,6 +439,9 @@ class LibraryPanel(Adw.Bin):
pixbuf = self._standalone_pixbuf pixbuf = self._standalone_pixbuf
# Check pixelbuffer # Check pixelbuffer
if pixbuf is None: if pixbuf is None:
icon = self._get_default_icon(size_width, size_height)
self.standalone_image.set_from_paintable(icon)
self.standalone_image.set_pixel_size(min(size_width, size_height)/2)
return return
# Skalierungswert für Breite und Höhe ermitteln # Skalierungswert für Breite und Höhe ermitteln
@ -459,9 +461,10 @@ class LibraryPanel(Adw.Bin):
self.standalone_image.set_pixel_size(min(width, height)) self.standalone_image.set_pixel_size(min(width, height))
self.standalone_image.show() self.standalone_image.show()
def _get_default_image(self): def _get_default_icon(self, width, height):
return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None, return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None,
512, 512, Gtk.TextDirection.LTR, width, height,
Gtk.TextDirection.LTR,
Gtk.IconLookupFlags.FORCE_SYMBOLIC) Gtk.IconLookupFlags.FORCE_SYMBOLIC)
def _get_selected_albums(self): def _get_selected_albums(self):

View file

@ -171,15 +171,13 @@ class PlaylistPanel(Adw.Bin):
def set_albumart(self, album, data): def set_albumart(self, album, data):
if album in self._selected_albums: if album in self._selected_albums:
self._standalone_pixbuf = None
if data: if data:
# Load image and draw it # Load image and draw it
try: try:
self._standalone_pixbuf = Utils.load_pixbuf(data) self._standalone_pixbuf = Utils.load_pixbuf(data)
except Exception: except Exception:
self._logger.exception("Failed to set albumart") self._logger.exception("Failed to set albumart")
self._cover_pixbuf = self._get_default_image()
else:
self._cover_pixbuf = self._get_default_image()
# Show image # Show image
GObject.idle_add(self._show_image) GObject.idle_add(self._show_image)
@ -197,6 +195,8 @@ class PlaylistPanel(Adw.Bin):
cache = client.MCGCache(host, size) cache = client.MCGCache(host, size)
for album in playlist: for album in playlist:
grid_item = GridItem(album)
pixbuf = None pixbuf = None
# Load albumart thumbnail # Load albumart thumbnail
try: try:
@ -207,12 +207,12 @@ class PlaylistPanel(Adw.Bin):
except Exception: except Exception:
self._logger.exception("Failed to load albumart") self._logger.exception("Failed to load albumart")
if pixbuf is None: if pixbuf is None:
pixbuf = self._icon_theme.lookup_icon( icon = self._get_default_icon(self._item_size, self._item_size)
Utils.STOCK_ICON_DEFAULT, None, self._item_size, grid_item.set_icon(icon)
self._item_size, Gtk.TextDirection.LTR, else:
Gtk.IconLookupFlags.FORCE_SYMBOLIC) grid_item.set_cover(pixbuf)
if pixbuf is not None:
self._playlist_grid_model.append(GridItem(album, pixbuf)) GObject.idle_add(self._playlist_grid_model.append, grid_item)
if self._playlist_stop.is_set(): if self._playlist_stop.is_set():
self._playlist_lock.release() self._playlist_lock.release()
@ -247,6 +247,9 @@ class PlaylistPanel(Adw.Bin):
pixbuf = self._standalone_pixbuf pixbuf = self._standalone_pixbuf
# Check pixelbuffer # Check pixelbuffer
if pixbuf is None: if pixbuf is None:
icon = self._get_default_icon(size_width, size_height)
self.standalone_image.set_from_paintable(icon)
self.standalone_image.set_pixel_size(min(size_width, size_height)/2)
return return
# Skalierungswert für Breite und Höhe ermitteln # Skalierungswert für Breite und Höhe ermitteln
@ -266,9 +269,10 @@ class PlaylistPanel(Adw.Bin):
self.standalone_image.set_pixel_size(min(width, height)) self.standalone_image.set_pixel_size(min(width, height))
self.standalone_image.show() self.standalone_image.show()
def _get_default_image(self): def _get_default_icon(self, width, height):
return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None, return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None,
512, 512, Gtk.TextDirection.LTR, width, height,
Gtk.TextDirection.LTR,
Gtk.IconLookupFlags.FORCE_SYMBOLIC) Gtk.IconLookupFlags.FORCE_SYMBOLIC)
def _get_selected_albums(self): def _get_selected_albums(self):

View file

@ -86,11 +86,9 @@ class GridItem(GObject.GObject):
tooltip = GObject.Property(type=str, default=None) tooltip = GObject.Property(type=str, default=None)
cover = GObject.Property(type=Gdk.Paintable, default=None) cover = GObject.Property(type=Gdk.Paintable, default=None)
def __init__(self, album, cover): def __init__(self, album):
super().__init__() super().__init__()
self._album = album self._album = album
if cover:
self.cover = Gdk.Texture.new_for_pixbuf(cover)
self.tooltip = GObject.markup_escape_text("\n".join([ self.tooltip = GObject.markup_escape_text("\n".join([
album.get_title(), ', '.join(album.get_dates()), album.get_title(), ', '.join(album.get_dates()),
Utils.create_artists_label(album), Utils.create_artists_label(album),
@ -103,6 +101,9 @@ class GridItem(GObject.GObject):
def set_cover(self, cover): def set_cover(self, cover):
self.cover = Gdk.Texture.new_for_pixbuf(cover) self.cover = Gdk.Texture.new_for_pixbuf(cover)
def set_icon(self, icon):
self.cover = icon
class SearchFilter(Gtk.Filter): class SearchFilter(Gtk.Filter):