[gnome-music/wip/mschraal/gtk4-v2: 81/89] albumsview: Fix coverloading code a bit
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/gtk4-v2: 81/89] albumsview: Fix coverloading code a bit
- Date: Mon, 10 May 2021 10:39:02 +0000 (UTC)
commit 3f7928860d652aba78c988e9532ffa10d3684c9f
Author: Marinus Schraal <mschraal gnome org>
Date: Tue Apr 13 00:56:15 2021 +0200
albumsview: Fix coverloading code a bit
gnomemusic/artcache.py | 11 ++++++++++-
gnomemusic/coverpaintable.py | 41 +++++++++++++++++++++++++++--------------
gnomemusic/views/albumsview.py | 17 ++++++++++-------
3 files changed, 47 insertions(+), 22 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/coverpaintable.py b/gnomemusic/coverpaintable.py
index 47666a6c7..545bb8370 100644
--- a/gnomemusic/coverpaintable.py
+++ b/gnomemusic/coverpaintable.py
@@ -2,7 +2,7 @@ from math import pi
import gi
gi.require_versions({"Gdk": "4.0", "Gtk": "4.0"})
-from gi.repository import Gtk, GObject, Graphene, Gdk
+from gi.repository import Gsk, Gtk, GObject, Graphene, Gdk
from gnomemusic.utils import ArtSize
@@ -12,11 +12,11 @@ class CoverPaintable(GObject.GObject, Gdk.Paintable):
__gtype_name__ = "CoverPaintable"
- def __init__(self, art_size):
+ def __init__(self, art_size, texture=None):
super().__init__()
+ self._texture = texture
self._art_size = art_size
- print("CoverPaintable")
def do_snapshot(self, snapshot, width, height):
width = self._art_size.width
@@ -24,21 +24,34 @@ class CoverPaintable(GObject.GObject, Gdk.Paintable):
w = width
h = height
- degrees = pi / 180
- if self._art_size == ArtSize.SMALL:
- radius = 2
+ if self._texture is not None:
+ rect = Graphene.Rect().init(0, 0, w, h)
+ rgba = Gdk.RGBA(1.0, 1.0, 1.0, 0.5)
+
+ # snapshot.append_color(rgba, rect)
+ snapshot.append_texture(self._texture, rect)
+
+ # gs = Graphene.Size().init(10.0, 10.0)
+ # gskrr = Gsk.RoundedRect().init(
+ # rect, gs, gs, gs, gs)
+ # snapshot.push_rounded_clip(gskrr)
+ # snapshot.append_color(rgba, rect)
+ # snapshot.pop()
else:
- radius = 8
- # icon_w = icon_surface.get_width()
- # icon_h = icon_surface.get_height()
- ratio = h / w
+ degrees = pi / 180
+ if self._art_size == ArtSize.SMALL:
+ radius = 2
+ else:
+ radius = 8
+
+ ratio = h / w
- theme = Gtk.IconTheme.new()
+ theme = Gtk.IconTheme.new()
- icon_pt = theme.lookup_icon(
- "folder-music-symbolic", None, w, 1, 0, 0)
+ icon_pt = theme.lookup_icon(
+ "folder-music-symbolic", None, w, 1, 0, 0)
- icon_pt.snapshot(snapshot, w, h)
+ icon_pt.snapshot(snapshot, w, h)
def do_get_flags(self):
return Gdk.PaintableFlags.SIZE | Gdk.PaintableFlags.CONTENTS
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index d086350d4..c9dd0a4c4 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -114,22 +114,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]