summaryrefslogtreecommitdiff
path: root/configs/apps/gladevcp/by-widget/combobox_manual_list.py
blob: 0607cf944a14cda630f75ee5c5af376feeb3a8c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'''
    HAL combobox

    demo for adding a dynamic list of values

    Michael Haberler 12/2010
'''

#import pygtk
import gtk
import gobject

debug = 0


class HandlerClass:

    def on_destroy(self,obj,data=None):
        print "on_destroy"
        self.halcomp.exit() # avoid lingering HAL component
        gtk.main_quit()

    def on_changed(self, combobox, data=None):
        model = combobox.get_model()
        index = combobox.get_active()
        if index:
            print 'index of selected value',index
        return


    def __init__(self, halcomp,builder,useropts):
        self.halcomp = halcomp
        self.builder = builder
        self.useropts = useropts

        self.combo = self.builder.get_object('hal_combobox1')


        self.list_store = gtk.ListStore(gobject.TYPE_FLOAT)
        self.list_store.append([3.14])
        self.list_store.append([2.71828])
        self.list_store.append([1.67])
        self.list_store.append([47.11])
        self.list_store.append([42.0])
        self.combo.set_model(self.list_store)
        self.combo.set_active(0)
        cell = gtk.CellRendererText()
        self.combo.pack_start(cell, True)
        self.combo.add_attribute(cell, "text", 0)


def get_handlers(halcomp,builder,useropts):

    global debug
    for cmd in useropts:
        exec cmd in globals()

    return [HandlerClass(halcomp,builder,useropts)]