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

from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, EXPAND_BOTH, FILL_BOTH, \
    EVAS_CALLBACK_RENDER_PRE, EVAS_CALLBACK_RENDER_POST, \
    EVAS_CALLBACK_CANVAS_FOCUS_IN, EVAS_CALLBACK_CANVAS_FOCUS_OUT, \
    EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN, \
    EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT, \
    EVAS_CALLBACK_RENDER_FLUSH_PRE, EVAS_CALLBACK_RENDER_FLUSH_POST, \
    EVAS_CALLBACK_CANVAS_VIEWPORT_RESIZE, \
    Text, Rectangle

# edje is imported because the canvas callbacks point to an edje obj,
# an instance cannot be created unless the class is available.
# (it's not mapped in efl.eo object_mapping)
from efl import edje

from efl import elementary
from efl.elementary.window import StandardWindow
from efl.elementary.box import Box
from efl.elementary.button import Button


def btn_del_cbs_cb(button):
    canvas = button.evas_get()
    canvas.event_callback_del(EVAS_CALLBACK_CANVAS_FOCUS_IN, events_cb1)
    canvas.event_callback_del(EVAS_CALLBACK_CANVAS_FOCUS_OUT, events_cb1)
    canvas.event_callback_del(EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN, events_cb2)
    canvas.event_callback_del(EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT, events_cb2)
    canvas.event_callback_del(EVAS_CALLBACK_RENDER_FLUSH_PRE, events_cb1)
    canvas.event_callback_del(EVAS_CALLBACK_RENDER_FLUSH_POST, events_cb1)
    canvas.event_callback_del(EVAS_CALLBACK_RENDER_PRE, events_cb1)
    canvas.event_callback_del(EVAS_CALLBACK_RENDER_POST, events_cb1)
    canvas.event_callback_del(EVAS_CALLBACK_CANVAS_VIEWPORT_RESIZE, events_cb1)


def events_cb1(rect, event_name):
    print(event_name + " No data for event")

def events_cb2(rect, evtinfo, event_name):
    print(event_name + " " + str(evtinfo))


def core_evas_canvas_callbacks_clicked(obj, item=None):
    win = StandardWindow("evascanvascbs", "Evas canvas callbacks", autodel=True,
        size=(320,320))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    text = Text(win.evas, text="Events printed on console", size=(300, 30),
        color=(0,0,0,255))
    text.font_set("Sans", 12)
    text.pos = (10, 10)
    text.show()

    canvas = win.evas_get()
    canvas.event_callback_add(EVAS_CALLBACK_CANVAS_FOCUS_IN,
        events_cb1, "EVAS_CALLBACK_CANVAS_FOCUS_IN")
    canvas.event_callback_add(EVAS_CALLBACK_CANVAS_FOCUS_OUT,
        events_cb1, "EVAS_CALLBACK_CANVAS_FOCUS_OUT")
    canvas.event_callback_add(EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
        events_cb2, "EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN")
    canvas.event_callback_add(EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
        events_cb2, "EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT")

    canvas.event_callback_add(EVAS_CALLBACK_RENDER_FLUSH_PRE,
        events_cb1, "EVAS_CALLBACK_RENDER_FLUSH_PRE")
    canvas.event_callback_add(EVAS_CALLBACK_RENDER_FLUSH_POST,
        events_cb1, "EVAS_CALLBACK_RENDER_FLUSH_POST")
    canvas.event_callback_add(EVAS_CALLBACK_RENDER_PRE,
        events_cb1, "EVAS_CALLBACK_RENDER_PRE")
    canvas.event_callback_add(EVAS_CALLBACK_RENDER_POST,
        events_cb1, "EVAS_CALLBACK_RENDER_POST")

    canvas.event_callback_add(EVAS_CALLBACK_CANVAS_VIEWPORT_RESIZE,
        events_cb1, "EVAS_CALLBACK_CANVAS_VIEWPORT_RESIZE")

    r2 = Rectangle(win.evas, size=(120,70), color=(0,100,0,100), pos=(70,70))
    r2.show()

    hbox = Box(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
        horizontal=True)
    win.resize_object_add(hbox)
    hbox.show()

    b = Button(win, text="del cbs", size_hint_align=(0.5, 1.0))
    hbox.pack_end(b)
    b.callback_clicked_add(btn_del_cbs_cb)
    b.show()

    win.show()


if __name__ == "__main__":

    core_evas_canvas_callbacks_clicked(None)

    elementary.run()