aboutsummaryrefslogtreecommitdiffstats
path: root/examples/elementary/test_segment_control.py
blob: 95b86ea8a46ba89ddb406d0d9acabdadb6f10e10 (plain) (blame)
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
#!/usr/bin/env python
# encoding: utf-8

import os

from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, \
    EXPAND_BOTH, FILL_BOTH, EXPAND_HORIZ, FILL_HORIZ
from efl import elementary
from efl.elementary.window import StandardWindow
from efl.elementary.box import Box
from efl.elementary.icon import Icon
from efl.elementary.segment_control import SegmentControl


script_path = os.path.dirname(os.path.abspath(__file__))
img_path = os.path.join(script_path, "images")

def cb_seg_changed(seg, item):
    print(seg)
    print(item)

def segment_control_clicked(obj):
    win = StandardWindow("segment-control", "Segment Control test",
        autodel=True, size=(320, 280))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    vbox = Box(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    win.resize_object_add(vbox)
    vbox.show()

    # segment 1
    seg = SegmentControl(win, size_hint_weight=EXPAND_BOTH,
        size_hint_align=FILL_HORIZ)
    seg.item_add(None, "Only Text")
    ic = Icon(win, file=os.path.join(img_path, "logo_small.png"))
    it = seg.item_add(ic)
    ic = Icon(win)
    ic = Icon(win, file=os.path.join(img_path, "logo_small.png"))
    seg.item_add(ic, "Text + Icon")
    seg.item_add(None, "Seg4")
    seg.item_add(None, "Seg5")

    seg.callback_changed_add(cb_seg_changed)
    it.selected = True
    vbox.pack_end(seg)
    seg.show()

    # segment 2
    seg = SegmentControl(win, size_hint_weight=EXPAND_BOTH,
        size_hint_align=FILL_HORIZ)
    seg.item_add(None, "SegmentItem")
    it = seg.item_add(None, "SegmentItem")
    seg.item_add(None, "SegmentItem")
    seg.item_add(None, "SegmentItem")

    it.selected = True
    vbox.pack_end(seg)
    seg.show()

    # segment 3
    seg = SegmentControl(win, size_hint_weight=EXPAND_BOTH,
        size_hint_align=(0.5, 0.5))

    for i in range(3):
        ic = Icon(win, file=os.path.join(img_path, "logo_small.png"))
        if i == 1:
            it = seg.item_add(ic)
        else:
            seg.item_add(ic)

    it.selected = True
    vbox.pack_end(seg)
    seg.show()

    # segment 4
    seg = SegmentControl(win, size_hint_weight=EXPAND_BOTH,
        size_hint_align=FILL_HORIZ, disabled=True)

    seg.item_add(None, "Disabled")

    ic = Icon(win, file=os.path.join(img_path, "logo_small.png"))
    it = seg.item_add(ic, "Disabled")

    ic = Icon(win, file=os.path.join(img_path, "logo_small.png"))
    seg.item_add(ic)

    it.selected = True

    vbox.pack_end(seg)
    seg.show()

    win.show()


if __name__ == "__main__":

    segment_control_clicked(None)

    elementary.run()