1 #!/usr/bin/env python2.5
5 from album_art_spec import getCoverArtThumbFileName
6 from download_dialog import MussorgskyAlbumArtDownloadDialog
7 from utils import escape_html
8 from aa_selection_dialog import AlbumArtSelectionDialog, RESPONSE_CLICK
12 EMPTY_PIXBUF = gtk.gdk.Pixbuf (gtk.gdk.COLORSPACE_RGB, False, 8, 64, 64)
14 class MussorgskyAlbumArtPanel (hildon.StackableWindow):
16 def __init__ (self, album_artists):
17 hildon.StackableWindow.__init__ (self)
18 self.set_title ("Album art handling")
19 self.set_border_width (12)
20 print "Create view :",time.time ()
22 print "Create view (DONE):", time.time ()
23 self.downloader = None
24 # Visible string, image, artist, album, painted!
25 self.model = gtk.ListStore (str, gtk.gdk.Pixbuf, str, str, bool)
26 print "Populate model :", time.time ()
27 for p in album_artists:
30 t = ("".join (["<b>", escape_html (p[0]),"</b>\n<small>",
31 escape_html(p[1]), "</small>"]), None, p[1], p[0], False)
33 print "Populate model (DONE):", time.time ()
35 self.treeview.set_model (self.model)
37 def __create_view (self):
38 self.treeview = gtk.TreeView ()
39 self.treeview.connect ("row-activated", self.row_activated_cb)
41 artist_column = gtk.TreeViewColumn ("Artist", gtk.CellRendererText (), markup=0)
42 artist_column.set_expand (True)
43 self.treeview.append_column (artist_column)
45 renderer = gtk.CellRendererPixbuf ()
46 album_art = gtk.TreeViewColumn ("Album art", renderer, pixbuf=1)
47 # This doesn't have real effect:
48 album_art.set_sizing (gtk.TREE_VIEW_COLUMN_FIXED)
49 album_art.set_fixed_width (64)
51 album_art.set_cell_data_func (renderer, self.album_art_cell_data_cb)
52 self.treeview.append_column (album_art)
54 pannable_area = hildon.PannableArea ()
55 pannable_area.add (self.treeview)
56 self.add (pannable_area)
59 menu = hildon.AppMenu ()
60 automatic_retrieval = hildon.Button (hildon.BUTTON_STYLE_NORMAL,
61 hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
62 automatic_retrieval.set_title ("Automatic retrieval")
63 automatic_retrieval.connect ("clicked", self.get_all_album_art)
64 menu.append (automatic_retrieval)
66 self.set_app_menu (menu)
68 def album_art_cell_data_cb (self, column, cell, model, iter):
69 pixbuf, album, not_first_time = model.get (iter, 1, 3, 4)
72 #print "Calling album art cell data cb", model.get (iter, 3)
73 album_art_path = getCoverArtThumbFileName (album)
74 if (os.path.exists (album_art_path)):
75 pxb = gtk.gdk.pixbuf_new_from_file_at_size (album_art_path, 64, 64)
76 model.set (iter, 1, pxb)
78 #print "Cannot find thumbnail in '%s'" % (album_art_path)
79 model.set (iter, 1, EMPTY_PIXBUF)
82 model.set (iter, 4, True)
84 def get_all_album_art (self, user_data):
85 dialog = MussorgskyAlbumArtDownloadDialog (self)
87 dialog.do_the_job (self.model)
89 def row_activated_cb (self, treeview, path, view_colum):
90 it = treeview.get_model ().get_iter (path)
91 album = treeview.get_model ().get_value (it, 3)
92 artist = treeview.get_model ().get_value (it, 2)
94 dialog = AlbumArtSelectionDialog (self, artist, album, 5)
97 response = dialog.run ()
98 if (response == RESPONSE_CLICK):
99 (img, thumb) = dialog.get_selection ()
101 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 64, 64)
102 treeview.get_model ().set (it, 1, pixbuf)
104 treeview.get_model ().set (it, 1, EMPTY_PIXBUF)
108 if __name__ == "__main__":
111 artists_albums = [("Artist %d the greatest bolero singer in the universe" % i, "Album <%d>" % i) for i in range (0, 10000)]
113 # Overwrite the get thumb path for testing
114 def local_file (path):
115 return "../thumb%d.124.jpeg" % (random.randint (0, 3))
117 global getCoverArtThumbFileName
118 getCoverArtThumbFileName = local_file
120 window = MussorgskyAlbumArtPanel (artists_albums)
121 window.connect ("destroy", gtk.main_quit )