[gnome-music/wip/mschraal/artstack-pass-widget-around: 9/9] Move default icon type enum to utils




commit d15559af29cc3c0c56027ebf53f2b59e6faf5643
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Feb 4 14:38:36 2022 +0100

    Move default icon type enum to utils
    
    Rename from DefaultIcon.Type to DefaultIconType.

 gnomemusic/artcache.py                 |  6 +++---
 gnomemusic/defaulticon.py              | 23 ++++++++---------------
 gnomemusic/utils.py                    |  5 +++++
 gnomemusic/widgets/albumcover.py       |  5 ++---
 gnomemusic/widgets/albumwidget.py      |  5 ++---
 gnomemusic/widgets/artistsearchtile.py |  5 ++---
 gnomemusic/widgets/artisttile.py       |  5 ++---
 gnomemusic/widgets/artstack.py         | 12 ++++++------
 gnomemusic/widgets/playertoolbar.py    |  5 ++---
 9 files changed, 32 insertions(+), 39 deletions(-)
---
diff --git a/gnomemusic/artcache.py b/gnomemusic/artcache.py
index 08377652e..07ef47765 100644
--- a/gnomemusic/artcache.py
+++ b/gnomemusic/artcache.py
@@ -29,7 +29,7 @@ from gnomemusic.coreartist import CoreArtist
 from gnomemusic.coresong import CoreSong
 from gnomemusic.defaulticon import DefaultIcon, make_icon_frame
 from gnomemusic.musiclogger import MusicLogger
-from gnomemusic.utils import ArtSize
+from gnomemusic.utils import ArtSize, DefaultIconType
 
 
 class ArtCache(GObject.GObject):
@@ -72,11 +72,11 @@ class ArtCache(GObject.GObject):
 
         if isinstance(coreobject, CoreArtist):
             self._default_icon = DefaultIcon(self._widget).get(
-                DefaultIcon.Type.ARTIST, self._size)
+                DefaultIconType.ARTIST, self._size)
         elif (isinstance(coreobject, CoreAlbum)
                 or isinstance(coreobject, CoreSong)):
             self._default_icon = DefaultIcon(self._widget).get(
-                DefaultIcon.Type.ALBUM, self._size)
+                DefaultIconType.ALBUM, self._size)
 
         thumbnail_uri = coreobject.props.thumbnail
         if thumbnail_uri == "generic":
diff --git a/gnomemusic/defaulticon.py b/gnomemusic/defaulticon.py
index c1d5b92f4..f7e93a774 100644
--- a/gnomemusic/defaulticon.py
+++ b/gnomemusic/defaulticon.py
@@ -24,14 +24,13 @@
 
 from __future__ import annotations
 
-from enum import Enum
 from math import pi
 from typing import Dict, Tuple
 
 import cairo
 from gi.repository import Gtk, GObject, Gdk, Handy
 
