[gnome-music/wip/mschraal/gtk4-v2: 28/55] Add CoverPaintable for art (FIXME)




commit fcf8400a2663b32b2f3a4d7bbc2d80a78096c376
Author: Marinus Schraal <mschraal gnome org>
Date:   Mon Apr 12 16:12:34 2021 +0200

    Add CoverPaintable for art (FIXME)

 gnomemusic/artcache.py         | 35 ++++++++++++++++-------------
 gnomemusic/coverpaintable.py   | 51 ++++++++++++++++++++++++++++++++++++++++++
 gnomemusic/widgets/artstack.py |  6 ++---
 3 files changed, 73 insertions(+), 19 deletions(-)
---
diff --git a/gnomemusic/artcache.py b/gnomemusic/artcache.py
index d512c4e1f..079597c89 100644
--- a/gnomemusic/artcache.py
+++ b/gnomemusic/artcache.py
@@ -32,6 +32,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.musiclogger import MusicLogger
 from gnomemusic.utils import ArtSize
 
@@ -113,14 +114,15 @@ class DefaultIcon(GObject.GObject):
         super().__init__()
 
     def _make_default_icon(self, icon_type, art_size, scale, round_shape):
-        icon_info = self._default_theme.lookup_icon(
-            icon_type.value, None, art_size.width / 3, scale, 0, 0)
-        icon = icon_info.load_surface()
+        # icon_info = self._default_theme.lookup_icon(
+        #     icon_type.value, None, art_size.width / 3, scale, 0, 0)
+        # icon = icon_info.load_surface()
 
-        icon_surface = _make_icon_frame(
-            icon, art_size, scale, True, round_shape=round_shape)
+        # icon_surface = _make_icon_frame(
+        #     icon, art_size, scale, True, round_shape=round_shape)
+        paintable = CoverPaintable(art_size)
 
-        return icon_surface
+        return paintable
 
     def get(self, icon_type, art_size, scale=1, round_shape=False):
         """Returns the requested symbolic icon
@@ -219,16 +221,17 @@ class ArtCache(GObject.GObject):
 
         stream.close_async(GLib.PRIORITY_LOW, None, self._close_stream, None)
 
-        surface = Gdk.cairo_surface_create_from_pixbuf(
-            pixbuf, self._scale, None)
-        if isinstance(self._coreobject, CoreArtist):
-            surface = _make_icon_frame(
-                surface, self._size, self._scale, round_shape=True)
-        elif (isinstance(self._coreobject, CoreAlbum)
-                or isinstance(self._coreobject, CoreSong)):
-            surface = _make_icon_frame(surface, self._size, self._scale)
-
-        self.emit("result", surface)
+        # surface = Gdk.cairo_surface_create_from_pixbuf(
+        #     pixbuf, self._scale, None)
+        # if isinstance(self._coreobject, CoreArtist):
+        #     surface = _make_icon_frame(
+        #         surface, self._size, self._scale, round_shape=True)
+        # elif (isinstance(self._coreobject, CoreAlbum)
+        #         or isinstance(self._coreobject, CoreSong)):
+        #     surface = _make_icon_frame(surface, self._size, self._scale)
+        paintable = CoverPaintable(self._size)
+
+        self.emit("result", paintable)
 
     def _close_stream(self, stream, result, data):
         try:
diff --git a/gnomemusic/coverpaintable.py b/gnomemusic/coverpaintable.py
new file mode 100644
index 000000000..47666a6c7
--- /dev/null
+++ b/gnomemusic/coverpaintable.py
@@ -0,0 +1,51 @@
+from math import pi
+
+import gi
+gi.require_versions({"Gdk": "4.0", "Gtk": "4.0"})
+from gi.repository import Gtk, GObject, Graphene, Gdk
+
+
+from gnomemusic.utils import ArtSize
+
+
+class CoverPaintable(GObject.GObject, Gdk.Paintable):
+
+    __gtype_name__ = "CoverPaintable"
+
+    def __init__(self, art_size):
+        super().__init__()
+
+        self._art_size = art_size
+        print("CoverPaintable")
+
+    def do_snapshot(self, snapshot, width, height):
+        width = self._art_size.width
+        height = self._art_size.height
+        w = width
+        h = height
+
+        degrees = pi / 180
+        if self._art_size == ArtSize.SMALL:
+            radius = 2
+        else:
+            radius = 8
+        # icon_w = icon_surface.get_width()
+        # icon_h = icon_surface.get_height()
+        ratio = h / w
+
+        theme = Gtk.IconTheme.new()
+
+        icon_pt = theme.lookup_icon(
+            "folder-music-symbolic", None, w, 1, 0, 0)
+
+        icon_pt.snapshot(snapshot, w, h)
+
+    def do_get_flags(self):
+        return Gdk.PaintableFlags.SIZE | Gdk.PaintableFlags.CONTENTS
+
+    def do_get_intrinsic_height(self):
+        return self._art_size.height
+
+    def do_get_intrinsic_width(self):
+        return self._art_size.width
+
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index 129b67a81..ca94124c6 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -107,12 +107,12 @@ class ArtStack(Gtk.Stack):
 
         self._cache.query(coreobject)
 
-    def _on_cache_result(self, cache, surface):
+    def _on_cache_result(self, cache, paintable):
         if self.props.visible_child_name == "B":
-            self._cover_a.props.surface = surface
+            self._cover_a.props.paintable = paintable
             self.props.visible_child_name = "A"
         else:
-            self._cover_b.props.surface = surface
+            self._cover_b.props.paintable = paintable
             self.props.visible_child_name = "B"
 
     def _on_destroy(self, widget):


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