tracklist: Use the Texture Cache for album art
Replacing our tracklist-specific one that caches textures, but not to local disk. Implements #53 ("Convert the TrackList to use the Texture Cache") Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
a4f30d87e6
commit
6ebf29a632
|
@ -4,10 +4,10 @@ import datetime
|
|||
import dateutil.tz
|
||||
import pathlib
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Gtk
|
||||
from .. import buttons
|
||||
from .. import factory
|
||||
from .. import texture
|
||||
|
||||
|
||||
class TrackRow(factory.ListRow):
|
||||
|
@ -278,8 +278,6 @@ class MediumString(InscriptionRow):
|
|||
class AlbumCover(TrackRow):
|
||||
"""A Track Row to display Album art."""
|
||||
|
||||
Cache = dict()
|
||||
|
||||
filepath = GObject.Property(type=GObject.TYPE_PYOBJECT)
|
||||
|
||||
def __init__(self, listitem: Gtk.ListItem, property: str):
|
||||
|
@ -293,19 +291,14 @@ class AlbumCover(TrackRow):
|
|||
match param.name:
|
||||
case "mediumid": self.rebind_album("filepath", to_self=True)
|
||||
case "filepath":
|
||||
if self.filepath is None:
|
||||
texture = None
|
||||
elif (texture := AlbumCover.Cache.get(self.filepath)) is None:
|
||||
texture = Gdk.Texture.new_from_filename(str(self.filepath))
|
||||
AlbumCover.Cache[self.filepath] = texture
|
||||
|
||||
self.child.set_paintable(texture)
|
||||
self.child.set_has_tooltip(texture is not None)
|
||||
tex = texture.CACHE[self.filepath]
|
||||
self.child.set_paintable(tex)
|
||||
self.child.set_has_tooltip(tex is not None)
|
||||
|
||||
def __query_tooltip(self, child: Gtk.Picture, x: int, y: int,
|
||||
keyboard_mode: bool, tooltip: Gtk.Tooltip) -> bool:
|
||||
texture = AlbumCover.Cache.get(self.filepath)
|
||||
tooltip.set_custom(Gtk.Picture.new_for_paintable(texture))
|
||||
tex = texture.CACHE[self.filepath]
|
||||
tooltip.set_custom(Gtk.Picture.new_for_paintable(tex))
|
||||
return True
|
||||
|
||||
def do_bind(self) -> None:
|
||||
|
|
|
@ -8,7 +8,6 @@ import emmental.tracklist.row
|
|||
import tests.util
|
||||
import unittest.mock
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Adw
|
||||
|
||||
|
@ -193,9 +192,6 @@ class TestTrackRowWidgets(tests.util.TestCase):
|
|||
|
||||
def test_album_cover(self):
|
||||
"""Test the Album Cover widget."""
|
||||
self.assertDictEqual(emmental.tracklist.row.AlbumCover.Cache, {})
|
||||
cache = emmental.tracklist.row.AlbumCover.Cache
|
||||
|
||||
row = emmental.tracklist.row.AlbumCover(self.listitem, "cover")
|
||||
self.assertIsInstance(row, emmental.tracklist.row.TrackRow)
|
||||
self.assertIsInstance(row.child, Gtk.Picture)
|
||||
|
@ -206,10 +202,9 @@ class TestTrackRowWidgets(tests.util.TestCase):
|
|||
row.bind()
|
||||
self.assertEqual(row.filepath, tests.util.COVER_JPG)
|
||||
|
||||
self.assertEqual(len(cache), 1)
|
||||
self.assertIsInstance(cache[tests.util.COVER_JPG], Gdk.Texture)
|
||||
self.assertEqual(len(emmental.texture.CACHE), 1)
|
||||
self.assertEqual(row.child.get_paintable(),
|
||||
cache[tests.util.COVER_JPG])
|
||||
emmental.texture.CACHE[tests.util.COVER_JPG])
|
||||
self.assertTrue(row.child.get_has_tooltip())
|
||||
|
||||
self.album.cover = None
|
||||
|
|
Loading…
Reference in New Issue