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)
15 _ = i18n.language.gettext
17 class MussorgskyAlbumArtPanel (hildon.StackableWindow):
19 def __init__ (self, album_artists):
20 hildon.StackableWindow.__init__ (self)
21 self.set_title (_("Album art selection"))
22 self.set_border_width (12)
24 self.downloader = None
25 # Visible string, image, artist, album, painted!
26 self.model = gtk.ListStore (str, gtk.gdk.Pixbuf, str, str, bool)
27 for p in album_artists:
30 t = (None, None, p[1], p[0], False)
33 self.treeview.set_model (self.model)
35 def __create_view (self):
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 renderer = gtk.CellRendererPixbuf ()
44 album_art = gtk.TreeViewColumn ("Album art", renderer, pixbuf=1)
45 # This doesn't have real effect:
46 album_art.set_sizing (gtk.TREE_VIEW_COLUMN_FIXED)
47 album_art.set_fixed_width (64)
49 album_art.set_cell_data_func (renderer, self.album_art_cell_data_cb)
50 self.treeview.append_column (album_art)
52 pannable_area = hildon.PannableArea ()
53 pannable_area.add (self.treeview)
54 self.add (pannable_area)
57 menu = hildon.AppMenu ()
58 automatic_retrieval = hildon.Button (hildon.BUTTON_STYLE_NORMAL,
59 hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
60 automatic_retrieval.set_title (_("Automatic download"))
61 automatic_retrieval.connect ("clicked", self.get_all_album_art)
62 menu.append (automatic_retrieval)
64 self.set_app_menu (menu)
66 def album_art_cell_data_cb (self, column, cell, model, iter):
67 text, pixbuf, artist, album, not_first_time = model.get (iter, 0, 1, 2, 3, 4)
70 text = "".join (["<b>", escape_html (album),"</b>\n<small>",
71 escape_html(artist), "</small>"])
72 model.set (iter, 0, text)
75 #print "Calling album art cell data cb", model.get (iter, 3)
76 album_art_path = getCoverArtThumbFileName (album)
77 if (os.path.exists (album_art_path)):
78 pxb = gtk.gdk.pixbuf_new_from_file_at_size (album_art_path, 64, 64)
79 model.set (iter, 1, pxb)
81 #print "Cannot find thumbnail in '%s'" % (album_art_path)
82 model.set (iter, 1, EMPTY_PIXBUF)
85 model.set (iter, 4, True)
87 def get_all_album_art (self, user_data):
88 dialog = MussorgskyAlbumArtDownloadDialog (self)
90 dialog.do_the_job (self.model)
92 def row_activated_cb (self, treeview, path, view_colum):
93 it = treeview.get_model ().get_iter (path)
94 artist = treeview.get_model ().get_value (it, 2)
95 album = treeview.get_model ().get_value (it, 3)
96 if (artist.find ('|') != -1):
97 artist = "Various artists"
99 dialog = AlbumArtSelectionDialog (self, artist, album, 5)
102 response = dialog.run ()
103 if (response == RESPONSE_CLICK):
104 (img, thumb) = dialog.get_selection ()
106 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 64, 64)
107 treeview.get_model ().set (it, 1, pixbuf)
109 treeview.get_model ().set (it, 1, EMPTY_PIXBUF)
113 if __name__ == "__main__":
116 artists_albums = [("Artist %d|artist Y" % i, "Album <%d>" % i) for i in range (0, 10)]
118 # Overwrite the get thumb path for testing
119 def local_file (path):
120 return "../thumb%d.124.jpeg" % (random.randint (0, 3))
122 global getCoverArtThumbFileName
123 getCoverArtThumbFileName = local_file
125 window = MussorgskyAlbumArtPanel (artists_albums)
126 window.connect ("destroy", gtk.main_quit )