1 #!/usr/bin/env python2.5
4 from album_art_spec import getCoverArtThumbFileName
5 from download_dialog import MussorgskyAlbumArtDownloadDialog
6 from utils import escape_html
7 from aa_selection_dialog import AlbumArtSelectionDialog
9 class MussorgskyAlbumArtPanel (hildon.StackableWindow):
11 def __init__ (self, album_artists):
12 hildon.StackableWindow.__init__ (self)
13 self.set_title ("Album art handling")
14 self.set_border_width (12)
16 self.downloader = None
17 # Visible string, image, artist, album
18 self.model = gtk.ListStore (str, gtk.gdk.Pixbuf, str, str)
20 for p in album_artists:
23 album_art_path = getCoverArtThumbFileName (p[0])
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[0]), escape_html(p[1])), pixbuf, p[1], p[0])
31 self.treeview.set_model (self.model)
33 def __create_view (self):
34 self.treeview = gtk.TreeView ()
35 self.treeview.connect ("row-activated", self.row_activated_cb)
37 artist_column = gtk.TreeViewColumn ("Artist", gtk.CellRendererText (), markup=0)
38 artist_column.set_expand (True)
39 self.treeview.append_column (artist_column)
41 album_art = gtk.TreeViewColumn ("Album art", gtk.CellRendererPixbuf (), pixbuf=1)
42 self.treeview.append_column (album_art)
44 pannable_area = hildon.PannableArea ()
45 pannable_area.add (self.treeview)
46 self.add (pannable_area)
49 menu = hildon.AppMenu ()
50 automatic_retrieval = hildon.Button (hildon.BUTTON_STYLE_NORMAL,
51 hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
52 automatic_retrieval.set_title ("Automatic retrieval")
53 automatic_retrieval.connect ("clicked", self.get_all_album_art)
54 menu.append (automatic_retrieval)
56 self.set_app_menu (menu)
58 def get_all_album_art (self, user_data):
59 dialog = MussorgskyAlbumArtDownloadDialog (self)
61 dialog.do_the_job (self.model)
63 def row_activated_cb (self, treeview, path, view_colum):
64 it = treeview.get_model ().get_iter (path)
65 album = treeview.get_model ().get_value (it, 3)
66 artist = treeview.get_model ().get_value (it, 2)
68 dialog = AlbumArtSelectionDialog (self, artist, album, 5)
71 response = dialog.run ()
73 (img, thumb) = dialog.get_selection ()
75 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 64, 64)
76 treeview.get_model ().set (it, 1, pixbuf)
78 treeview.get_model ().set (it, 1, None)
81 if __name__ == "__main__":
83 artists_albums = [("Artist %d the greatest bolero singer in the universe" % i, "Album <%d>" % i) for i in range (0, 100)]
86 window = MussorgskyAlbumArtPanel (artists_albums)
87 window.connect ("destroy", gtk.main_quit )