audio: Create a class for showing album art
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
828fca9abd
commit
16d31dfd3a
|
@ -0,0 +1,46 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from gi.repository import Gtk, GdkPixbuf, Gst
|
||||
|
||||
class Artwork(Gtk.AspectFrame):
|
||||
def __init__(self):
|
||||
Gtk.AspectFrame.__init__(self)
|
||||
self.picture = Gtk.Picture()
|
||||
|
||||
self.frame = Gtk.Frame()
|
||||
self.frame.set_child(self.picture)
|
||||
|
||||
self.set_child(self.frame)
|
||||
self.set_obey_child(False)
|
||||
self.set_margin_start(5)
|
||||
self.set_margin_end(5)
|
||||
self.set_margin_top(5)
|
||||
self.set_margin_bottom(5)
|
||||
self.set_ratio(1.0)
|
||||
self.reset()
|
||||
|
||||
def get_default_path(self):
|
||||
display = self.picture.get_display()
|
||||
theme = Gtk.IconTheme.get_for_display(display)
|
||||
icon = theme.lookup_icon("emmental", [ ], 1024, 1, 0, 0)
|
||||
return icon.get_file().get_path()
|
||||
|
||||
def set_from_data(self, data):
|
||||
loader = GdkPixbuf.PixbufLoader()
|
||||
loader.write(data)
|
||||
|
||||
pixbuf = loader.get_pixbuf()
|
||||
self.picture.set_pixbuf(pixbuf)
|
||||
loader.close()
|
||||
|
||||
def set_from_sample(self, sample):
|
||||
buffer = sample.get_buffer()
|
||||
|
||||
(res, map) = buffer.map(Gst.MapFlags.READ)
|
||||
if res == True:
|
||||
self.set_from_data(map.data)
|
||||
buffer.unmap(map)
|
||||
else:
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
self.picture.set_filename(self.get_default_path())
|
|
@ -0,0 +1,27 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import artwork
|
||||
from gi.repository import Gtk
|
||||
import pathlib
|
||||
import unittest
|
||||
|
||||
Path = pathlib.Path("./data/hicolor/scalable/apps/emmental.svg")
|
||||
|
||||
class TestAudioArtwork(unittest.TestCase):
|
||||
def test_audio_artwork_init(self):
|
||||
art = artwork.Artwork()
|
||||
|
||||
self.assertIsInstance(art, Gtk.AspectFrame)
|
||||
self.assertIsInstance(art.frame, Gtk.Frame)
|
||||
self.assertIsInstance(art.picture, Gtk.Picture)
|
||||
|
||||
self.assertEqual(art.get_child(), art.frame)
|
||||
self.assertEqual(art.frame.get_child(), art.picture)
|
||||
self.assertEqual(art.get_obey_child(), False)
|
||||
self.assertEqual(art.get_ratio(), 1.0)
|
||||
|
||||
self.assertEqual(art.get_margin_start(), 5)
|
||||
self.assertEqual(art.get_margin_end(), 5)
|
||||
self.assertEqual(art.get_margin_top(), 5)
|
||||
self.assertEqual(art.get_margin_bottom(), 5)
|
||||
|
||||
self.assertEqual(art.get_default_path(), str(Path.absolute()))
|
Loading…
Reference in New Issue