1 #!/usr/bin/env python2.5
3 from album_art_thread import MussorgskyAlbumArt
4 from utils import escape_html
6 class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
8 def __init__ (self, parent, downloader=None):
9 gtk.Dialog.__init__ (self,
10 "Downloading album art", parent,
11 gtk.DIALOG_DESTROY_WITH_PARENT,
12 (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)
15 self.downloader = downloader
17 self.downloader = MussorgskyAlbumArt ()
19 self.set_title ("Downloading album art")
20 self.connect ("response", self.handle_response)
24 def __create_view (self):
26 hbox = gtk.HBox (homogeneous=False)
28 self.album_art = gtk.Image ()
29 self.album_art.set_size_request (124, 124)
31 hbox.pack_start (self.album_art, expand=False, fill=True)
34 self.previous_label = gtk.Label ("")
35 labels.pack_start (self.previous_label)
36 self.current_label = gtk.Label ("")
37 labels.pack_start (self.current_label)
39 hbox.pack_start (labels, expand=True, fill=False)
44 def do_the_job (self, artist_albums_model):
46 each row: ("Visible text", pixbuf, Artist, Album)
48 TOTAL = len (artist_albums_model)
51 it = artist_albums_model.get_iter_first ()
53 while (gtk.events_pending()):
59 artist = artist_albums_model.get_value (it, 2)
60 album = artist_albums_model.get_value (it, 3)
62 if (artist.find ('|') != -1):
63 real_artist = "Various artists"
66 self.current_label.set_markup ("<small>Trying: %s - %s</small>" % (escape_html(real_artist),
70 while (gtk.events_pending()):
76 (image, thumb) = self.downloader.get_album_art (real_artist, album)
78 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 64, 64)
79 artist_albums_model.set_value (it, 1, pixbuf)
81 print "Error processing %s - %s" % (artist, album)
85 self.set_title ("Downloading album art (%d/%d)" % (current, TOTAL))
86 self.previous_label.set_markup ("<b>%s - %s</b>" % (escape_html(real_artist), escape_html(album)))
89 self.album_art.set_from_file (thumb)
91 self.album_art.set_from_stock (gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
94 it = artist_albums_model.iter_next (it)
97 def handle_response (self, widget, response_id):
98 if (response_id == gtk.RESPONSE_DELETE_EVENT):
99 print "Cancel the work!"
103 if __name__ == "__main__":
107 class MockDownloader:
109 self.alt = [("../hendrix.jpeg", "../hendrix-thumb.jpeg"),
110 ("../hoover.jpeg", "../hoover-thumb.jpeg"),
111 ("../backbeat.jpeg", "../backbeat-thumb.jpeg"),
112 ("../dylan.jpeg", "../dylan-thumb.jpeg")]
114 def get_album_art (self, artist, album, force=False):
116 return self.alt [random.randint (0, len (self.alt)-1)]
118 PAIRS_store = gtk.ListStore (str, gtk.gdk.Pixbuf, str, str)
119 for i in range (0, 100):
120 PAIRS_store.append (("blablabal", None, "Artist %d" % i, "Album %d" %i))
122 def clicked_button (self):
123 aadd = MussorgskyAlbumArtDownloadDialog (w, MockDownloader ())
125 aadd.do_the_job (PAIRS_store)
130 button = gtk.Button ("click")
131 button.connect ("clicked", clicked_button)