rind: Calculate a fixed height for album art

And make sure we center the pixbuf in the GtkImage by allowing the image
to expand to its maximum width.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2020-01-02 15:47:16 -05:00
parent a7438b2be3
commit 1891bc8f61
2 changed files with 9 additions and 8 deletions

View File

@ -27,8 +27,9 @@ def set_image(data):
set_scaled_image()
def set_scaled_image():
new_w = Paned.get_position()
new_h = (Pixbuf.get_height() * new_w) / Pixbuf.get_width()
pos = Paned.get_position()
new_h = pos * 0.9
new_w = min((Pixbuf.get_width() * new_h) / Pixbuf.get_height(), pos)
if new_h > 0:
pix = Pixbuf.scale_simple(new_w, new_h, GdkPixbuf.InterpType.BILINEAR)
Image.set_from_pixbuf(pix)

View File

@ -32,8 +32,8 @@ class TestAudioArtwork(unittest.TestCase):
self.assertEqual(artwork.Pixbuf.get_width(), 512)
pbuf = artwork.Image.get_pixbuf()
self.assertEqual(pbuf.get_height(), 150)
self.assertEqual(pbuf.get_width(), 150)
self.assertEqual(pbuf.get_height(), 135)
self.assertEqual(pbuf.get_width(), 135)
playbin.set_uri(test_track)
self.assertEqual(artwork.Pixbuf, artwork.Default)
@ -44,10 +44,10 @@ class TestAudioArtwork(unittest.TestCase):
gtk.main_loop(delay=0.1)
pbuf = artwork.Image.get_pixbuf()
self.assertEqual(pbuf.get_height(), 150)
self.assertEqual(pbuf.get_width(), 150)
self.assertEqual(pbuf.get_height(), 135)
self.assertEqual(pbuf.get_width(), 135)
artwork.Paned.set_position(140)
pbuf = artwork.Image.get_pixbuf()
self.assertEqual(pbuf.get_height(), 140)
self.assertEqual(pbuf.get_width(), 140)
self.assertEqual(pbuf.get_height(), 126)
self.assertEqual(pbuf.get_width(), 126)