-from gnomemusic.utils import ArtSize
+from gnomemusic.utils import ArtSize, DefaultIconType
 
 
 def make_icon_frame(
@@ -104,14 +103,8 @@ def make_icon_frame(
 
 class DefaultIcon(GObject.GObject):
     """Provides the symbolic fallback icons."""
-
-    class Type(Enum):
-        ALBUM = "folder-music-symbolic"
-        ARTIST = "avatar-default-symbolic"
-
     _cache: Dict[
-        Tuple[DefaultIcon.Type, ArtSize, int, bool, bool],
-        cairo.ImageSurface] = {}
+        Tuple[DefaultIconType, ArtSize, int, bool], cairo.ImageSurface] = {}
 
     _default_theme = Gtk.IconTheme.get_default()
 
@@ -125,14 +118,14 @@ class DefaultIcon(GObject.GObject):
         self._widget = widget
 
     def _make_default_icon(
-            self, icon_type: DefaultIcon.Type, art_size: ArtSize, scale: int,
+            self, icon_type: DefaultIconType, art_size: ArtSize, scale: int,
             dark: bool) -> cairo.ImageSurface:
         icon_info = self._default_theme.lookup_icon_for_scale(
             icon_type.value, art_size.width / 3, scale, 0)
         icon = icon_info.load_surface()
 
         round_shape = False
-        if icon_type == DefaultIcon.Type.ARTIST:
+        if icon_type == DefaultIconType.ARTIST:
             round_shape = True
 
         icon_surface = make_icon_frame(
@@ -140,15 +133,15 @@ class DefaultIcon(GObject.GObject):
 
         return icon_surface
 
-    def get(self, icon_type: DefaultIcon.Type,
+    def get(self, icon_type: DefaultIconType,
             art_size: ArtSize) -> cairo.ImageSurface:
         """Returns the requested symbolic icon
 
         Returns a cairo surface of the requested symbolic icon in the
         given size and shape.
 
-        :param enum icon_type: The DefaultIcon.Type of the icon
-        :param enum art_size: The ArtSize requested
+        :param DefaultIconType icon_type: The type of icon
+        :param ArtSize art_size: The size requested
 
         :return: The symbolic icon
         :rtype: cairo.ImageSurface
@@ -156,7 +149,7 @@ class DefaultIcon(GObject.GObject):
         dark = Handy.StyleManager.get_default().props.dark
         scale = self._widget.props.scale_factor
 
-        if (icon_type, art_size,scale, dark) not in self._cache.keys():
+        if (icon_type, art_size, scale, dark) not in self._cache.keys():
             new_icon = self._make_default_icon(
                 icon_type, art_size, scale, dark)
             self._cache[(icon_type, art_size, scale, dark)] = new_icon
diff --git a/gnomemusic/utils.py b/gnomemusic/utils.py
index 5d3262a00..c2762cf06 100644
--- a/gnomemusic/utils.py
+++ b/gnomemusic/utils.py
@@ -46,6 +46,11 @@ class ArtSize(Enum):
         self.height = height
 
 
+class DefaultIconType(Enum):
+    ALBUM = "folder-music-symbolic"
+    ARTIST = "avatar-default-symbolic"
+
+
 class SongStateIcon(Enum):
     """Enum for icons used in song playing and validation"""
     ERROR = "dialog-error-symbolic"
diff --git a/gnomemusic/widgets/albumcover.py b/gnomemusic/widgets/albumcover.py
index ec51de65b..6b0dd1dcf 100644
--- a/gnomemusic/widgets/albumcover.py
+++ b/gnomemusic/widgets/albumcover.py
@@ -26,9 +26,8 @@ import gi
 gi.require_version('Grl', '0.3')
 from gi.repository import GObject, Gtk
 
-from gnomemusic.defaulticon import DefaultIcon
 from gnomemusic.corealbum import CoreAlbum
-from gnomemusic.utils import ArtSize
+from gnomemusic.utils import ArtSize, DefaultIconType
 from gnomemusic.widgets.twolinetip import TwoLineTip
 
 
@@ -83,7 +82,7 @@ class AlbumCover(Gtk.FlowBoxChild):
         self.connect('query-tooltip', self._on_tooltip_query)
 
         self._art_stack.props.size = ArtSize.MEDIUM
-        self._art_stack.props.art_type = DefaultIcon.Type.ALBUM
+        self._art_stack.props.art_type = DefaultIconType.ALBUM
 
         self.show()
 
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 1475f4104..03f8c254e 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -30,8 +30,7 @@ import typing
 from gi.repository import Gfm, Gio, GLib, GObject, Gtk, Handy
 
 from gnomemusic.corealbum import CoreAlbum
-from gnomemusic.defaulticon import DefaultIcon
-from gnomemusic.utils import ArtSize
+from gnomemusic.utils import ArtSize, DefaultIconType
 from gnomemusic.widgets.discbox import DiscBox
 from gnomemusic.widgets.playlistdialog import PlaylistDialog
 if typing.TYPE_CHECKING:
@@ -83,7 +82,7 @@ class AlbumWidget(Handy.Clamp):
         self._playlist_dialog: Optional[PlaylistDialog] = None
 
         self._art_stack.props.size = ArtSize.LARGE
-        self._art_stack.props.art_type = DefaultIcon.Type.ALBUM
+        self._art_stack.props.art_type = DefaultIconType.ALBUM
         self._player = self._application.props.player
 
         self.bind_property(
diff --git a/gnomemusic/widgets/artistsearchtile.py b/gnomemusic/widgets/artistsearchtile.py
index 2eaad9725..7bcecfc01 100644
--- a/gnomemusic/widgets/artistsearchtile.py
+++ b/gnomemusic/widgets/artistsearchtile.py
@@ -25,8 +25,7 @@
 from gi.repository import Gdk, GObject, Gtk
 
 from gnomemusic.coreartist import CoreArtist
-from gnomemusic.defaulticon import DefaultIcon
-from gnomemusic.utils import ArtSize
+from gnomemusic.utils import ArtSize, DefaultIconType
 from gnomemusic.widgets.artstack import ArtStack  # noqa: F401
 from gnomemusic.widgets.twolinetip import TwoLineTip
 
@@ -62,7 +61,7 @@ class ArtistSearchTile(Gtk.FlowBoxChild):
         self.props.coreartist = coreartist
 
         self._art_stack.props.size = ArtSize.MEDIUM
-        self._art_stack.props.art_type = DefaultIcon.Type.ARTIST
+        self._art_stack.props.art_type = DefaultIconType.ARTIST
         self._art_stack.props.coreobject = self.props.coreartist
 
         self._tooltip = TwoLineTip()
diff --git a/gnomemusic/widgets/artisttile.py b/gnomemusic/widgets/artisttile.py
index da2c5d55b..17ea1b6ef 100644
--- a/gnomemusic/widgets/artisttile.py
+++ b/gnomemusic/widgets/artisttile.py
@@ -25,8 +25,7 @@
 from gi.repository import GObject, Gtk
 
 from gnomemusic.coreartist import CoreArtist
-from gnomemusic.defaulticon import DefaultIcon
-from gnomemusic.utils import ArtSize
+from gnomemusic.utils import ArtSize, DefaultIconType
 
 
 @Gtk.Template(resource_path='/org/gnome/Music/ui/ArtistTile.ui')
@@ -50,7 +49,7 @@ class ArtistTile(Gtk.ListBoxRow):
         self.props.coreartist = coreartist
 
         self._art_stack.props.size = ArtSize.XSMALL
-        self._art_stack.props.art_type = DefaultIcon.Type.ARTIST
+        self._art_stack.props.art_type = DefaultIconType.ARTIST
 
         self.bind_property('text', self._label, 'label')
         self.bind_property('text', self._label, 'tooltip-text')
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index 81357e41d..2f805f2a4 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -34,7 +34,7 @@ if typing.TYPE_CHECKING:
 from gnomemusic.asyncqueue import AsyncQueue
 from gnomemusic.artcache import ArtCache
 from gnomemusic.defaulticon import DefaultIcon
-from gnomemusic.utils import ArtSize
+from gnomemusic.utils import ArtSize, DefaultIconType
 if typing.TYPE_CHECKING:
     from gnomemusic.corealbum import CoreAlbum
     from gnomemusic.coreartist import CoreArtist
@@ -64,7 +64,7 @@ class ArtStack(Gtk.Stack):
         """
         super().__init__()
 
-        self._art_type = DefaultIcon.Type.ALBUM
+        self._art_type = DefaultIconType.ALBUM
         self._cache = ArtCache(self)
         self._coreobject: Optional[CoreObject] = None
         self._handler_id = 0
@@ -104,19 +104,19 @@ class ArtStack(Gtk.Stack):
         self._size = value
 
     @GObject.Property(type=object, flags=GObject.ParamFlags.READWRITE)
-    def art_type(self) -> DefaultIcon.Type:
+    def art_type(self) -> DefaultIconType:
         """Type of the stack cover
 
         :returns: The type of the default icon
-        :rtype: DefaultIcon.Type
+        :rtype: DefaultIconType
         """
         return self._art_type
 
     @art_type.setter  # type: ignore
-    def art_type(self, value: DefaultIcon.Type) -> None:
+    def art_type(self, value: DefaultIconType) -> None:
         """Set the stack cover type
 
-        :param DefaultIcon.Type value: The default icon type for the
+        :param DefaultIconType value: The default icon type for the
             stack
         """
         self._art_type = value
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 11d5e6a3c..f148bd228 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -25,9 +25,8 @@
 from gettext import gettext as _
 from gi.repository import Gio, GLib, GObject, Gtk
 
-from gnomemusic.defaulticon import DefaultIcon
 from gnomemusic.gstplayer import Playback
-from gnomemusic.utils import ArtSize
+from gnomemusic.utils import ArtSize, DefaultIconType
 from gnomemusic.player import Player, RepeatMode
 from gnomemusic.widgets.smoothscale import SmoothScale  # noqa: F401
 from gnomemusic.widgets.twolinetip import TwoLineTip
@@ -65,7 +64,7 @@ class PlayerToolbar(Gtk.ActionBar):
         self._player = None
 
         self._art_stack.props.size = ArtSize.SMALL
-        self._art_stack.props.art_type = DefaultIcon.Type.ALBUM
+        self._art_stack.props.art_type = DefaultIconType.ALBUM
 
         self._tooltip = TwoLineTip()
 


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