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

import os

from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, FilledImage, \
    EXPAND_BOTH, FILL_BOTH
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.button import Button
from efl.elementary.list import List, ELM_LIST_COMPRESS
from efl.elementary.ctxpopup import Ctxpopup
from efl.elementary.scroller import Scroller


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

def cb_items(li, item):
    print(("ctxpopup item selected: %s" % (item.text)))

def item_new(cp, label, icon = None):
    if icon:
        ic = Icon(cp, standard=icon, resizable=(False,False))
        return cp.item_append(label, ic, cb_items)
    else:
        return cp.item_append(label, None, cb_items)

def cb_btn(btn):
    cp = btn.data["ctxpopup"]
    if "img" in cp.data:
        return
    img = FilledImage(btn.evas)
    img.file_set(os.path.join(img_path, "sky_04.jpg"))
    img.move(40, 40)
    img.resize(320, 320)
    img.show()

    cp = btn.data["ctxpopup"]
    cp.data["img"] = img
    cp.raise_()
    # NOTE: the '_' is wanted as 'raise' is a reserved word in py

def cb_dismissed(cp):
    if "img" in cp.data:
        cp.data["img"].delete()

def cb_geometry_update(cp, geom):
    print("geometry,update", geom)

def cb_item1(li, item):
    cp = Ctxpopup(li)
    cp.callback_geometry_update_add(cb_geometry_update)
    it = item_new(cp, "Go to home folder", "user-home")
    it = item_new(cp, "Save file", "document-save")
    it = item_new(cp, "Delete file", "user-trash")
    it = item_new(cp, "Navigate to folder", "folder")
    it.disabled = True
    it = item_new(cp, "Edit entry", "document-edit")
    it = item_new(cp, "Sate date and time", "list-remove")
    it.disabled = True

    ic = Icon(cp, standard="list-add", resizable=(False,False))
    it2 = cp.item_prepend("Prepended item", ic, cb_items)

    ic = Icon(cp, standard="list-add", resizable=(False,False))
    cp.item_insert_before(it2, "Before the Prepended", ic)

    ic = Icon(cp, standard="list-add", resizable=(False,False))
    cp.item_insert_after(it2, "After the Prepended", ic)

    (x, y) = li.evas.pointer_canvas_xy_get()
    cp.move(x, y)
    cp.show()

    print("\n### Testing items getters 1")
    for it in cp.items:
        print("ITEM: " + it.text)

    print("\n### Testing items getters 2")
    print("FIRST ITEM: " + cp.first_item.text)
    print("LAST ITEM: " + cp.last_item.text)

    print("\n### Testing items getters 3")
    it = cp.first_item
    while it:
        print("ITEM: " + it.text)
        it = it.next

    print("\n### Testing items getters 4")
    it = cp.last_item
    while it:
        print("ITEM: " + it.text)
        it = it.prev

def cb_item2(li, item):
    cp = Ctxpopup(li)
    it = item_new(cp, "", "user-home")
    it = item_new(cp, "", "user-trash")
    it = item_new(cp, "", "user-bookmarks")
    it = item_new(cp, "", "folder")
    it = item_new(cp, "", "document-save")
    it.disabled = True
    it = item_new(cp, "", "document-send")

    (x, y) = li.evas.pointer_canvas_xy_get()
    cp.move(x, y)
    cp.show()

def cb_item3(li, item):
    cp = Ctxpopup(li)
    it = item_new(cp, "Eina")
    it = item_new(cp, "Eet")
    it = item_new(cp, "Evas")
    it = item_new(cp, "Ecore")
    it.disabled = True
    it = item_new(cp, "Embryo")
    it = item_new(cp, "Edje")

    (x, y) = li.evas.pointer_canvas_xy_get()
    cp.move(x, y)
    cp.show()

def cb_item4(li, item):
    cp = Ctxpopup(li)
    cp.horizontal = True
    it = item_new(cp, "", "user-home")
    it = item_new(cp, "", "document-save")
    it = item_new(cp, "", "user-trash")
    it = item_new(cp, "", "folder")
    it = item_new(cp, "", "user-bookmarks")
    it = item_new(cp, "", "document-send")

    (x, y) = li.evas.pointer_canvas_xy_get()
    cp.move(x, y)
    cp.show()

def cb_item5(li, item):
    box = Box(li, size_hint_min=(150, 150))

    sc = Scroller(li, bounce=(False, True), size_hint_align=FILL_BOTH,
        size_hint_weight=EXPAND_BOTH)
    sc.show()

    bt = Button(li, text="Enlightenment", size_hint_min=(140, 140))

    sc.content = bt
    box.pack_end(sc)

    cp = Ctxpopup(li, content = box)
    (x, y) = li.evas.pointer_canvas_xy_get()
    cp.move(x, y)
    cp.show()

def cb_item6(li, item):
    box = Box(li, size_hint_min=(200, 150))

    sc = Scroller(li, bounce=(False, True), size_hint_align=FILL_BOTH,
        size_hint_weight=EXPAND_BOTH)
    sc.show()

    bt = Button(li, text="Ctxpop will be on the top of layer",
        size_hint_min=(190, 140))
    bt.callback_clicked_add(cb_btn)

    sc.content = bt
    box.pack_end(sc)

    cp = Ctxpopup(li, content=box)
    cp.callback_dismissed_add(cb_dismissed)
    (x, y) = li.evas.pointer_canvas_xy_get()
    cp.move(x, y)
    cp.show()
    bt.data["ctxpopup"] = cp

def ctxpopup_clicked(obj):
    win = StandardWindow("ctxpopup", "Context popup test", autodel=True,
        size=(400,400))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    li = List(win, size_hint_weight=EXPAND_BOTH, mode=ELM_LIST_COMPRESS)
    win.resize_object_add(li)
    li.show()

    li.item_append("Ctxpopup with icons and labels", callback=cb_item1)
    li.item_append("Ctxpopup with icons only", callback=cb_item2)
    li.item_append("Ctxpopup with labels only", callback=cb_item3)
    li.item_append("Ctxpopup at horizontal mode", callback=cb_item4)
    li.item_append("Ctxpopup with user content", callback=cb_item5)
    li.item_append("Ctxpopup with restacking", callback=cb_item6)
    li.go()

    win.show()


if __name__ == "__main__":

    ctxpopup_clicked(None)

    elementary.run()