[gnome-music/wip/cdavis/dark-style-opt-in: 18/20] artstack: Reload default icon when dark style pref changes
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/cdavis/dark-style-opt-in: 18/20] artstack: Reload default icon when dark style pref changes
- Date: Wed, 2 Feb 2022 11:51:43 +0000 (UTC)
commit 72ace3bd1396b97b2e995248032f988effe12d8f
Author: Christopher Davis <christopherdavis gnome org>
Date: Sat Nov 27 18:50:13 2021 -0800
artstack: Reload default icon when dark style pref changes
gnomemusic/defaulticon.py | 24 +++++++++++++++---------
gnomemusic/widgets/artstack.py | 16 +++++++++++++++-
2 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/defaulticon.py b/gnomemusic/defaulticon.py
index 95def3e62..6e4d04a25 100644
--- a/gnomemusic/defaulticon.py
+++ b/gnomemusic/defaulticon.py
@@ -34,7 +34,7 @@ from gnomemusic.utils import ArtSize
def make_icon_frame(
icon_surface, art_size=None, scale=1, default_icon=False,
- round_shape=False):
+ round_shape=False, dark=False):
"""Create an Art frame, square or round.
:param cairo.Surface icon_surface: The surface to use
@@ -78,7 +78,7 @@ def make_icon_frame(
fill_color = Gdk.RGBA(1.0, 1.0, 1.0, 1.0)
icon_color = Gdk.RGBA(0.0, 0.0, 0.0, 0.3)
- if Handy.StyleManager.get_default().props.dark:
+ if dark:
fill_color = Gdk.RGBA(66.0 / 255, 66.0 / 255, 66.0 / 255, 1.0)
icon_color = Gdk.RGBA(1.0, 1.0, 1.0, 1.0)
@@ -105,20 +105,22 @@ class DefaultIcon(GObject.GObject):
ARTIST = "avatar-default-symbolic"
_cache: Dict[
- Tuple["DefaultIcon.Type", ArtSize, int, bool], cairo.Surface] = {}
+ Tuple[
+ "DefaultIcon.Type", ArtSize, int, bool, bool], cairo.Surface] = {}
_default_theme = Gtk.IconTheme.get_default()
def __init__(self):
super().__init__()
- def _make_default_icon(self, icon_type, art_size, scale, round_shape):
+ def _make_default_icon(
+ self, icon_type, art_size, scale, round_shape, dark):
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, round_shape=round_shape)
+ icon, art_size, scale, True, round_shape=round_shape, dark=dark)
return icon_surface
@@ -140,9 +142,13 @@ class DefaultIcon(GObject.GObject):
else:
round_shape = True
- if (icon_type, art_size, scale, round_shape) not in self._cache.keys():
+ dark = Handy.StyleManager.get_default().props.dark
+
+ if (icon_type, art_size,
+ scale, round_shape, dark) not in self._cache.keys():
new_icon = self._make_default_icon(
- icon_type, art_size, scale, round_shape)
- self._cache[(icon_type, art_size, scale, round_shape)] = new_icon
+ icon_type, art_size, scale, round_shape, dark)
+ self._cache[
+ (icon_type, art_size, scale, round_shape, dark)] = new_icon
- return self._cache[(icon_type, art_size, scale, round_shape)]
+ return self._cache[(icon_type, art_size, scale, round_shape, dark)]
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index a42056d9b..4c67612fa 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -26,7 +26,7 @@ from __future__ import annotations
from typing import Optional, Union
import typing
-from gi.repository import GObject, Gtk
+from gi.repository import GObject, Gtk, Handy
if typing.TYPE_CHECKING:
from cairo import ImageSurface
@@ -84,6 +84,8 @@ class ArtStack(Gtk.Stack):
self.props.visible_child_name = "A"
self.connect("destroy", self._on_destroy)
+ Handy.StyleManager.get_default().connect(
+ "notify::dark", self._on_dark_changed, self)
@GObject.Property(type=object, flags=GObject.ParamFlags.READWRITE)
def size(self) -> ArtSize:
@@ -143,6 +145,18 @@ class ArtStack(Gtk.Stack):
if self._coreobject.props.thumbnail is not None:
self._on_thumbnail_changed(self._coreobject, None)
+ def _on_dark_changed(
+ self, style_manager: Handy.StyleManager,
+ pspec: Optional[GObject.ParamSpecBoolean], data) -> None:
+ default_icon = DefaultIcon().get(
+ self._art_type, self._size, self.props.scale_factor)
+
+ if self.coreobject:
+ if self.coreobject.props.thumbnail == "generic":
+ self._on_cache_result(self, default_icon)
+ else:
+ self._on_cache_result(self, default_icon)
+
def _on_thumbnail_changed(
self, coreobject: CoreObject,
uri: Optional[GObject.ParamSpecString]) -> None:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]