[gnome-music/wip/jfelder/gtk4-v3: 104/115] coverpaintable: Pass icon type




commit f23b1d9d1fb3fca7c1bdce90fc02314e4a6a437c
Author: Marinus Schraal <mschraal gnome org>
Date:   Sat Feb 5 14:17:40 2022 +0100

    coverpaintable: Pass icon type

 gnomemusic/artcache.py       | 23 ++++++++++-------------
 gnomemusic/coverpaintable.py | 18 +++++++++++++++---
 gnomemusic/defaulticon.py    |  2 +-
 3 files changed, 26 insertions(+), 17 deletions(-)
---
diff --git a/gnomemusic/artcache.py b/gnomemusic/artcache.py
index 891cb0674..e31ad30d6 100644
--- a/gnomemusic/artcache.py
+++ b/gnomemusic/artcache.py
@@ -24,9 +24,7 @@
 
 from gi.repository import Gdk, GdkPixbuf, Gio, Gtk, GLib, GObject
 
-from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.coreartist import CoreArtist
-from gnomemusic.coresong import CoreSong
 from gnomemusic.coverpaintable import CoverPaintable
 from gnomemusic.defaulticon import DefaultIcon
 from gnomemusic.musiclogger import MusicLogger
@@ -60,6 +58,7 @@ class ArtCache(GObject.GObject):
 
         self._coreobject = None
         self._default_icon = None
+        self._icon_type = DefaultIconType.ALBUM
         self._surface = None
 
     def start(self, coreobject, size):
@@ -72,12 +71,10 @@ class ArtCache(GObject.GObject):
         self._size = size
 
         if isinstance(coreobject, CoreArtist):
-            self._default_icon = DefaultIcon(self._widget).get(
-                DefaultIconType.ARTIST, self._size)
-        elif (isinstance(coreobject, CoreAlbum)
-                or isinstance(coreobject, CoreSong)):
-            self._default_icon = DefaultIcon(self._widget).get(
-                DefaultIconType.ALBUM, self._size)
+            self._icon_type = DefaultIconType.ARTIST
+
+        self._default_icon = DefaultIcon(self._widget).get(
+            self._icon_type, self._size)
 
         thumbnail_uri = coreobject.props.thumbnail
         if thumbnail_uri == "generic":
@@ -117,12 +114,12 @@ class ArtCache(GObject.GObject):
             GLib.PRIORITY_DEFAULT_IDLE, 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, self._widget, texture)
+        if texture:
+            paintable = CoverPaintable(
+                self._size, self._widget, icon_type=self._icon_type,
+                texture=texture)
         else:
-            paintable = CoverPaintable(self._size, self._widget)
+            paintable = self._default_icon
 
         self._surface = paintable
 
diff --git a/gnomemusic/coverpaintable.py b/gnomemusic/coverpaintable.py
index 8b02cc65d..4507bf6e3 100644
--- a/gnomemusic/coverpaintable.py
+++ b/gnomemusic/coverpaintable.py
@@ -2,6 +2,8 @@ import gi
 gi.require_versions({"Gdk": "4.0", "Gtk": "4.0", "Gsk": "4.0"})
 from gi.repository import Gsk, Gtk, GObject, Graphene, Gdk
 
+from gnomemusic.utils import ArtSize, DefaultIconType
+
 
 class CoverPaintable(GObject.GObject, Gdk.Paintable):
 
@@ -9,17 +11,27 @@ class CoverPaintable(GObject.GObject, Gdk.Paintable):
 
     _icon_theme = Gtk.IconTheme.new()
 
-    def __init__(self, art_size, widget, texture=None):
+    def __init__(
+            self, art_size, widget, icon_type=DefaultIconType.ALBUM,
+            texture=None):
         super().__init__()
 
         self._art_size = art_size
+        self._icon_type = icon_type
         self._texture = texture
         self._widget = widget
 
     def do_snapshot(self, snapshot, w, h):
+        if self._icon_type == DefaultIconType.ARTIST:
+            radius = 90
+        elif self._art_size == ArtSize.SMALL:
+            radius = 4.5
+        else:
+            radius = 9
+
         rect = Graphene.Rect().init(0, 0, w, h)
         rounded_rect = Gsk.RoundedRect()
-        rounded_rect.init_from_rect(rect, 9)
+        rounded_rect.init_from_rect(rect, radius)
         snapshot.push_rounded_clip(rounded_rect)
 
         if self._texture is not None:
@@ -29,7 +41,7 @@ class CoverPaintable(GObject.GObject, Gdk.Paintable):
         else:
             i_s = 1 / 3  # Icon scale
             icon_pt = self._icon_theme.lookup_icon(
-                "folder-music-symbolic", None, w * i_s,
+                self._icon_type.value, None, w * i_s,
                 self._widget.props.scale_factor, 0, 0)
 
             snapshot.append_color(
diff --git a/gnomemusic/defaulticon.py b/gnomemusic/defaulticon.py
index c2536aa2f..8027577ed 100644
--- a/gnomemusic/defaulticon.py
+++ b/gnomemusic/defaulticon.py
@@ -49,7 +49,7 @@ class DefaultIcon(GObject.GObject):
     def _make_default_icon(
             self, icon_type: DefaultIconType, art_size: ArtSize, scale: int,
             dark: bool) -> cairo.ImageSurface:
-        paintable = CoverPaintable(art_size, self._widget)
+        paintable = CoverPaintable(art_size, self._widget, icon_type=icon_type)
 
         return paintable
 


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