1 #!/usr/bin/env python2.5
4 from album_art_spec import getCoverArtThumbFileName
5 from download_dialog import MussorgskyAlbumArtDownloadDialog
6 from album_art import MussorgskyAlbumArt
7 from utils import escape_html
8 from aa_selection_dialog import AlbumArtSelectionDialog
10 class MussorgskyAlbumArtPanel (hildon.StackableWindow):
12 def __init__ (self, album_artists):
13 hildon.StackableWindow.__init__ (self)
14 self.set_title ("Album art handling")
15 self.set_border_width (12)
17 self.downloader = None
18 self.model = gtk.ListStore (str, gtk.gdk.Pixbuf, str, str)
20 for p in album_artists:
23 album_art_path = getCoverArtThumbFileName (p[1])
25 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (album_art_path, 64, 64)
26 except gobject.GError:
28 t = ("<b>%s</b>\n<small>%s</small>" % (escape_html(p[1]), escape_html(p[0])), pixbuf, p[0], p[1])
31 self.treeview.set_model (self.model)
33 def __create_view (self):
34 vbox = gtk.VBox (spacing=12, homogeneous=False)
36 self.treeview = gtk.TreeView ()
37 self.treeview.connect ("row-activated", self.row_activated_cb)
39 artist_column = gtk.TreeViewColumn ("Artist", gtk.CellRendererText (), markup=0)
40 artist_column.set_expand (True)
41 self.treeview.append_column (artist_column)
43 album_art = gtk.TreeViewColumn ("Album art", gtk.CellRendererPixbuf (), pixbuf=1)
44 self.treeview.append_column (album_art)
46 #vbox.add (self.treeview)
48 pannable_area = hildon.PannableArea ()
49 pannable_area.add (self.treeview)
50 self.add (pannable_area)
53 menu = hildon.AppMenu ()
54 automatic_retrieval = hildon.Button (hildon.BUTTON_STYLE_NORMAL,
55 hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
56 automatic_retrieval.set_title ("Automatic retrieval")
57 automatic_retrieval.connect ("clicked", self.get_all_album_art)
58 menu.append (automatic_retrieval)
60 self.set_app_menu (menu)
62 def get_all_album_art (self, user_data):
63 dialog = MussorgskyAlbumArtDownloadDialog (self)
65 dialog.do_the_job (self.model)
67 def row_activated_cb (self, treeview, path, view_colum):
68 it = treeview.get_model ().get_iter (path)
69 album = treeview.get_model ().get_value (it, 3)
70 artist = treeview.get_model ().get_value (it, 2)
71 if (not self.downloader):
72 self.downloader = MussorgskyAlbumArt ()
74 dialog = AlbumArtSelectionDialog (self, 4)
77 paths = self.downloader.get_alternatives (album, artist, 4)
78 dialog.populate (paths)
80 response = dialog.run ()
82 assert response < len (paths)
83 (img, thumb) = self.downloader.save_alternative (artist, album, paths[response])
84 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 64, 64)
85 treeview.get_model ().set (it, 1, pixbuf)
88 if __name__ == "__main__":
90 artists_albums = [("Artist %d the greatest bolero singer in the universe" % i, "Album <%d>" % i) for i in range (0, 100)]
93 window = MussorgskyAlbumArtPanel (artists_albums)
94 window.connect ("destroy", gtk.main_quit )