aboutsummaryrefslogtreecommitdiffstats
path: root/examples/elementary/test_actionslider.py
blob: e43fb69ff7957ca82b73bdd40f0776e78bbb000c (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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
# encoding: utf-8

from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, \
    EXPAND_BOTH, EXPAND_HORIZ, FILL_BOTH
from efl import elementary
from efl.elementary.actionslider import Actionslider, ELM_ACTIONSLIDER_NONE, \
    ELM_ACTIONSLIDER_ALL, ELM_ACTIONSLIDER_LEFT, ELM_ACTIONSLIDER_CENTER, \
    ELM_ACTIONSLIDER_RIGHT
from efl.elementary.box import Box
from efl.elementary.window import StandardWindow


positions = {
    ELM_ACTIONSLIDER_NONE: "none",
    ELM_ACTIONSLIDER_ALL: "all",
    ELM_ACTIONSLIDER_LEFT: "left",
    ELM_ACTIONSLIDER_CENTER: "center",
    ELM_ACTIONSLIDER_RIGHT: "right"
}

def _pos_selected_cb(obj, event_info):
    print("Selection: {0}".format(event_info))
    print("Label selected: {0}".format(obj.selected_label))
    ipos = obj.indicator_pos
    mpos = obj.magnet_pos
    epos = obj.enabled_pos
    iposs = []
    mposs = []
    eposs = []
    for k, v in positions.items():
        if k == ELM_ACTIONSLIDER_NONE or k == ELM_ACTIONSLIDER_ALL:
            if k == ipos:
                iposs = [v,]
            if k == mpos:
                mposs = [v,]
            if k == epos:
                eposs = [v,]
        else:
            if k & obj.indicator_pos:
                iposs.append(v)
            if k & obj.magnet_pos:
                mposs.append(v)
            if k & obj.enabled_pos:
                eposs.append(v)
    print("actionslider indicator pos: {0}".format(", ".join(iposs)))
    print("actionslider magnet pos: {0}".format(", ".join(mposs)))
    print("actionslider enabled pos: {0}".format(", ".join(eposs)))

def _position_change_magnetic_cb(obj, event_info):
    if event_info == "left":
        obj.magnet_pos = ELM_ACTIONSLIDER_LEFT
    elif event_info == "right":
        obj.magnet_pos = ELM_ACTIONSLIDER_RIGHT

def _magnet_enable_disable_cb(obj, event_info):
    if event_info == "left":
        obj.magnet_pos = ELM_ACTIONSLIDER_CENTER
    elif event_info == "right":
        obj.magnet_pos = ELM_ACTIONSLIDER_NONE

def actionslider_clicked(obj):
    win = StandardWindow("actionslider", "Actionslider")
    win.autodel_set(True)
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    bx = Box(win, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(bx)
    bx.show()

    acts = Actionslider(win, size_hint_weight=EXPAND_HORIZ,
        size_hint_align=(EVAS_HINT_FILL, 0.0),
        indicator_pos=ELM_ACTIONSLIDER_RIGHT, magnet_pos=ELM_ACTIONSLIDER_RIGHT,
        enabled_pos=(ELM_ACTIONSLIDER_LEFT | ELM_ACTIONSLIDER_RIGHT))
    acts.part_text_set("left", "Snooze")
    acts.part_text_set("center", "")
    acts.part_text_set("right", "Stop")
    acts.callback_pos_changed_add(_position_change_magnetic_cb)
    acts.callback_selected_add(_pos_selected_cb)
    bx.pack_end(acts)
    acts.show()

    acts = Actionslider(win, size_hint_weight=EXPAND_HORIZ,
        size_hint_align=(EVAS_HINT_FILL, 0.0),
        indicator_pos=ELM_ACTIONSLIDER_CENTER,
        magnet_pos=ELM_ACTIONSLIDER_CENTER,
        enabled_pos=(ELM_ACTIONSLIDER_LEFT | ELM_ACTIONSLIDER_RIGHT))
    acts.part_text_set("left", "Snooze")
    acts.part_text_set("center", "")
    acts.part_text_set("right", "Stop")
    acts.callback_selected_add(_pos_selected_cb)
    bx.pack_end(acts)
    acts.show()

    acts = Actionslider(win, style="bar", size_hint_weight=EXPAND_HORIZ,
        size_hint_align=(EVAS_HINT_FILL, 0.0),
        indicator_pos=ELM_ACTIONSLIDER_LEFT,
        magnet_pos=(ELM_ACTIONSLIDER_CENTER | ELM_ACTIONSLIDER_RIGHT),
        enabled_pos=(ELM_ACTIONSLIDER_CENTER | ELM_ACTIONSLIDER_RIGHT))
    acts.part_text_set("left", "")
    acts.part_text_set("center", "Accept")
    acts.part_text_set("right", "Reject")
    acts.callback_selected_add(_pos_selected_cb)
    bx.pack_end(acts)
    acts.show()

    acts = Actionslider(win, style="bar", text="Go",
        size_hint_weight=EXPAND_HORIZ, size_hint_align=(EVAS_HINT_FILL, 0.0),
        indicator_pos=ELM_ACTIONSLIDER_LEFT, magnet_pos=ELM_ACTIONSLIDER_LEFT)
    acts.part_text_set("left", "")
    acts.part_text_set("center", "Accept")
    acts.part_text_set("right", "Reject")
    acts.callback_pos_changed_add(_position_change_magnetic_cb)
    acts.callback_selected_add(_pos_selected_cb)
    bx.pack_end(acts)
    acts.show()

    acts = Actionslider(win, size_hint_weight=EXPAND_HORIZ,
        size_hint_align=(EVAS_HINT_FILL, 0.0),
        indicator_pos=ELM_ACTIONSLIDER_LEFT, magnet_pos=ELM_ACTIONSLIDER_ALL)
    acts.part_text_set("left", "Left")
    acts.part_text_set("center", "Center")
    acts.part_text_set("right", "Right")
    acts.text_set("Go")
    acts.callback_selected_add(_pos_selected_cb)
    bx.pack_end(acts)
    acts.show()

    acts = Actionslider(win, size_hint_weight=EXPAND_HORIZ,
        size_hint_align=(EVAS_HINT_FILL, 0.0),
        indicator_pos=ELM_ACTIONSLIDER_CENTER,
        magnet_pos=ELM_ACTIONSLIDER_CENTER)
    acts.part_text_set("left", "Enable")
    acts.part_text_set("center", "Magnet")
    acts.part_text_set("right", "Disable")
    acts.callback_pos_changed_add(_magnet_enable_disable_cb)
    acts.callback_selected_add(_pos_selected_cb)
    bx.pack_end(acts)
    acts.show()

    win.resize(320, 400)
    win.show()

if __name__ == "__main__":

    actionslider_clicked(None)

    elementary.run()