[gnome-music/wip/mschraal/gtk4: 62/102] WIP: covers: CoverPaintable
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/gtk4: 62/102] WIP: covers: CoverPaintable
- Date: Mon, 8 Jun 2020 23:43:18 +0000 (UTC)
commit c4f1210f6db26c39d1f275de08514e1b1a22092b
Author: Marinus Schraal <mschraal gnome org>
Date: Fri Nov 8 11:50:37 2019 +0100
WIP: covers: CoverPaintable
gnomemusic/albumartcache.py | 20 +++++---
gnomemusic/coverpaintable.py | 100 +++++++++++++++++++++++++++++++++++++++
gnomemusic/widgets/coverstack.py | 11 +++--
3 files changed, 119 insertions(+), 12 deletions(-)
---
diff --git a/gnomemusic/albumartcache.py b/gnomemusic/albumartcache.py
index 9253f744..535ff81b 100644
--- a/gnomemusic/albumartcache.py
+++ b/gnomemusic/albumartcache.py
@@ -31,9 +31,10 @@ import gi
gi.require_version('GstTag', '1.0')
gi.require_version('MediaArt', '2.0')
gi.require_version("Soup", "2.4")
-from gi.repository import (Gdk, GdkPixbuf, Gio, GLib, GObject, Gtk, MediaArt,
- Gst, GstTag, GstPbutils, Soup)
+from gi.repository import (GdkPixbuf, Gio, GLib, GObject, Gtk, MediaArt, Gst,
+ GstTag, GstPbutils, Soup)
+from gnomemusic.coverpaintable import CoverPaintable
from gnomemusic.musiclogger import MusicLogger
@@ -129,13 +130,14 @@ class DefaultIcon(GObject.GObject):
super().__init__()
def _make_default_icon(self, icon_type, art_size, scale):
- icon_info = self._default_theme.lookup_icon_for_scale(
- icon_type.value, art_size.width / 3, scale, 0)
- icon = icon_info.load_surface()
+ # icon_info = self._default_theme.lookup_icon_for_scale(
+ # icon_type.value, art_size.width / 3, scale, 0)
+ # icon = icon_info.load_surface()
- icon_surface = _make_icon_frame(icon, art_size, scale, True)
+ # icon_surface = _make_icon_frame(icon, art_size, scale, True)
- return icon_surface
+ icon = CoverPaintable(art_size)
+ return icon
def get(self, icon_type, art_size, scale=1):
"""Returns the requested symbolic icon
@@ -196,6 +198,8 @@ class Art(GObject.GObject):
except AttributeError:
self._url = None
self._surface = None
+ self.texture = None
+ self.pixbuf = None
self._scale = scale
def lookup(self):
@@ -221,6 +225,8 @@ class Art(GObject.GObject):
surface = None
# surface = _make_icon_frame(surface, self._size, self._scale)
self._surface = surface
+ # self.texture = Gdk.Texture.new_for_pixbuf(pixbuf)
+ self.pixbuf = pixbuf
self.emit('finished')
diff --git a/gnomemusic/coverpaintable.py b/gnomemusic/coverpaintable.py
new file mode 100644
index 00000000..b56eb76b
--- /dev/null
+++ b/gnomemusic/coverpaintable.py
@@ -0,0 +1,100 @@
+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.albumartcache import Art
+
+
+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
+
+ border = 3
+ degrees = pi / 180
+ radius = 3
+
+ theme = Gtk.IconTheme.get_default()
+
+ # pixbuf = theme.load_icon("content-loading-symbolic", w, 0)
+ icon_pt = theme.lookup_icon(
+ "content-loading-symbolic", None, w, 1, 0, 0)
+ texture = Gdk.Texture.new_from_file(icon_pt.get_file())
+ rect = Graphene.Rect().init(0, 0, width, height)
+ snapshot.append_texture(texture, rect)
+
+ size = min(width, height)
+
+ cr = snapshot.append_cairo(Graphene.Rect().init(
+ (width - size) / 2.0, (height - size) / 2.0, size, size))
+
+ # draw outline
+ cr.new_sub_path()
+ cr.arc(w - radius, radius, radius - 0.5, -90 * degrees, 0 * degrees)
+ cr.arc(w - radius, h - radius, radius - 0.5, 0 * degrees, 90 * degrees)
+ cr.arc(radius, h - radius, radius - 0.5, 90 * degrees, 180 * degrees)
+ cr.arc(radius, radius, radius - 0.5, 180 * degrees, 270 * degrees)
+ cr.close_path()
+ cr.set_line_width(0.6)
+ cr.set_source_rgba(0, 0, 0, 0.7)
+ cr.stroke_preserve()
+
+ cr.set_source_rgb(1, 1, 1)
+ cr.fill()
+ cr.set_source_rgba(0, 0, 0, 0.3)
+ # ctx.mask_surface(icon_surface, w / 3, h / 3)
+ cr.fill()
+ # Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0)
+ color = Gdk.RGBA(red=0.9, green=0.75, blue=0.75, alpha=.5)
+ color.red = 0.9
+ color.alpha = 1.0
+ rect = Graphene.Rect().init(0, 0, width, height)
+
+ # pixbuf = theme.load_icon("content-loading-symbolic", w,# 0)
+ icon_pt = theme.lookup_icon(
+ "content-loading-symbolic", None, w, 1, 0, 0)
+ texture = Gdk.Texture.new_from_file(icon_pt.get_file())
+ rect = Graphene.Rect().init(
+ 0 + border, 0 + border, width - border, height - border)
+ snapshot.append_texture(texture, rect)
+ # snapshot.append_color(color, rect)
+
+ # size = min(width, height)
+
+ # cr = snapshot.append_cairo(Graphene.Rect().init(
+ # (width - size) / 2.0, (height - size) / 2.0, size, size))
+
+ # cr.translate(width / 2.0, height / 2.0)
+ # cr.scale(size, size)
+ # cr.rotate(0.0)
+
+ # PI = 3.14159
+ # cr.arc(0, 0, 0.1, -PI, PI)
+ # cr.fill()
+
+ # cr.set_line_width(0.3)
+ # cr.set_dash([0.3 * PI / 3], 1.0)
+ # cr.arc(0, 0, 0.3, -PI, PI)
+ # cr.stroke()
+
+ 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/coverstack.py b/gnomemusic/widgets/coverstack.py
index b5a837c2..1b1d2983 100644
--- a/gnomemusic/widgets/coverstack.py
+++ b/gnomemusic/widgets/coverstack.py
@@ -52,6 +52,7 @@ class CoverStack(Gtk.Stack):
self._timeout = None
self._loading_cover = Gtk.Image()
+ self.set_size_request(size.width, size.height)
self._cover_a = Gtk.Image()
self._cover_b = Gtk.Image()
@@ -82,9 +83,9 @@ class CoverStack(Gtk.Stack):
"""
self._size = value
- # icon = self._default_icon.get(
- # DefaultIcon.Type.LOADING, self.props.size, self.props.scale_factor)
- # self._loading_cover.props.surface = icon
+ paintable = self._default_icon.get(
+ DefaultIcon.Type.LOADING, self.props.size, self.props.scale_factor)
+ self._loading_cover.props.paintable = paintable
def update(self, coresong):
"""Update the stack with the given CoreSong
@@ -120,10 +121,10 @@ class CoverStack(Gtk.Stack):
self._timeout = None
if self._active_child == "B":
- # self._cover_a.props.surface = klass.surface
+ self._cover_a.set_from_pixbuf(klass.pixbuf)
self.props.visible_child_name = "A"
else:
- # self._cover_b.props.surface = klass.surface
+ self._cover_b.set_from_pixbuf(klass.pixbuf)
self.props.visible_child_name = "B"
self._active_child = self.props.visible_child_name
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]