[gnome-music/wip/mschraal/gtk4-v2: 49/55] albumsview: Use CoverPaintable




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

    albumsview: Use CoverPaintable

 gnomemusic/artcache.py         | 11 ++++++++++-
 gnomemusic/views/albumsview.py | 17 ++++++++++-------
 2 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/gnomemusic/artcache.py b/gnomemusic/artcache.py
index 079597c89..7b0032998 100644
--- a/gnomemusic/artcache.py
+++ b/gnomemusic/artcache.py
@@ -221,6 +221,14 @@ class ArtCache(GObject.GObject):
 
         stream.close_async(GLib.PRIORITY_LOW, None, self._close_stream, 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)
+            # surface = _make_icon_frame(surface, self._size, self._scale)
+
         # surface = Gdk.cairo_surface_create_from_pixbuf(
         #     pixbuf, self._scale, None)
         # if isinstance(self._coreobject, CoreArtist):
@@ -229,7 +237,8 @@ class ArtCache(GObject.GObject):
         # elif (isinstance(self._coreobject, CoreAlbum)
         #         or isinstance(self._coreobject, CoreSong)):
         #     surface = _make_icon_frame(surface, self._size, self._scale)
-        paintable = CoverPaintable(self._size)
+        else:
+            paintable = CoverPaintable(self._size)
 
         self.emit("result", paintable)
 
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index c5981e6bd..5be7629cc 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -117,22 +117,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]