Same API but now retrieving the album art in threads
[mussorgsky] / src / aa_selection_dialog.py
index b22ecc0..50fcae6 100644 (file)
@@ -1,7 +1,7 @@
 import hildon
 import gtk
 import gobject
-from album_art import MussorgskyAlbumArt
+from album_art_thread import MussorgskyAlbumArt
 
 class AlbumArtSelectionDialog (gtk.Dialog):
 
@@ -19,6 +19,8 @@ class AlbumArtSelectionDialog (gtk.Dialog):
         self.size = size
         self.paths = []
         self.__create_view (size)
+        self.cancel = False
+        self.connect ("response", self.handle_response)
 
         if (downloader):
             self.downloader = downloader
@@ -54,9 +56,16 @@ class AlbumArtSelectionDialog (gtk.Dialog):
     def __get_alternatives_async (self):
         counter = 0
         for (path, thumb) in self.downloader.get_alternatives (self.album, self.artist, self.size):
+            print path, thumb
+            if (self.cancel):
+                return False
             self.paths.insert (counter, (path, thumb))
-            self.images[counter].set_from_file (thumb)
-            self.event_boxes [counter].set_sensitive (True)
+            if (thumb):
+                print "Setting", thumb, "as image"
+                self.images[counter].set_from_file (thumb)
+                self.event_boxes [counter].set_sensitive (True)
+            else:
+                continue
             counter += 1
             while (gtk.events_pending()):
                 gtk.main_iteration()
@@ -79,6 +88,10 @@ class AlbumArtSelectionDialog (gtk.Dialog):
         return (self.selection_img, self.selection_thumb)
 
     
+    def handle_response (self, widget, response_id):
+        self.cancel = True
+        # Return False to continue propagating the signal
+        return False
 
 if __name__ == "__main__":