summaryrefslogtreecommitdiff
path: root/tests/test_index.py
blob: f877b98fc4d25cb49518a0f3c13e0fc6ee95d6fb (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
# encoding: utf-8
import os
import elementary
import edje
import ecore
import evas


#----- Index -{{{-
def gl_text_get(gl, part, data):
    return str(data)

def cb_idx_item(idx, item, gl_item):
    print(("Current Index: %s" % (item.letter)))
    gl_item.bring_in()

def cb_idx_changed(idx, item):
    print(("changed event on: %s" % (item.letter)))
    
def cb_idx_delay_changed(idx, item):
    print(("delay_changed event on: %s" % (item.letter)))
    # BROKEN (see below)
    # gl_item = item.data["gl_item"]
    # gl_item.bring_in()
    
def cb_idx_selected(idx, item):
    print(("selected event on: %s" % (item.letter)))
    

def index_clicked(obj):
    win = elementary.Window("index", elementary.ELM_WIN_BASIC)
    win.title_set("Index test")
    win.autodel_set(True)
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    bg = elementary.Background(win)
    win.resize_object_add(bg)
    bg.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
    bg.show()

    vbox = elementary.Box(win)
    vbox.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
    win.resize_object_add(vbox)
    vbox.show()

    # index
    idx = elementary.Index(win)
    idx.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)
    idx.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
    idx.callback_delay_changed_add(cb_idx_delay_changed)
    idx.callback_changed_add(cb_idx_changed)
    idx.callback_selected_add(cb_idx_selected)
    win.resize_object_add(idx)
    idx.show()
    
    # genlist
    itc = elementary.GenlistItemClass(item_style="default",
                                      text_get_func=gl_text_get)
                                      # content_get_func=gl_content_get,
                                      # state_get_func=gl_state_get)
    gl = elementary.Genlist(win)
    gl.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)
    gl.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
    vbox.pack_end(gl)
    gl.show()

    
    for i in 'ABCDEFGHILMNOPQRSTUVZ':
        for j in 'acegikmo':
            gl_item = gl.item_append(itc, i + j)
            if j == 'a':
                idx_item = idx.item_append(i, cb_idx_item, gl_item)

                # TODO This is broken (data assignment to ItemObject)
                # ...for now just bringin on select
                # idx_item.data["gl_item"] = gl_item
        

    idx.level_go(0)

    sep = elementary.Separator(win)
    sep.horizontal = True
    vbox.pack_end(sep)
    sep.show()

    hbox = elementary.Box(win)
    hbox.horizontal = True
    hbox.size_hint_weight_set(evas.EVAS_HINT_EXPAND, 0.0)
    vbox.pack_end(hbox)
    hbox.show()

    ck = elementary.Check(win)
    ck.text = "autohide_disabled"
    ck.callback_changed_add(lambda ck: idx.autohide_disabled_set(ck.state))
    hbox.pack_end(ck)
    ck.show()

    ck = elementary.Check(win)
    ck.text = "indicator_disabled"
    ck.callback_changed_add(lambda ck: idx.indicator_disabled_set(ck.state))
    hbox.pack_end(ck)
    ck.show()

    ck = elementary.Check(win)
    ck.text = "horizontal"
    ck.callback_changed_add(lambda ck: idx.horizontal_set(ck.state))
    hbox.pack_end(ck)
    ck.show()

    win.resize(320, 480)
    win.show()
# }}}

#----- Main -{{{-
if __name__ == "__main__":
    elementary.init()

    index_clicked(None)

    elementary.run()
    elementary.shutdown()
# }}}
# vim:foldmethod=marker