[gnome-music/wip/jfelder/gtk4-v3: 58/208] albumsview: Use CoverPaintable




commit a30574d33de719dfed569ed5a27cf08deb05f7e3
Author: Marinus Schraal <mschraal gnome org>
Date:   Sat May 15 15:31:39 2021 +0200

    albumsview: Use CoverPaintable

 gnomemusic/artcache.py         |  8 +++++++-
 gnomemusic/views/albumsview.py | 17 ++++++++++-------
 2 files changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/gnomemusic/artcache.py b/gnomemusic/artcache.py
index 86b7e1fb9..b3c769446 100644
--- a/gnomemusic/artcache.py
+++ b/gnomemusic/artcache.py
@@ -118,13 +118,19 @@ class ArtCache(GObject.GObject):
 
         # scale = self._widget.props.scale_factor
         # surface = Gdk.cairo_surface_create_from_pixbuf(pixbuf, scale, None)
+        texture = Gdk.Texture.new_for_pixbuf(pixbuf)
+        if (texture
+                and (isinstance(self._coreobject, CoreAlbum)
+                     or isinstance(self._coreobject, CoreSong))):
+            paintable = CoverPaintable(self._size, texture)
         # if isinstance(self._coreobject, CoreArtist):
         #     surface = make_icon_frame(
         #         surface, self._size, scale, round_shape=True)
         # elif (isinstance(self._coreobject, CoreAlbum)
         #         or isinstance(self._coreobject, CoreSong)):
         #     surface = make_icon_frame(surface, self._size, scale)
-        paintable = CoverPaintable(self._size)
+        else:
+            paintable = CoverPaintable(self._size)
 
         self._surface = paintable
 
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index dcfe943b4..53c3e4c6b 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -122,22 +122,25 @@ class AlbumsView(Gtk.Stack):
         if first_cover is None:
             return GLib.SOURCE_REMOVE
 
-        cover_size, _ = first_cover.get_allocated_size()
-        if cover_size.width == 0 or cover_size.height == 0:
+        cover_w = first_cover.get_allocated_width()
+        cover_h = first_cover.get_allocated_height()
+
+        if cover_w == 0 or cover_h == 0:
             return GLib.SOURCE_REMOVE
 
-        viewport_size, _ = self._viewport.get_allocated_size()
+        viewport_w = self._viewport.get_allocated_width()
+        viewport_h = self._viewport.get_allocated_height()
 
         h_space = self._flowbox.get_column_spacing()
         v_space = self._flowbox.get_row_spacing()
         nr_cols = (
-            (viewport_size.width + h_space) // (cover_size.width + h_space))
+            (viewport_w + h_space) // (cover_w + h_space))
 
         top_left_cover = self._flowbox.get_child_at_index(
-            nr_cols * (adjustment // (cover_size.height + v_space)))
+            nr_cols * (adjustment // (cover_h + v_space)))
 
-        covers_col = math.ceil(viewport_size.width / cover_size.width)
-        covers_row = math.ceil(viewport_size.height / cover_size.height)
+        covers_col = math.ceil(viewport_w / cover_w)
+        covers_row = math.ceil(viewport_h / cover_h)
 
         children = self._flowbox.get_children()
         retrieve_list = []


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]