aboutsummaryrefslogtreecommitdiffstats
path: root/examples/elementary/test_genlist_reorder.py
blob: e048a7794142e499744276749f7887d8b8b2955a (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
#!/usr/bin/env python
# encoding: utf-8

import os

from efl.evas import EXPAND_BOTH, FILL_BOTH, EXPAND_HORIZ, FILL_HORIZ

from efl import elementary as elm
from efl.elementary import StandardWindow, Icon, Box, Check, Label, Frame, \
    Genlist, GenlistItemClass


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


class MyItemClass(GenlistItemClass):
    def text_get(self, obj, part, data):
        if part == "elm.text":
            return "Item # %d" % data

    def content_get(self, obj, part, data):
        if part == "elm.swallow.icon":
            return Icon(obj, file=os.path.join(img_path, "logo_small.png"))


def genlist11_focus_highlight_ck_changed_cb(chk, win):
    win.focus_highlight_enabled = chk.state

def genlist11_reorder_tg_changed_cb(chk, gl):
    gl.reorder_mode = chk.state


def test_genlist_reorder(parent):
    win = StandardWindow("genlist-reorder", "Genlist Reorder Mode",
                         size=(350,500), autodel=True)

    gl = Genlist(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)

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

    lb = Label(win)
    lb.text = "<align=left>Enable reorder mode if you want to move items.<br>" \
              "To move longress with mouse.</align>"
    fr = Frame(win, text="Reorder Mode", content=lb,
               size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
    bx.pack_end(fr)
    fr.show()

    hbx = Box(win, horizontal=True, padding=(20,0),
              size_hint_weight=EXPAND_HORIZ)
    bx.pack_end(hbx)
    hbx.show()

    tg = Check(win, style="toggle", text="Reorder Mode:")
    tg.callback_changed_add(genlist11_reorder_tg_changed_cb, gl)
    hbx.pack_end(tg)
    tg.show()

    ck = Check(win, text="Focus Highlight")
    ck.state = win.focus_highlight_enabled
    ck.callback_changed_add(genlist11_focus_highlight_ck_changed_cb, win)
    hbx.pack_end(ck)
    ck.show()

    itc = MyItemClass()
    for i in range(1,50):
        gl.item_append(itc, i)
    bx.pack_end(gl)
    gl.show()

    win.show()
  


if __name__ == "__main__":
    elm.policy_set(elm.ELM_POLICY_QUIT, elm.ELM_POLICY_QUIT_LAST_WINDOW_CLOSED)
    test_genlist_reorder(None)
    elm.run()