From 6773d9837ef2a7e7e19d7aa7d1bda7aaa1d406d3 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 18 Jun 2011 09:23:50 -0400 Subject: [PATCH] ocarina: Set album art in the main thread I use a gobject signal to force setting album art in the main loop. In theory, this should cut down on the number of crashes I see when album art is fetched. --- ocarina/__init__.py | 3 ++- ocarina/callbacks.py | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ocarina/__init__.py b/ocarina/__init__.py index 9c1ce209..355c5c69 100644 --- a/ocarina/__init__.py +++ b/ocarina/__init__.py @@ -26,7 +26,8 @@ import library import callbacks def run(): - callbacks.on_get_art("images/ocarina.png", 0) + import body + body.footer.set_art("images/ocarina.png") libsaria.startup() print "Startup took:", uptime() gtk.threads_enter() diff --git a/ocarina/callbacks.py b/ocarina/callbacks.py index d375118d..3cd7fe44 100644 --- a/ocarina/callbacks.py +++ b/ocarina/callbacks.py @@ -1,5 +1,8 @@ # Bryan Schumaker (4 / 20 / 2011) +import gtk +import gobject + import libsaria import queue from ocarina import body @@ -26,11 +29,23 @@ def on_like(like): footer.on_like(like) callbacks.on_like = on_like + +# A bit of a hack to force setting album art in the main thread +# Basically, I create a new signal and trigger it when new album +# art arrives +gobject.signal_new("get_art", gobject.GObject, gobject.SIGNAL_RUN_LAST, + gobject.TYPE_NONE, + (gobject.TYPE_INT, gobject.TYPE_STRING)) + +def on_get_art_helper(obj, id, path): + if id == libsaria.sources.get_cur_id(): + footer.set_art(path) + +on_get_art_obj = gobject.GObject() +on_get_art_obj.connect("get_art", on_get_art_helper) + def on_get_art(path, id): - cur_id = libsaria.sources.get_cur_id() - if [id] != cur_id: - path = "images/ocarina.png" - footer.set_art(path) + on_get_art_obj.emit("get_art", id, path) callbacks.on_get_art = on_get_art def on_load_playlist():