[gnome-music/wip/jfelder/gtk4-v3: 54/112] Add CoverPaintable for art (FIXME)
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/gtk4-v3: 54/112] Add CoverPaintable for art (FIXME)
- Date: Wed, 2 Feb 2022 23:32:38 +0000 (UTC)
commit 7d0505ceeff24a6f0c05de380ede7887f571d004
Author: Marinus Schraal <mschraal gnome org>
Date: Mon Apr 12 16:12:34 2021 +0200
Add CoverPaintable for art (FIXME)
Very simple implementation.
Anything Gsk related seems to fail, which limits abilities for now.
gnomemusic/artcache.py | 24 +++++++++++----------
gnomemusic/coverpaintable.py | 49 ++++++++++++++++++++++++++++++++++++++++++
gnomemusic/defaulticon.py | 14 ++++++------
gnomemusic/widgets/artstack.py | 6 +++---
4 files changed, 73 insertions(+), 20 deletions(-)
---
diff --git a/gnomemusic/artcache.py b/gnomemusic/artcache.py
index 9162c19ee..060cfbc12 100644
--- a/gnomemusic/artcache.py
+++ b/gnomemusic/artcache.py
@@ -27,7 +27,8 @@ from gi.repository import Gdk, GdkPixbuf, Gio, GLib, GObject
from gnomemusic.corealbum import CoreAlbum
from gnomemusic.coreartist import CoreArtist
from gnomemusic.coresong import CoreSong
-from gnomemusic.defaulticon import DefaultIcon, make_icon_frame
+from gnomemusic.coverpaintable import CoverPaintable
+from gnomemusic.defaulticon import DefaultIcon
from gnomemusic.musiclogger import MusicLogger
from gnomemusic.utils import ArtSize
@@ -113,16 +114,17 @@ class ArtCache(GObject.GObject):
stream.close_async(
GLib.PRIORITY_DEFAULT_IDLE, 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._surface = 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._surface = 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..2ee97b30f
--- /dev/null
+++ b/gnomemusic/coverpaintable.py
@@ -0,0 +1,49 @@
+import gi
+gi.require_versions({"Gdk": "4.0", "Gtk": "4.0"})
+# from gi.repository import Gsk, Gtk, GObject, Graphene, Gdk
+from gi.repository import Gtk, GObject, Graphene, Gdk
+
+
+class CoverPaintable(GObject.GObject, Gdk.Paintable):
+
+ __gtype_name__ = "CoverPaintable"
+
+ def __init__(self, art_size, texture=None):
+ super().__init__()
+
+ self._texture = texture
+ self._art_size = art_size
+
+ def do_snapshot(self, snapshot, width, height):
+ w = width
+ h = height
+
+ if self._texture is not None:
+ snapshot.translate(Graphene.Point().init(width / 2, height / 2))
+
+ rect = Graphene.Rect().init(-(w / 2), -(h / 2), w, h)
+ rect2 = Graphene.Rect().init(-50, -50, 100, 100)
+
+ # Anything Gsk related seems to be failing, no rounded
+ # clips for now. Related: pygobject#471
+ #
+ # gskrr = Gsk.RoundedRect().init_from_rect(rect2, 10)
+ # snapshot.push_rounded_clip(gskrr)
+
+ snapshot.push_clip(rect2)
+ snapshot.append_texture(self._texture, rect)
+ snapshot.pop()
+ else:
+ 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/defaulticon.py b/gnomemusic/defaulticon.py
index 32c1921be..2383e76ec 100644
--- a/gnomemusic/defaulticon.py
+++ b/gnomemusic/defaulticon.py
@@ -29,6 +29,7 @@ from typing import Dict, Tuple
import cairo
from gi.repository import Gtk, GObject
+from gnomemusic.coverpaintable import CoverPaintable
from gnomemusic.utils import ArtSize
@@ -106,14 +107,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, art_size.width / 3, scale, 0, 0)
- icon = icon_info.load_surface()
+ # icon_info = self._default_theme.lookup_icon(
+ # icon_type.value, 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):
"""Returns the requested symbolic icon
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index a42056d9b..eea35bc98 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -154,12 +154,12 @@ class ArtStack(Gtk.Stack):
self._async_queue.queue(
self._cache, coreobject, self._size, self.props.scale_factor)
- def _on_cache_result(self, cache: ArtCache, surface: ImageSurface) -> None:
+ def _on_cache_result(self, cache: ArtCache, paintable: Gdk.Paintable) -> None:
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: ArtStack) -> None:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]