aboutsummaryrefslogtreecommitdiffstats
path: root/examples/elementary/test_slider.py
blob: c69e44d4fb97964a1a37b9716e95077e48dd80dd (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env python
# encoding: utf-8

import os

from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, \
    EVAS_ASPECT_CONTROL_VERTICAL, EVAS_ASPECT_CONTROL_HORIZONTAL, \
    EXPAND_BOTH, EXPAND_HORIZ, EXPAND_VERT, \
    FILL_BOTH, FILL_HORIZ, FILL_VERT
from efl import elementary
from efl.elementary.window import StandardWindow
from efl.elementary.box import Box
from efl.elementary.button import Button
from efl.elementary.frame import Frame
from efl.elementary.label import Label
from efl.elementary.list import List
from efl.elementary.icon import Icon
from efl.elementary.radio import Radio
from efl.elementary.slider import Slider, \
    ELM_SLIDER_INDICATOR_VISIBLE_MODE_DEFAULT, \
    ELM_SLIDER_INDICATOR_VISIBLE_MODE_ALWAYS, \
    ELM_SLIDER_INDICATOR_VISIBLE_MODE_ON_FOCUS, \
    ELM_SLIDER_INDICATOR_VISIBLE_MODE_NONE


ALIGN_CENTER = 0.5, 0.5
ZERO_WEIGHT = 0.0, 0.0

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


def delay_change_cb(obj, data=None):
    print("delay,changed! slider value : %d" % round(obj.value))

def change_cb(obj, data=None):
    data.value = obj.value

def change_print_cb(obj, data=None):
    print("change to %3.3f" % obj.value)

def bt_0(obj, data=None):
    data.value = 0.0

def bt_1(obj, data=None):
    data.value = 1.0

def bt_p1(obj, data=None):
    data.value += 0.1

def bt_m1(obj, data=None):
    data.value -= 0.1

def step_size_calculate(min_size, max_size):
    steps = max_size - min_size
    if steps:
        step = (1.0 / steps)
    return step

def slider_clicked(obj):
    win = StandardWindow("slider", "Slider", autodel=True)
    if obj is None:
        win.callback_delete_request_add(lambda x: elementary.exit())
    win.show()

    fr = Frame(win, size_hint_weight=EXPAND_BOTH, style="pad_large")
    win.resize_object_add(fr)
    fr.show()

    bx = Box(win)
    fr.content = bx
    bx.show()

    # disabled horizontal slider
    ic = Icon(bx, file=os.path.join(img_path, "logo_small.png"),
        size_hint_aspect=(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1))
    ic.show()

    sl = Slider(bx, text="Disabled", unit_format="%1.1f units", span_size=120,
        min_max=(50, 150), value=80, disabled=True, size_hint_align=FILL_HORIZ,
        size_hint_weight=EXPAND_HORIZ)
    sl.part_content_set("icon", ic)
    bx.pack_end(sl)
    sl.show()

    # manual step
    step = step_size_calculate(0, 9)
    sl = Slider(bx, unit_format="%1.0f units", indicator_format="%1.0f",
        span_size=120, min_max=(0, 9), text="Manual step", step=step,
        size_hint_align=FILL_HORIZ, size_hint_weight=EXPAND_HORIZ)
    bx.pack_end(sl)
    sl.show()

    # normal horizontal slider
    ic = Icon(bx, file=os.path.join(img_path, "logo_small.png"),
        size_hint_aspect=(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1))

    sl1 = sl = Slider(bx, text="Horizontal", unit_format="%1.1f units",
        indicator_format="%1.1f", span_size=120, size_hint_align=FILL_HORIZ,
        size_hint_weight=EXPAND_HORIZ)
    sl.part_content_set("icon", ic)
    bx.pack_end(sl)
    ic.show()
    sl.show()

    # horizontally inverted slider
    ic = Icon(bx, file=os.path.join(img_path, "logo_small.png"),
        size_hint_aspect=(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1))
    ic.show()

    sl = Slider(bx, text="Horizontal inverted", unit_format="%3.0f units",
        span_size=80, indicator_format="%3.0f", min_max=(50, 150), value=80,
        inverted=True, size_hint_align=ALIGN_CENTER,
        size_hint_weight=(0.0, 0.0))
    sl.part_content_set("end", ic)
    sl.callback_delay_changed_add(delay_change_cb)
    bx.pack_end(sl)
    sl.show()

    # disabled horizontally inverted slider
    ic = Icon(bx, file=os.path.join(img_path, "logo_small.png"),
        size_hint_aspect=(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1))
    ic.show()

    sl = Slider(bx, text="Disabled inverted", span_size=80,
        indicator_format="%3.0f", min_max=(50, 150), value=80, inverted=True,
        disabled=True, size_hint_align=ALIGN_CENTER,
        size_hint_weight=(0.0, 0.0))
    sl.part_content_set("end", ic)
    bx.pack_end(sl)
    sl.show()

    # scale doubled slider
    sl = Slider(bx, indicator_show=False, text="Scale doubled",
        unit_format="%3.0f units", span_size=40, size_hint_align=FILL_HORIZ,
        size_hint_weight=EXPAND_HORIZ, indicator_format="%3.0f",
        min_max=(50, 150), value=80, inverted=True, scale=2.0)
    bx.pack_end(sl)
    sl.show()

    # horizontal box
    bx2 = Box(bx, size_hint_weight=EXPAND_BOTH,
        size_hint_align=FILL_VERT, horizontal=True)
    bx.pack_end(bx2)
    bx2.show()

    # vertical inverted slider
    ic = Icon(bx2, file=os.path.join(img_path, "logo_small.png"),
        size_hint_aspect=(EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1))
    ic.show()

    sl = Slider(bx2, text="Vertical inverted", inverted=True,
        unit_format="%1.1f units", span_size=60,
        size_hint_align=FILL_VERT,
        size_hint_weight=EXPAND_VERT,
        indicator_format="%1.1f", value=0.2, scale=1.0, horizontal=False)
    sl.part_content_set("icon", ic)
    bx2.pack_end(sl)
    sl.show()

    sl1.callback_changed_add(change_cb, sl)

    # disabled vertical slider
    ic = Icon(bx2, file=os.path.join(img_path, "logo_small.png"),
        size_hint_aspect=(EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1))

    sl = Slider(bx2, text="Disabled vertical", inverted=True,
        unit_format="%1.1f units", span_size=100,
        size_hint_align=FILL_VERT,
        size_hint_weight=EXPAND_VERT,
        indicator_format="%1.1f", value=0.2, scale=1.0, horizontal=False)
    #
    # XXX:  If vertical mode is set after disabled, it's no longer disabled.
    #       Elm bug?
    #
    sl.disabled = True

    sl.part_content_set("icon", ic)
    bx2.pack_end(sl)
    sl.show()

    # normal vertical slider
    sl = Slider(bx2, text="Vertical", unit_format="%1.1f units", span_size=60,
        size_hint_align=FILL_VERT, size_hint_weight=EXPAND_VERT,
        value=0.2, scale=1.0, horizontal=False, indicator_format="%.1f")
    sl.callback_changed_add(change_print_cb, sl)
    bx2.pack_end(sl)
    sl.show()

    # box for bottom buttons
    bx2 = Box(win,size_hint_weight=EXPAND_HORIZ, horizontal=True)
    bx.pack_end(bx2)
    bx2.show()

    bt = Button(win, text="0")
    bt.callback_clicked_add(bt_0, sl)
    bt.show()
    bx2.pack_end(bt)

    bt = Button(win, text="1")
    bt.callback_clicked_add(bt_1, sl)
    bt.show()
    bx2.pack_end(bt)

    bt = Button(win, text="+0.1")
    bt.callback_clicked_add(bt_p1, sl)
    bt.show()
    bx2.pack_end(bt)

    bt = Button(win, text="-0.1")
    bt.callback_clicked_add(bt_m1, sl)
    bt.show()
    bx2.pack_end(bt)

    # box for indicator visible mode
    bx2 = Box(win,size_hint_weight=EXPAND_HORIZ, horizontal=True)
    bx.pack_end(bx2)
    bx2.show()

    lb = Label(win, text="Indicator mode:")
    bx2.pack_end(lb)
    lb.show()
    
    rd = rdg = Radio(win, text="Default", state_value=ELM_SLIDER_INDICATOR_VISIBLE_MODE_DEFAULT)
    rd.callback_changed_add(lambda r: sl.indicator_visible_mode_set(ELM_SLIDER_INDICATOR_VISIBLE_MODE_DEFAULT))
    bx2.pack_end(rd)
    rd.show()

    rd = Radio(win, text="Always", state_value=ELM_SLIDER_INDICATOR_VISIBLE_MODE_ALWAYS)
    rd.callback_changed_add(lambda r: sl.indicator_visible_mode_set(ELM_SLIDER_INDICATOR_VISIBLE_MODE_ALWAYS))
    rd.group_add(rdg)
    bx2.pack_end(rd)
    rd.show()

    rd = Radio(win, text="On Focus", state_value=ELM_SLIDER_INDICATOR_VISIBLE_MODE_ON_FOCUS)
    rd.callback_changed_add(lambda r: sl.indicator_visible_mode_set(ELM_SLIDER_INDICATOR_VISIBLE_MODE_ON_FOCUS))
    rd.group_add(rdg)
    bx2.pack_end(rd)
    rd.show()

    rd = Radio(win, text="None", state_value=ELM_SLIDER_INDICATOR_VISIBLE_MODE_NONE)
    rd.callback_changed_add(lambda r: sl.indicator_visible_mode_set(ELM_SLIDER_INDICATOR_VISIBLE_MODE_NONE))
    rd.group_add(rdg)
    bx2.pack_end(rd)
    rd.show()

if __name__ == "__main__":
    elementary.init()

    slider_clicked(None)

    elementary.run()
    elementary.shutdown()