[gnome-music/wip/mschraal/searchview-rework: 14/15] work some more on the icons



commit 2c7ba8565af2b465d79c228f9b5384badeda0c9c
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Aug 2 23:22:06 2019 +0200

    work some more on the icons

 gnomemusic/artistart.py              | 57 ++++++++++++++++++++++++++++++++----
 gnomemusic/widgets/artistartstack.py |  4 +--
 2 files changed, 54 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/artistart.py b/gnomemusic/artistart.py
index ff9049fa..f488b623 100644
--- a/gnomemusic/artistart.py
+++ b/gnomemusic/artistart.py
@@ -58,13 +58,16 @@ def _make_icon_frame(icon_surface, art_size=None, scale=1, default_icon=False):
 
     matrix = cairo.Matrix()
 
-    # if default_icon:
-    #     matrix.translate(-w * (1 / 3), -h * (1 / 3))
-    #     ctx.set_operator(cairo.Operator.DIFFERENCE)
-    # else:
-    matrix.scale(icon_w / w, icon_h / h)
+    if default_icon:
+        ctx.set_source_rgb(0, 0, 0)
+        ctx.fill()
+        matrix.translate(-w * 1/3, -h * 1/3)
+        ctx.set_operator(cairo.Operator.DIFFERENCE)
+    else:
+        matrix.scale(icon_w / w, icon_h / h)
 
     ctx.set_source_surface(icon_surface, 0, 0)
+
     pattern = ctx.get_source()
     pattern.set_matrix(matrix)
     ctx.rectangle(0, 0, w, h)
@@ -73,6 +76,50 @@ def _make_icon_frame(icon_surface, art_size=None, scale=1, default_icon=False):
     return surface
 
 
+class DefaultIcon(GObject.GObject):
+    """Provides the symbolic fallback and loading icons."""
+
+    class Type(Enum):
+        LOADING = 'content-loading-symbolic'
+        MUSIC = 'folder-music-symbolic'
+
+    _cache = {}
+    _default_theme = Gtk.IconTheme.get_default()
+
+    def __repr__(self):
+        return '<DefaultIcon>'
+
+    def __init__(self):
+        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_surface = _make_icon_frame(icon, art_size, scale, True)
+
+        return icon_surface
+
+    def get(self, icon_type, art_size, scale=1):
+        """Returns the requested symbolic icon
+
+        Returns a cairo surface of the requested symbolic icon in the
+        given size.
+
+        :param enum icon_type: The DefaultIcon.Type of the icon
+        :param enum art_size: The Art.Size requested
+
+        :return: The symbolic icon
+        :rtype: cairo.Surface
+        """
+        if (icon_type, art_size, scale) not in self._cache.keys():
+            new_icon = self._make_default_icon(icon_type, art_size, scale)
+            self._cache[(icon_type, art_size, scale)] = new_icon
+
+        return self._cache[(icon_type, art_size, scale)]
+
+
 class ArtistArt(GObject.GObject):
 
     def __init__(self, coreartist):
diff --git a/gnomemusic/widgets/artistartstack.py b/gnomemusic/widgets/artistartstack.py
index ded31359..c7c43f9b 100644
--- a/gnomemusic/widgets/artistartstack.py
+++ b/gnomemusic/widgets/artistartstack.py
@@ -25,8 +25,8 @@
 from gi.repository import GLib, GObject, Gtk
 
 from gnomemusic import log
-from gnomemusic.albumartcache import Art, DefaultIcon
-from gnomemusic.artistart import ArtistCache
+from gnomemusic.albumartcache import Art
+from gnomemusic.artistart import ArtistCache, DefaultIcon
 from gnomemusic.coreartist import CoreArtist
 
 


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