New year, big checkin
[jamaendo] / jamaui / showartist.py
1 import gtk
2 import hildon
3 import jamaendo
4 from playerwindow import open_playerwindow
5
6 class ShowArtist(hildon.StackableWindow):
7     def __init__(self, artist):
8         hildon.StackableWindow.__init__(self)
9         self.set_title("Artist")
10         self.artist = artist
11
12         self.panarea = hildon.PannableArea()
13         vbox = gtk.VBox(False, 0)
14
15         name = gtk.Label()
16         name.set_markup('<big>%s</big>'%(artist.name))
17         vbox.pack_start(name, False)
18
19         self.album_store = gtk.ListStore(str, int)
20         self.album_view = gtk.TreeView(self.album_store)
21         col = gtk.TreeViewColumn('Name')
22         self.album_view.append_column(col)
23         cell = gtk.CellRendererText()
24         col.pack_start(cell, True)
25         col.add_attribute(cell, 'text', 0)
26         self.album_view.set_search_column(0)
27         col.set_sort_column_id(0)
28         self.album_view.connect('row-activated', self.row_activated)
29
30
31         self.panarea.add(self.album_view)
32         vbox.pack_start(self.panarea, True, True, 0)
33         self.add(vbox)
34
35         for album in jamaendo.get_albums(artist.ID):
36             self.album_store.append([album.name, album.ID])
37
38     def row_activated(self, treeview, path, view_column):
39         treeiter = self.album_store.get_iter(path)
40         title, _id = self.album_store.get(treeiter, 0, 1)
41         album = jamaendo.get_album(_id)
42         if isinstance(album, list):
43             album = album[0]
44         self.open_item(album)
45
46     def open_item(self, item):
47         if isinstance(item, jamaendo.Album):
48             from showalbum import ShowAlbum
49             wnd = ShowAlbum(item)
50             wnd.show_all()
51         elif isinstance(item, jamaendo.Artist):
52             wnd = ShowArtist(item)
53             wnd.show_all()
54         elif isinstance(item, jamaendo.Track):
55             wnd = open_playerwindow()
56             wnd.play_tracks([item])