[gnome-music/wip/merge: 123/343] Load album art



commit e501032c3b3d0bc65516fe23e3022857bb074ab2
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Mon Jul 15 18:46:04 2013 +0200

    Load album art

 gnomemusic/albumArtCache.py |   18 +++++++++---------
 gnomemusic/player.py        |    2 +-
 gnomemusic/view.py          |   18 ++++++++++--------
 gnomemusic/widgets.py       |    2 +-
 4 files changed, 21 insertions(+), 19 deletions(-)
---
diff --git a/gnomemusic/albumArtCache.py b/gnomemusic/albumArtCache.py
index 51ef792..807733f 100644
--- a/gnomemusic/albumArtCache.py
+++ b/gnomemusic/albumArtCache.py
@@ -105,22 +105,22 @@ class AlbumArtCache:
             ctx.fill()
 
     def _tryLoad(self, size, artist, album, i, format, callback):
-        if i >= self._keybuilder_funcs.length:
+        if i >= len(self._keybuilder_funcs):
             if format == 'jpeg':
                 self._tryLoad(size, artist, album, 0, 'png', callback)
             else:
                 callback(None)
             return
 
-        key = self._keybuilder_funcs[i].call(self, artist, album)
+        key = self._keybuilder_funcs[i].__call__( artist, album)
         path = GLib.build_filenamev([self.cacheDir, key + '.' + format])
         file = Gio.File.new_for_path(path)
 
-        def on_read_ready(object, res):
+        def on_read_ready(object, res, data=None):
             try:
                 stream = object.read_finish(res)
 
-                def on_pixbuf_ready(source, res):
+                def on_pixbuf_ready(source, res, data=None):
                     try:
                         pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res)
                         width = pixbuf.get_width()
@@ -139,7 +139,7 @@ class AlbumArtCache:
                     self._tryLoad(size, artist, album, ++i, format, callback)
 
                 GdkPixbuf.Pixbuf.new_from_stream_async(stream, None,
-                                                       on_pixbuf_ready)
+                                                       on_pixbuf_ready, None)
                 return
 
             except GLib.Error as error:
@@ -148,7 +148,7 @@ class AlbumArtCache:
 
             self._tryLoad(size, artist, album, ++i, format, callback)
 
-        file.read_async(GLib.PRIORITY_DEFAULT, None, on_read_ready)
+        file.read_async(GLib.PRIORITY_DEFAULT, None, on_read_ready, None)
 
     def lookup(self, size, artist, album, callback):
         self._tryLoad(size, artist, album, 0, 'jpeg', callback)
@@ -190,11 +190,11 @@ class AlbumArtCache:
     def normalizeAndHash(self, input_str):
         normalized = " "
 
-        if input_str is not None and input_str.length() > 0:
+        if input_str is not None and len(input_str) > 0:
             normalized = self.stripInvalidEntities(input_str)
             normalized = GLib.utf8_normalize(normalized, -1,
                                              GLib.NormalizeMode.NFKD)
-            normalized = normalized.toLowerCase()
+            normalized = normalized.lower()
 
         return GLib.compute_checksum_for_string(GLib.ChecksumType.MD5,
                                                 normalized, -1)
@@ -242,7 +242,7 @@ class AlbumArtCache:
                 p = p[pos2 + 1:]
 
                 # Do same again for position AFTER block
-                if p.length == 0:
+                if len(p) == 0:
                     blocks_done = True
 
         # Now convert chars to lower case
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index b26e383..a96a65d 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -92,7 +92,7 @@ class Player(GObject.GObject):
         self.bus.connect("message::eos", self._onBusEos)
         self._setupView()
         if self.nextTrack:
-            GLib.idle_add(GLib.PRIORITY_HIGH, self._onGLibIdle)
+            GLib.idle_add(self._onGLibIdle)
         elif (self.repeat == RepeatType.NONE):
             self.stop()
             self.playBtn.set_image(self._playImage)
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 7871862..f105db0 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -183,7 +183,7 @@ class ViewContainer(Gtk.Stack):
                 self._model.set(iter,
                                 [0, 1, 2, 3, 4, 5, 7, 8, 9, 10],
                                 [str(item.get_id()), "", item.get_title(), artist, self._symbolicIcon, item, 
-1, self.errorIconName, False, True])
-            GLib.idle_add(300, self._updateAlbumArt, item, iter)
+            GLib.idle_add(self._updateAlbumArt, item, iter)
 
     def _getRemainingItemCount(self):
         count = -1
@@ -194,15 +194,17 @@ class ViewContainer(Gtk.Stack):
         return count - self._offset
 
     def _updateAlbumArt(self, item, iter):
-        albumArtCache.lookupOrResolve(item, self._iconWidth, self._iconHeight, self._albumArtCacheLookUp)
+        def _albumArtCacheLookUp(icon, data=None):
+            if icon:
+                self._model.set_value(iter, 4, albumArtCache.getDefault().makeIconFrame(icon))
+            else:
+                self._model.set_value(iter, 4, None)
+                self.emit("album-art-updated")
+
+        albumArtCache.getDefault().lookupOrResolve(item, self._iconWidth, self._iconHeight, 
_albumArtCacheLookUp)
         return False
 
-    def _albumArtCacheLookUp(self, icon):
-        if icon:
-            self._model.set_value(iter, 4, albumArtCache.makeIconFrame(icon))
-        else:
-            self._model.set_value(iter, 4, None)
-            self.emit("album-art-updated")
+
 
     def _addListRenderers(self):
         pass
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index a9f3527..3082cf0 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -429,7 +429,7 @@ class ArtistAlbumWidget(Gtk.HBox):
 
         self.cache = AlbumArtCache.getDefault()
         pixbuf = self.cache.makeDefaultIcon(128, 128)
-        GLib.idle_add(300, self._updateAlbumArt)
+        GLib.idle_add(self._updateAlbumArt)
 
         self.ui.get_object("cover").set_from_pixbuf(pixbuf)
         self.ui.get_object("title").set_label(album.get_title())


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]