Anna Schumaker
0584a2398a
This is mostly a wrapper around an Adw.Avatar to make it easier to load images from a file. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
# Copyright 2022 (c) Anna Schumaker.
|
|
"""Custom icon widgets for playlist rows."""
|
|
from gi.repository import GObject
|
|
from gi.repository import Gdk
|
|
from gi.repository import Adw
|
|
|
|
|
|
class Icon(Adw.Bin):
|
|
"""A custom Adw.Avatar that can load images from a file path."""
|
|
|
|
text = GObject.Property(type=str)
|
|
filepath = GObject.Property(type=GObject.TYPE_PYOBJECT)
|
|
icon_name = GObject.Property(type=str)
|
|
show_initials = GObject.Property(type=bool, default=False)
|
|
|
|
def __init__(self, **kwargs):
|
|
"""Initialize our Playlist icon."""
|
|
super().__init__(**kwargs)
|
|
self._icon = Adw.Avatar(size=40, show_initials=self.show_initials)
|
|
|
|
self.bind_property("text", self._icon, "text")
|
|
self.bind_property("icon-name", self._icon, "icon-name")
|
|
self.bind_property("show-initials", self._icon, "show-initials")
|
|
|
|
self.connect("notify::filepath", self.__notify_filepath)
|
|
|
|
self.set_child(self._icon)
|
|
|
|
def __notify_filepath(self, icon: Adw.Bin, param) -> None:
|
|
if self.filepath is None:
|
|
texture = None
|
|
else:
|
|
texture = Gdk.Texture.new_from_filename(str(self.filepath))
|
|
self._icon.set_custom_image(texture)
|