rind: Set album artwork through an idle task
This lets us set the album art once per track, rather than up to three times. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
1891bc8f61
commit
4e1e2b0d0a
|
@ -1,8 +1,9 @@
|
|||
# Copyright 2019 (c) Anna Schumaker.
|
||||
from .. import gtk
|
||||
from gi.repository import GdkPixbuf, Gtk
|
||||
from gi.repository import GdkPixbuf, Gtk, GLib
|
||||
|
||||
Default = Gtk.IconTheme.get_default().load_icon("applications-multimedia-symbolic", 512, 0)
|
||||
IdleCount = 0
|
||||
Image = gtk.Builder.get_object("album_artwork")
|
||||
Paned = gtk.Builder.get_object("sidebar_pane")
|
||||
Pixbuf = Default
|
||||
|
@ -10,7 +11,7 @@ Pixbuf = Default
|
|||
def reset():
|
||||
global Pixbuf
|
||||
Pixbuf = Default
|
||||
set_scaled_image()
|
||||
set_scaled_image_idle()
|
||||
|
||||
def resize(*args):
|
||||
if Pixbuf != None:
|
||||
|
@ -24,7 +25,7 @@ def set_image(data):
|
|||
loader.write(data)
|
||||
Pixbuf = loader.get_pixbuf()
|
||||
loader.close()
|
||||
set_scaled_image()
|
||||
set_scaled_image_idle()
|
||||
|
||||
def set_scaled_image():
|
||||
pos = Paned.get_position()
|
||||
|
@ -34,3 +35,15 @@ def set_scaled_image():
|
|||
pix = Pixbuf.scale_simple(new_w, new_h, GdkPixbuf.InterpType.BILINEAR)
|
||||
Image.set_from_pixbuf(pix)
|
||||
set_scaled_image()
|
||||
|
||||
def __set_scaled_image_idle():
|
||||
global IdleCount
|
||||
if (IdleCount := IdleCount - 1) == 0:
|
||||
set_scaled_image()
|
||||
return GLib.SOURCE_REMOVE
|
||||
return GLib.SOURCE_CONTINUE
|
||||
|
||||
def set_scaled_image_idle():
|
||||
global IdleCount
|
||||
if (IdleCount := IdleCount + 1) == 1:
|
||||
GLib.idle_add(__set_scaled_image_idle, priority=GLib.PRIORITY_LOW)
|
||||
|
|
|
@ -18,13 +18,16 @@ class TestAudioArtwork(unittest.TestCase):
|
|||
self.assertIsInstance(artwork.Default, GdkPixbuf.Pixbuf)
|
||||
self.assertIsInstance(artwork.Image, Gtk.Image)
|
||||
self.assertIsInstance(artwork.Paned, Gtk.Paned)
|
||||
self.assertEqual(artwork.IdleCount, 0)
|
||||
self.assertEqual(artwork.Pixbuf, artwork.Default)
|
||||
self.assertTrue(artwork.Image.is_visible())
|
||||
|
||||
def test_artwork_load(self):
|
||||
artwork.Paned.set_position(150)
|
||||
playbin.set_uri(test_track, Gst.State.PAUSED)
|
||||
gtk.main_loop(delay=0.1)
|
||||
self.assertEqual(artwork.IdleCount, 1)
|
||||
while (artwork.IdleCount > 0):
|
||||
gtk.main_loop()
|
||||
|
||||
self.assertTrue(artwork.Image.is_visible())
|
||||
self.assertEqual(artwork.Image.get_storage_type(), Gtk.ImageType.PIXBUF)
|
||||
|
@ -41,7 +44,8 @@ class TestAudioArtwork(unittest.TestCase):
|
|||
def test_artwork_resize(self):
|
||||
artwork.Paned.set_position(150)
|
||||
playbin.set_uri(test_track, Gst.State.PAUSED)
|
||||
gtk.main_loop(delay=0.1)
|
||||
while (artwork.IdleCount > 0):
|
||||
gtk.main_loop()
|
||||
|
||||
pbuf = artwork.Image.get_pixbuf()
|
||||
self.assertEqual(pbuf.get_height(), 135)
|
||||
|
|
Loading…
Reference in New Issue