1 #!/usr/bin/env python2.5
3 from album_art 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 self.current_label.set_markup ("<small>Trying: %s - %s</small>" % (escape_html(artist),
66 while (gtk.events_pending()):
72 (image, thumb) = self.downloader.get_album_art (artist, album)
74 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 64, 64)
75 artist_albums_model.set_value (it, 1, pixbuf)
77 print "Error processing %s - %s" % (artist, album)
81 self.set_title ("Downloading album art (%d/%d)" % (current, TOTAL))
82 self.previous_label.set_markup ("<b>%s - %s</b>" % (escape_html(artist), escape_html(album)))
85 self.album_art.set_from_file (thumb)
87 self.album_art.set_from_stock (gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
90 it = artist_albums_model.iter_next (it)
93 def handle_response (self, widget, response_id):
94 if (response_id == gtk.RESPONSE_DELETE_EVENT):
95 print "Cancel the work!"
99 if __name__ == "__main__":
103 class MockDownloader:
105 self.alt = [("../hendrix.jpeg", "../hendrix-thumb.jpeg"),
106 ("../hoover.jpeg", "../hoover-thumb.jpeg"),
107 ("../backbeat.jpeg", "../backbeat-thumb.jpeg"),
108 ("../dylan.jpeg", "../dylan-thumb.jpeg")]
110 def get_album_art (self, artist, album, force=False):
112 return self.alt [random.randint (0, len (self.alt)-1)]
114 PAIRS_store = gtk.ListStore (str, gtk.gdk.Pixbuf, str, str)
115 for i in range (0, 100):
116 PAIRS_store.append (("blablabal", None, "Artist %d" % i, "Album %d" %i))
118 def clicked_button (self):
119 aadd = MussorgskyAlbumArtDownloadDialog (w, MockDownloader ())
121 aadd.do_the_job (PAIRS_store)
126 button = gtk.Button ("click")
127 button.connect ("clicked", clicked_button)