1 #!/usr/bin/env python2.5
3 from album_art import MussorgskyAlbumArt
5 class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
7 def __init__ (self, parent):
8 gtk.Dialog.__init__ (self,
9 "Downloading album art", parent,
10 gtk.DIALOG_DESTROY_WITH_PARENT,
11 (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)
13 self.downloader = MussorgskyAlbumArt ()
14 self.set_title ("Downloading album art")
15 self.connect ("response", self.handle_response)
19 def create_view (self):
21 hbox = gtk.HBox (homogeneous=False)
23 self.album_art = gtk.Image ()
24 self.album_art.set_size_request (124, 124)
26 hbox.pack_start (self.album_art, expand=False, fill=True)
29 self.status_label = gtk.Label ("")
30 labels.pack_start (self.status_label)
31 self.current_label = gtk.Label ("")
32 labels.pack_start (self.current_label)
34 hbox.pack_start (labels, expand=True, fill=False)
39 def do_the_job (self, artist_albums):
40 TOTAL = len (artist_albums)
43 for (artist, album) in artist_albums:
44 self.status_label.set_text ("Retrieving (%d/%d)" % (current, TOTAL))
45 self.current_label.set_markup ("<b>%s - %s</b>" % (artist, album))
47 while (gtk.events_pending()):
54 (image, thumb) = self.downloader.get_album_art (artist, album)
55 except LookupError, e:
56 print "Error processing %s - %s" % (artist, album)
58 self.album_art.set_from_stock (gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
62 self.album_art.set_from_file (thumb)
64 self.album_art.set_from_stock (gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
69 def handle_response (self, widget, response_id):
70 if (response_id == gtk.RESPONSE_DELETE_EVENT):
71 print "Cancel the work!"
75 if __name__ == "__main__":
77 PAIRS_NO = [("Led Zeppelin", "Led Zeppelin IV"),
78 ("Pink Floyd", "The Wall"),
79 ("Deep purple", "Made in Japan"),
81 ("Dinah Washington", "")]
83 PAIRS = [ ("Artist %d" % i, "Album %d" %i) for i in range (0, 100)]
85 def clicked_button (self):
86 aadd = MussorgskyAlbumArtDownloadDialog (w)
88 aadd.do_the_job (PAIRS)
93 button = gtk.Button ("click")
94 button.connect ("clicked", clicked_button)