Added missing files
[jamaendo] / jamaui / search.py
1 import gtk
2 import hildon
3 import jamaendo
4 from playerwindow import open_playerwindow
5
6 class SearchWindow(hildon.StackableWindow):
7     def __init__(self):
8         hildon.StackableWindow.__init__(self)
9         self.set_title("Search")
10
11         vbox = gtk.VBox(False, 0)
12
13         hbox = gtk.HBox()
14         self.entry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
15         self.entry.set_placeholder("Search")
16         self.entry.connect('activate', self.on_search)
17         btn = hildon.GtkButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
18         btn.set_label("Go")
19         btn.connect('clicked', self.on_search)
20         hbox.pack_start(self.entry, True, True, 0)
21         hbox.pack_start(btn, False)
22
23         btnbox = gtk.HBox()
24         playbtn = hildon.GtkButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
25         playbtn.set_label("Play selected")
26         playbtn.connect('clicked', self.play_selected)
27         btnbox.pack_start(playbtn, False)
28
29         self.results = hildon.TouchSelector(text=True)
30         self.results.connect("changed", self.selection_changed)
31         self.results.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
32
33         vbox.pack_start(hbox, False)
34         vbox.pack_start(self.results, True, True, 0)
35         vbox.pack_start(btnbox, False)
36
37         self.add(vbox)
38
39         self.idmap = {}
40
41         self.pwnd = None
42
43     def on_search(self, w):
44         txt = self.entry.get_text()
45         for album in jamaendo.search_albums(query=txt):
46             title = "%s - %s" % (album.artist_name, album.name)
47             self.idmap[title] = album
48             self.results.append_text(title)
49
50     def selection_changed(self, results, userdata):
51         pass
52
53     def play_selected(self, btn):
54         current_selection = self.results.get_current_text()
55
56         album = self.idmap[current_selection]
57         tracks = jamaendo.get_tracks(album.ID)
58         if tracks:
59             wnd = open_playerwindow(tracks)
60             wnd.on_play(None)