summaryrefslogtreecommitdiff
path: root/tests/edje/test_05_decorators.py
blob: b1552c4c15311ace84faa459ef3771773c2ff954 (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
#!/usr/bin/env python

from efl import evas
from efl import ecore
from efl import edje
from efl.edje import Edje

import os, unittest
import logging


theme_path = os.path.dirname(os.path.abspath(__file__))
theme_file = os.path.join(theme_path, "theme.edj")


expected_signals = ["seat,added,seat1,default", "edje,language,none",
                    "edje,state,ltr", "load", "edje,state,ltr", "resize",
                    "emit,message", "emit,message"]
expected_signals2 = ["load", "resize"]
expected_messages = [33, 33]
expected_text_parts = ["label", "label"]


class MyEdje(Edje):
    def __init__(self, canvas):
        Edje.__init__(self, canvas, file=theme_file, group="main")


    @edje.on_signal("*", "*")
    def cb_signal_all(self, emission, source):
        if source == "" or source == "edje":
            expected_signals.remove(emission)

    @edje.on_signal("load", "*")
    @edje.on_signal("resize", "*")
    def cb_signal_load_resize(self, emission, source):
        expected_signals2.remove(emission)

    @edje.message_handler
    def message_handler(self, msg):
        expected_messages.remove(msg.val)

    @edje.on_text_change
    def text_change(self, part):
        expected_text_parts.remove(part)


class TestEdjeDecoratedCallbacks(unittest.TestCase):
    def setUp(self):
        self.canvas = evas.Canvas(method="buffer",
                                  size=(400, 500),
                                  viewport=(0, 0, 400, 500))
        self.canvas.engine_info_set(self.canvas.engine_info_get())
        self.o = MyEdje(self.canvas)
        self.assertIsInstance(self.o, Edje)

    def tearDown(self):
        self.o.delete()
        self.assertTrue(self.o.is_deleted())
        self.canvas.delete()

    def testDecorators(self):
        o = self.o

        # this should trigger text_change, two times
        ecore.Timer(0.1, lambda: o.part_text_set("label", "asd"))
        ecore.Timer(0.1, lambda: o.part_text_set("label", "asd2"))

        # ask the edje obj to send a message, two times
        ecore.Timer(0.1, lambda: o.signal_emit("emit,message", ""))
        ecore.Timer(0.1, lambda: o.signal_emit("emit,message", ""))

        # and then quit the main loop
        ecore.Timer(0.2, lambda: ecore.main_loop_quit())

        ecore.main_loop_begin()

        self.assertEqual(expected_signals, [])
        self.assertEqual(expected_signals2, [])
        self.assertEqual(expected_messages, [])
        self.assertEqual(expected_text_parts, [])


if __name__ == '__main__':
    formatter = logging.Formatter("[%(levelname)s] %(name)s (%(filename)s: %(lineno)d) --- %(message)s")
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    efllog = logging.getLogger("efl")
    efllog.addHandler(handler)
    efllog.setLevel(logging.DEBUG)
    unittest.main(verbosity=2)