nowplaying: Remove the Gtk.Frame from the Artwork

All I needed the frame for was to add rounded corners to the
Gtk.Picture, but this had some problems with the Frame expanding beyond
the edges of the picture in some cases. I can get the same effect by
adding the "card" css class to the Picture so hopefully this will work
better.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2023-06-05 14:47:32 -04:00
parent 1f434358de
commit 087c378e59
2 changed files with 26 additions and 26 deletions

View File

@ -8,39 +8,40 @@ from .. import gsetup
FALLBACK_RESOURCE = f"{gsetup.RESOURCE_ICONS}/emmental.svg"
class Artwork(Gtk.Frame):
"""Our custom Album Art widget that draws a border around a picture."""
class Artwork(Gtk.Picture):
"""Our custom Album Art widget takes a pathlib.Path."""
def __init__(self):
"""Initialize the Album Art widget."""
super().__init__(margin_top=6, margin_bottom=6, margin_start=6,
margin_end=6, halign=Gtk.Align.CENTER,
valign=Gtk.Align.CENTER)
self._picture = Gtk.Picture(content_fit=Gtk.ContentFit.CONTAIN)
super().__init__(content_fit=Gtk.ContentFit.CONTAIN,
margin_top=6, margin_bottom=6,
margin_start=6, margin_end=6,
halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER)
self._fullsize = Gtk.Picture(content_fit=Gtk.ContentFit.FILL)
self._popover = Gtk.Popover(child=self._fullsize)
self._clicked = Gtk.GestureClick()
self._popover = Gtk.Popover(child=self._fullsize)
self._popover.set_parent(self)
self._clicked = Gtk.GestureClick()
self._clicked.connect("released", self.clicked)
self.add_controller(self._clicked)
self._popover.set_parent(self)
self.set_child(self._picture)
self.add_css_class("card")
self.filepath = None
@GObject.Property(type=GObject.TYPE_PYOBJECT)
def filepath(self) -> pathlib.Path:
"""Get the current artwork path."""
name = self._picture.get_file().get_parse_name()
name = self.get_file().get_parse_name()
return None if name.startswith("resource:") else pathlib.Path(name)
@filepath.setter
def filepath(self, path: pathlib.Path) -> None:
if path is not None:
self._picture.set_filename(str(path))
self.set_filename(str(path))
self._fullsize.set_filename(str(path))
else:
self._picture.set_resource(FALLBACK_RESOURCE)
self.set_resource(FALLBACK_RESOURCE)
self._fullsize.set_resource(FALLBACK_RESOURCE)
def clicked(self, gesture: Gtk.GestureClick, n_press: int,

View File

@ -21,7 +21,9 @@ class TestArtwork(unittest.TestCase):
def test_init(self):
"""Test that the artwork widget is configured correctly."""
self.assertIsInstance(self.artwork, Gtk.Frame)
self.assertIsInstance(self.artwork, Gtk.Picture)
self.assertEqual(self.artwork.get_content_fit(),
Gtk.ContentFit.CONTAIN)
self.assertEqual(self.artwork.get_halign(), Gtk.Align.CENTER)
self.assertEqual(self.artwork.get_valign(), Gtk.Align.CENTER)
@ -31,27 +33,24 @@ class TestArtwork(unittest.TestCase):
self.assertEqual(self.artwork.get_margin_start(), 6)
self.assertEqual(self.artwork.get_margin_end(), 6)
def test_picture(self):
"""Test that the artwork picture is configured correctly."""
self.assertIsInstance(self.artwork._picture, Gtk.Picture)
self.assertEqual(self.artwork._picture.get_content_fit(),
Gtk.ContentFit.CONTAIN)
self.assertEqual(self.artwork.get_child(), self.artwork._picture)
self.assertTrue(self.artwork.has_css_class("card"))
def test_filepath(self):
"""Test that the filepath property works as expected."""
self.assertIsNone(self.artwork.filepath)
self.assertIsNotNone(self.artwork._picture.get_paintable())
self.assertEqual(self.artwork._picture.get_file().get_parse_name(),
self.assertIsNotNone(self.artwork.get_paintable())
self.assertEqual(self.artwork.get_file().get_parse_name(),
f"resource://{self.fallback}")
self.artwork.filepath = tests.util.COVER_JPG
self.assertIsNotNone(self.artwork._picture.get_paintable())
self.assertEqual(self.artwork._picture.get_file().get_parse_name(),
self.assertIsNotNone(self.artwork.get_paintable())
self.assertEqual(self.artwork.get_file().get_parse_name(),
str(tests.util.COVER_JPG))
self.assertEqual(self.artwork.filepath, tests.util.COVER_JPG)
self.artwork.filepath = None
self.assertIsNotNone(self.artwork._picture.get_paintable())
self.assertEqual(self.artwork._picture.get_file().get_parse_name(),
self.assertIsNotNone(self.artwork.get_paintable())
self.assertEqual(self.artwork.get_file().get_parse_name(),
f"resource://{self.fallback}")
def test_fullsize(self):