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

import os

from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, FilledImage
from efl import elementary
from efl.elementary.window import StandardWindow
from efl.elementary.button import Button
from efl.elementary.list import List, ELM_LIST_LIMIT
from efl.elementary.icon import Icon
from efl.elementary.popup import Popup, ELM_WRAP_CHAR

EXPAND_BOTH = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
FILL_BOTH = EVAS_HINT_FILL, EVAS_HINT_FILL

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

def cb_bnt_close(btn, popup):
    if "im" in popup.data:
        popup.data["im"].delete()
    popup.delete()

def cb_btn_restack(btn, popup):
    im = FilledImage(popup.evas)
    im.file = os.path.join(img_path, "mystrale_2.jpg")
    im.move(40, 40)
    im.resize(500, 320)
    im.show()

    popup.data["im"] = im
    popup.raise_()

def cb_popup_center_text(li, item, win):
    popup = Popup(win, size_hint_weight=EXPAND_BOTH, timeout=3.0)
    popup.text = "This Popup has content area and timeout value is 3 seconds"
    popup.show()

def cb_popup_center_title_text_1button(li, item, win):
    popup = Popup(win, size_hint_weight=EXPAND_BOTH)
    popup.text = "This Popup has content area and " \
                 "action area set, action area has one button Close"
    bt = Button(win, text="Close")
    bt.callback_clicked_add(cb_bnt_close, popup)
    popup.part_content_set("button1", bt)
    popup.show()

def cb_popup_center_title_text_2button(li, item, win):
    popup = Popup(win, size_hint_weight=EXPAND_BOTH)
    popup.text = "This Popup has title area, content area and " \
                 "action area set, action area has one button Close"
    popup.part_text_set("title,text", "Title")
    bt = Button(win, text="Close")
    bt.callback_clicked_add(cb_bnt_close, popup)
    popup.part_content_set("button1", bt)
    popup.show()

def cb_popup_center_title_text_block_clicked_event(li, item, win):
    popup = Popup(win, size_hint_weight=EXPAND_BOTH)
    popup.text = "This Popup has title area and content area. " \
                 "When clicked on blocked event region, popup gets deleted"
    popup.part_text_set("title,text", "Title")
    popup.callback_block_clicked_add(cb_bnt_close, popup)
    popup.show()

def cb_popup_bottom_title_text_3button(li, item, win):
    popup = Popup(win, size_hint_weight=EXPAND_BOTH,
        content_text_wrap_type=ELM_WRAP_CHAR)
    popup.text = "This Popup has title area, content area and " \
                 "action area set with content being character wrapped. " \
                 "action area has three buttons OK, Cancel and Close"
    popup.part_text_set("title,text", "Title")

    ic = Icon(win, file=os.path.join(img_path, "logo_small.png"))
    popup.part_content_set("title,icon", ic)

    bt = Button(win, text="OK")
    popup.part_content_set("button1", bt)

    bt = Button(win, text="Cancel")
    popup.part_content_set("button2", bt)

    bt = Button(win, text="Close")
    bt.callback_clicked_add(cb_bnt_close, popup)
    popup.part_content_set("button3", bt)

    popup.show()

def cb_popup_center_title_content_3button(li, item, win):
    ic = Icon(win, file=os.path.join(img_path, "logo_small.png"))
    bt = Button(win, text="Content", content=ic)

    popup = Popup(win, size_hint_weight=EXPAND_BOTH, content=bt)
    popup.part_text_set("title,text", "Title")

    bt = Button(win, text="OK")
    popup.part_content_set("button1", bt)

    bt = Button(win, text="Cancel")
    popup.part_content_set("button2", bt)

    bt = Button(win, text="Close")
    bt.callback_clicked_add(cb_bnt_close, popup)
    popup.part_content_set("button3", bt)

    popup.show()

def cb_popup_center_title_item_3button(li, item, win):
    popup = Popup(win, size_hint_weight=EXPAND_BOTH)
    popup.part_text_set("title,text", "Title")

    for i in range(1, 11):
        if i in [3, 5, 6]:
            ic = Icon(win, file=os.path.join(img_path, "logo_small.png"))
            popup.item_append("item"+str(i), ic)
        else:
            popup.item_append("item"+str(i), None)

    bt = Button(win, text="OK")
    popup.part_content_set("button1", bt)

    bt = Button(win, text="Cancel")
    popup.part_content_set("button2", bt)

    bt = Button(win, text="Close")
    bt.callback_clicked_add(cb_bnt_close, popup)
    popup.part_content_set("button3", bt)

    popup.show()

def cb_popup_center_title_text_2button_restack(li, item, win):
    popup = Popup(win, size_hint_weight=EXPAND_BOTH)
    popup.text = "When you click the 'Restack' button, " \
                 "an image will be located under this popup"
    popup.part_text_set("title,text", "Title")

    bt = Button(win, text="Restack")
    bt.callback_clicked_add(cb_btn_restack, popup)
    popup.part_content_set("button1", bt)

    bt = Button(win, text="Close")
    bt.callback_clicked_add(cb_bnt_close, popup)
    popup.part_content_set("button3", bt)

    popup.show()

times = 0
g_popup = None
def cb_popup_center_text_1button_hide_show(li, item, win):
    global times
    global g_popup

    times += 1

    if g_popup is not None:
        g_popup.text = "You have checked this popup %d times." % times
        g_popup.show()
        return

    g_popup = Popup(win, size_hint_weight=EXPAND_BOTH)
    g_popup.text = "Hide this popup by using the button." \
                   "When you click list item again, you will see this popup again."

    bt = Button(win, text="Hide")
    bt.callback_clicked_add(lambda b: g_popup.hide())
    g_popup.part_content_set("button1", bt)

    g_popup.show()


def popup_clicked(obj):
    win = StandardWindow("popup", "Popup test", autodel=True, size=(480, 800))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    li = List(win, mode=ELM_LIST_LIMIT, size_hint_weight=EXPAND_BOTH)
    li.callback_selected_add(lambda li, it: it.selected_set(False))
    win.resize_object_add(li)
    li.show()

    li.item_append("popup-center-text", None, None,
                   cb_popup_center_text, win)
    li.item_append("popup-center-text + 1 button", None, None,
                   cb_popup_center_title_text_1button, win)
    li.item_append("popup-center-title + text + 1 button", None, None,
                   cb_popup_center_title_text_2button, win)
    li.item_append("popup-center-title + text (block,clicked handling)", None, None,
                   cb_popup_center_title_text_block_clicked_event, win)
    li.item_append("popup-bottom-title + text + 3 buttons", None, None,
                   cb_popup_bottom_title_text_3button, win)
    li.item_append("popup-center-title + content + 3 buttons", None, None,
                   cb_popup_center_title_content_3button, win)
    li.item_append("popup-center-title + items + 3 buttons", None, None,
                   cb_popup_center_title_item_3button, win)
    li.item_append("popup-center-title + text + 2 buttons (check restacking)", None, None,
                   cb_popup_center_title_text_2button_restack, win)
    li.item_append("popup-center-text + 1 button (check hide, show)", None, None,
                   cb_popup_center_text_1button_hide_show, win)

    li.go()

    win.show()


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

    popup_clicked(None)

    elementary.run()
    elementary.shutdown()