tiny color change
[jamaendo] / jamaui / listbox.py
1 # what the fuck, GTK
2 import gtk
3 import hildon
4
5 class ListBox(gtk.TreeView):
6     def __init__(self):
7         gtk.TreeView.__init__(self)
8         self.store = gtk.ListStore(str)
9         column = gtk.TreeViewColumn("Text")
10         textRenderer = gtk.CellRendererText()
11         column.pack_start(textRenderer, True)
12         column.set_attributes(textRenderer, text = 0)
13         self.append_column(column)
14         self.set_model(self.store)
15
16     def get_text(self, path):
17         it = self.store.get_iter(path)
18         if not it:
19             return None
20         ret = self.store.get(it, 0)
21         return ret[0]
22
23     def get_selected_text(self):
24         model, it = self.get_selection().get_selected()
25         if not it:
26             return None
27         ret = self.store.get(it, 0)
28         return ret[0]
29
30     def append(self, text):
31         self.store.append([text])
32
33     def on_select(self, callback, *args):
34         def cb(lb, path, col):
35             ret = self.get_text(path)
36             if ret:
37                 callback(ret, *args)
38         self.connect('row-activated', cb)
39
40 class ListDialog(gtk.Dialog):
41     def __init__(self, title, parent=None):
42         gtk.Dialog.__init__(self, title, parent)
43         self.listbox = ListBox()
44         panarea = hildon.PannableArea()
45         panarea.add(self.listbox)
46         panarea.set_size_request(800, 300)
47         self.vbox.pack_start(panarea, True, True, 0)
48
49         self.selected = None
50
51         def selector(selected, dialog):
52             if selected:
53                 self.selected = selected
54                 dialog.response(gtk.RESPONSE_OK)
55         self.listbox.on_select(selector, self)
56
57 class ButtonListDialog(gtk.Dialog):
58     def __init__(self, title, parent=None):
59         gtk.Dialog.__init__(self, title, parent)
60         self.panarea = hildon.PannableArea()
61         self.panarea.set_size_request(800, 400)
62         self.buttons = gtk.VBox(False, 0)
63         self.panarea.add_with_viewport(self.buttons)
64         self.vbox.pack_start(self.panarea, True, True, 0)
65
66     def add_button(self, label, clickcb, *args):
67         btn = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH|gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
68         btn.set_label(label)
69         btn.connect('clicked', clickcb, *args)
70         self.buttons.pack_end(btn, False, False, 0)
71