summaryrefslogtreecommitdiff
path: root/efl/edje/efl.edje_object.pxi
blob: 1892db06be329a17d2144b8e19227648ff4049a7 (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# Copyright (C) 2007-2013 various contributors (see AUTHORS)
#
# This file is part of Python-EFL.
#
# Python-EFL is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# Python-EFL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this Python-EFL.  If not, see <http://www.gnu.org/licenses/>.


cdef void text_change_cb(void *data,
                         Evas_Object *obj,
                         const_char_ptr part) with gil:
    cdef Edje self
    self = <Edje>data
    if self._text_change_cb is None:
        return
    func, args, kargs = self._text_change_cb
    try:
        func(self, _ctouni(part), *args, **kargs)
    except Exception, e:
        traceback.print_exc()


cdef void message_handler_cb(void *data,
                             Evas_Object *obj,
                             Edje_Message_Type type,
                             int id, void *msg) with gil:
    cdef Edje self
    self = <Edje>data
    if self._message_handler_cb is None:
        return
    func, args, kargs = self._message_handler_cb
    try:
        func(self, Message_from_type(type, id, msg), *args, **kargs)
    except Exception, e:
        traceback.print_exc()


cdef void signal_cb(void *data, Evas_Object *obj,
                    const_char_ptr emission, const_char_ptr source) with gil:
    cdef Edje self
    self = object_from_instance(obj)
    lst = tuple(<object>data)
    for func, args, kargs in lst:
        try:
            func(self, _ctouni(emission), _ctouni(source), *args, **kargs)
        except Exception, e:
            traceback.print_exc()


class EdjeLoadError(Exception):
    def __init__(self, int code, char *file, char *group):
        if code == EDJE_LOAD_ERROR_NONE:
            msg = "No error"
        elif code == EDJE_LOAD_ERROR_GENERIC:
            msg = "Generic error"
        elif code == EDJE_LOAD_ERROR_DOES_NOT_EXIST:
            msg = "Does not exist"
        elif code == EDJE_LOAD_ERROR_PERMISSION_DENIED:
            msg = "Permission denied"
        elif code == EDJE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED:
            msg = "Resource allocation failed"
        elif code == EDJE_LOAD_ERROR_CORRUPT_FILE:
            msg = "Corrupt file"
        elif code == EDJE_LOAD_ERROR_UNKNOWN_FORMAT:
            msg = "Unknown format"
        elif code == EDJE_LOAD_ERROR_INCOMPATIBLE_FILE:
            msg = "Incompatible file"
        elif code == EDJE_LOAD_ERROR_UNKNOWN_COLLECTION:
            msg = "Unknown collection"

        self.code = code
        self.file = file
        self.group = group
        Exception.__init__(self, "%s (file=%r, group=%r)" % (msg, file, group))


cdef class Edje(Object):
    def __cinit__(self, *a, **ka):
        self._signal_callbacks = {}

    def __init__(self, Canvas canvas not None, **kargs):
        self._set_obj(edje_object_add(canvas.obj))
        self._set_common_params(**kargs)

    def __free_wrapper_resources(self, ed):
        self._signal_callbacks.clear()
        self._text_change_cb = None
        self._message_handler_cb = None

    def _set_common_params(self, file=None, group=None, size=None, pos=None,
                           geometry=None, color=None, name=None):
        if file:
            self.file_set(file, group)
        Object._set_common_params(self, size=size, pos=pos, geometry=geometry,
                                  color=color, name=name)
        if not size and not geometry:
            w, h = self.size_min_get()
            self.size_set(w, h)

    def __str__(self):
        x, y, w, h = self.geometry_get()
        r, g, b, a = self.color_get()
        file, group = self.file_get()
        name = self.name_get()
        if name:
            name_str = "name=%r, "
        else:
            name_str = ""
        clip = bool(self.clip_get() is not None)
        return ("%s(%sfile=%r, group=%r, geometry=(%d, %d, %d, %d), "
                "color=(%d, %d, %d, %d), layer=%s, clip=%s, visible=%s)") % \
               (self.__class__.__name__, name_str, file, group, x, y, w, h,
                r, g, b, a, self.layer_get(), clip, self.visible_get())

    def __repr__(self):
        x, y, w, h = self.geometry_get()
        r, g, b, a = self.color_get()
        file, group = self.file_get()
        clip = bool(self.clip_get() is not None)
        return ("%s(name=%r, file=%r, group=%r, geometry=(%d, %d, %d, %d), "
                "color=(%d, %d, %d, %d), layer=%s, clip=%r, visible=%s)") % \
               (self.__class__.__name__, self.name_get(), file, group,
                x, y, w, h, r, g, b, a,
                self.layer_get(), clip, self.visible_get())

    def data_get(self, key):
        return _ctouni(edje_object_data_get(self.obj, _cfruni(key)))

    def file_set(self, file, group):
        if edje_object_file_set(self.obj, _cfruni(file), _cfruni(group)) == 0:
            raise EdjeLoadError(edje_object_load_error_get(self.obj),
                                _cfruni(file), _cfruni(group))

    def file_get(self):
        cdef const_char_ptr file, group
        edje_object_file_get(self.obj, &file, &group)
        return (_ctouni(file), _ctouni(group))

    def load_error_get(self):
        return edje_object_load_error_get(self.obj)

    def play_get(self):
        return bool(edje_object_play_get(self.obj))

    def play_set(self, int value):
        edje_object_play_set(self.obj, value)

    property play:
        def __get__(self):
            return self.play_get()

        def __set__(self, int value):
            self.play_set(value)

    def animation_get(self):
        return bool(edje_object_animation_get(self.obj))

    def animation_set(self, int value):
        edje_object_animation_set(self.obj, value)

    property animation:
        def __get__(self):
            return self.animation_get()

        def __set__(self, int value):
            self.animation_set(value)

    def freeze(self):
        return edje_object_freeze(self.obj)

    def thaw(self):
        return edje_object_thaw(self.obj)

    def color_class_set(self, color_class,
                        int r, int g, int b, int a,
                        int r2, int g2, int b2, int a2,
                        int r3, int g3, int b3, int a3):
        edje_object_color_class_set(self.obj, _cfruni(color_class),
                                    r, g, b, a,
                                    r2, g2, b2, a2,
                                    r3, g3, b3, a3)

    def color_class_get(self, color_class):
        cdef int r, g, b, a
        cdef int r2, g2, b2, a2
        cdef int r3, g3, b3, a3
        edje_object_color_class_get(self.obj, _cfruni(color_class),
                                    &r, &g, &b, &a,
                                    &r2, &g2, &b2, &a2,
                                    &r3, &g3, &b3, &a3)
        return (r, g, b, a, r2, g2, b2, a2, r3, g3, b3, a3)

    def color_class_del(self, color_class):
        edje_object_color_class_del(self.obj, _cfruni(color_class))

    def text_class_set(self, text_class, font, int size):
        edje_object_text_class_set(self.obj, _cfruni(text_class),
                                   _cfruni(font), size)

    def size_min_get(self):
        cdef int w, h
        edje_object_size_min_get(self.obj, &w, &h)
        return (w, h)

    property size_min:
        def __get__(self):
            return self.size_min_get()

    def size_max_get(self):
        cdef int w, h
        edje_object_size_max_get(self.obj, &w, &h)
        return (w, h)

    property size_max:
        def __get__(self):
            return self.size_max_get()

    def calc_force(self):
        edje_object_calc_force(self.obj)

    def size_min_calc(self):
        cdef int w, h
        edje_object_size_min_calc(self.obj, &w, &h)
        return (w, h)

    def parts_extends_calc(self):
        cdef int x, y, w, h
        edje_object_parts_extends_calc(self.obj, &x, &y, &w, &h)
        return (x, y, w, h)

    def part_exists(self, part):
        return bool(edje_object_part_exists(self.obj, _cfruni(part)))

    def part_object_get(self, part):
        return object_from_instance(edje_object_part_object_get(self.obj,
                                                                _cfruni(part)))

    def part_geometry_get(self, part):
        cdef int x, y, w, h
        edje_object_part_geometry_get(self.obj, _cfruni(part), &x, &y, &w, &h)
        return (x, y, w, h)

    def part_size_get(self, part):
        cdef int w, h
        edje_object_part_geometry_get(self.obj, _cfruni(part), NULL, NULL, &w, &h)
        return (w, h)

    def part_pos_get(self, part):
        cdef int x, y
        edje_object_part_geometry_get(self.obj, _cfruni(part), &x, &y, NULL, NULL)
        return (x, y)

    def text_change_cb_set(self, func, *args, **kargs):
        if func is None:
            self._text_change_cb = None
            edje_object_text_change_cb_set(self.obj, NULL, NULL)
        elif callable(func):
            self._text_change_cb = (func, args, kargs)
            edje_object_text_change_cb_set(self.obj, text_change_cb, <void*>self)
        else:
            raise TypeError("func must be callable or None")

    def part_text_set(self, part, text):
        edje_object_part_text_set(self.obj, _cfruni(part), _cfruni(text))

    def part_text_get(self, part):
        cdef const_char_ptr s
        return _ctouni(edje_object_part_text_get(self.obj, _cfruni(part)))
        

    def part_text_select_all(self, part):
        edje_object_part_text_select_all(self.obj, _cfruni(part))

    def part_text_select_none(self, part):
        edje_object_part_text_select_none(self.obj, _cfruni(part))

    def part_text_unescaped_set(self, part, text_to_escape):
        edje_object_part_text_unescaped_set(self.obj, _cfruni(part),
                                            _cfruni(text_to_escape))

    def part_text_unescaped_get(self, part):
        cdef char *s
        s = edje_object_part_text_unescaped_get(self.obj, _cfruni(part))
        if s == NULL:
            return None
        else:
            str = _touni(s)
            libc.stdlib.free(s)
            return str

    def part_swallow(self, part, Object obj):
        edje_object_part_swallow(self.obj, _cfruni(part), obj.obj)

    def part_unswallow(self, Object obj):
        edje_object_part_unswallow(self.obj, obj.obj)

    def part_swallow_get(self, part):
        return object_from_instance(edje_object_part_swallow_get(self.obj,
                                                                 _cfruni(part)))

    def part_external_object_get(self, part):
        return object_from_instance(edje_object_part_external_object_get(self.obj,
                                                                _cfruni(part)))

    def part_external_param_set(self, char *part, char *param, value):
        cdef Edje_External_Param p
        cdef Edje_External_Param_Type t

        p.name = param
        if isinstance(value, bool): # bool is int, so keep it before!
            p.type = EDJE_EXTERNAL_PARAM_TYPE_BOOL
            p.i = value
        elif isinstance(value, int):
            p.type = EDJE_EXTERNAL_PARAM_TYPE_INT
            p.i = value
        elif isinstance(value, float):
            p.type = EDJE_EXTERNAL_PARAM_TYPE_DOUBLE
            p.d = value
        elif isinstance(value, (str, unicode)):
            # may be STRING or CHOICE
            p.type = edje_object_part_external_param_type_get(
                self.obj, part, param)

            if isinstance(value, unicode):
                value = value.encode("utf-8")
            p.s = value
        else:
            raise TypeError("unsupported type %s" % type(value).__name__)
        return bool(edje_object_part_external_param_set(self.obj, part, &p))

    def part_external_param_get(self, char *part, char *param):
        cdef Edje_External_Param p
        cdef Edje_External_Param_Type t

        t = edje_object_part_external_param_type_get(self.obj, part, param)
        if t == EDJE_EXTERNAL_PARAM_TYPE_MAX:
            return None

        p.name = param
        p.type = t
        if not edje_object_part_external_param_get(self.obj, part, &p):
            return None
        if t == EDJE_EXTERNAL_PARAM_TYPE_BOOL:
            return bool(p.i)
        elif t == EDJE_EXTERNAL_PARAM_TYPE_INT:
            return p.i
        elif t == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE:
            return p.d
        elif t == EDJE_EXTERNAL_PARAM_TYPE_STRING:
            if p.s == NULL:
                return ""
            return p.s
        elif t == EDJE_EXTERNAL_PARAM_TYPE_CHOICE:
            if p.s == NULL:
                return ""
            return p.s

    def part_box_append(self, part, Object obj):
        return bool(edje_object_part_box_append(self.obj, _cfruni(part), obj.obj))

    def part_box_prepend(self, part, Object obj):
        return bool(edje_object_part_box_prepend(self.obj, _cfruni(part), obj.obj))

    def part_box_insert_at(self, part, Object obj,
                           unsigned int pos):
        return bool(edje_object_part_box_insert_at(self.obj, _cfruni(part),
                                                   obj.obj, pos))

    def part_box_insert_before(self, part, Object obj, Object reference):
        return bool(edje_object_part_box_insert_before(self.obj, _cfruni(part),
                                                    obj.obj, reference.obj))

    def part_box_remove(self, part, Object obj):
        return object_from_instance(edje_object_part_box_remove(self.obj,
                                                        _cfruni(part), obj.obj))

    def part_box_remove_at(self, part, unsigned int pos):
        return object_from_instance(edje_object_part_box_remove_at(self.obj,
                                                            _cfruni(part), pos))

    def part_box_remove_all(self, part, int clear):
        return bool(edje_object_part_box_remove_all(self.obj,
                                                    _cfruni(part), clear))

    def part_table_pack(self, part, Object child, short col, short row, short colspan, short rowspan):
        return bool(edje_object_part_table_pack(self.obj, _cfruni(part),
                                        child.obj, col, row, colspan, rowspan))

    def part_table_unpack(self, part, Object child):
        return bool(edje_object_part_table_unpack(self.obj, _cfruni(part),
                                                  child.obj))

    def part_table_col_row_size_get(self, part):
        cdef int c, r
        edje_object_part_table_col_row_size_get(self.obj, _cfruni(part), &c, &r)
        return (c, r)

    def part_table_clear(self, part, int clear):
        return bool(edje_object_part_table_clear(self.obj, _cfruni(part), clear))

    def part_table_child_get(self, part, int row, int column):
        return object_from_instance(edje_object_part_table_child_get(self.obj,
                                                    _cfruni(part), row, column))

    def part_state_get(self, part):
        cdef double sv
        cdef const_char_ptr sn
        sn = edje_object_part_state_get(self.obj, _cfruni(part), &sv)
        return (_ctouni(sn), sv)

    def part_drag_dir_get(self, part):
        return edje_object_part_drag_dir_get(self.obj, _cfruni(part))

    def part_drag_value_set(self, part, double dx, double dy):
        edje_object_part_drag_value_set(self.obj, _cfruni(part), dx, dy)

    def part_drag_value_get(self, part):
        cdef double dx, dy
        edje_object_part_drag_value_get(self.obj, _cfruni(part), &dx, &dy)
        return (dx, dy)

    def part_drag_size_set(self, part, double dw, double dh):
        edje_object_part_drag_size_set(self.obj, _cfruni(part), dw, dh)

    def part_drag_size_get(self, part):
        cdef double dw, dh
        edje_object_part_drag_size_get(self.obj, _cfruni(part), &dw, &dh)
        return (dw, dh)

    def part_drag_step_set(self, part, double dx, double dy):
        edje_object_part_drag_step_set(self.obj, _cfruni(part), dx, dy)

    def part_drag_step_get(self, part):
        cdef double dx, dy
        edje_object_part_drag_step_get(self.obj, _cfruni(part), &dx, &dy)
        return (dx, dy)

    def part_drag_step(self, part, double dx, double dy):
        edje_object_part_drag_step(self.obj, _cfruni(part), dx, dy)

    def part_drag_page_set(self, part, double dx, double dy):
        edje_object_part_drag_page_set(self.obj, _cfruni(part), dx, dy)

    def part_drag_page_get(self, part):
        cdef double dx, dy
        edje_object_part_drag_page_get(self.obj, _cfruni(part), &dx, &dy)
        return (dx, dy)

    def part_drag_page(self, part, double dx, double dy):
        edje_object_part_drag_page(self.obj, _cfruni(part), dx, dy)

    cdef void message_send_int(self, int id, int data):
        cdef Edje_Message_Int m
        m.val = data
        edje_object_message_send(self.obj, EDJE_MESSAGE_INT, id, <void*>&m)

    cdef void message_send_float(self, int id, float data):
        cdef Edje_Message_Float m
        m.val = data
        edje_object_message_send(self.obj, EDJE_MESSAGE_FLOAT, id, <void*>&m)

    cdef void message_send_str(self, int id, data):
        cdef Edje_Message_String m
        m.str = _fruni(data)
        edje_object_message_send(self.obj, EDJE_MESSAGE_STRING, id, <void*>&m)

    cdef void message_send_str_set(self, int id, data):
        cdef int count, i
        cdef Edje_Message_String_Set *m

        count = len(data)
        m = <Edje_Message_String_Set*>PyMem_Malloc(
            sizeof(Edje_Message_String_Set) + (count - 1) * sizeof(char *))

        m.count = count
        i = 0
        for s in data:
            m.str[i] = s
            i = i + 1

        edje_object_message_send(self.obj, EDJE_MESSAGE_STRING_SET, id,
                                 <void*>m)
        PyMem_Free(m)

    cdef void message_send_str_int(self, int id, s, int i):
        cdef Edje_Message_String_Int m
        m.str = _fruni(s)
        m.val = i
        edje_object_message_send(self.obj, EDJE_MESSAGE_STRING_INT, id,
                                 <void*>&m)

    cdef void message_send_str_float(self, int id, s, float f):
        cdef Edje_Message_String_Float m
        m.str = _fruni(s)
        m.val = f
        edje_object_message_send(self.obj, EDJE_MESSAGE_STRING_FLOAT, id,
                                 <void*>&m)

    cdef void message_send_str_int_set(self, int id, s, data):
        cdef int count, i
        cdef Edje_Message_String_Int_Set *m

        count = len(data)
        m = <Edje_Message_String_Int_Set*>PyMem_Malloc(
            sizeof(Edje_Message_String_Int_Set) + (count - 1) * sizeof(int))

        m.str = _fruni(s)
        m.count = count
        i = 0
        for f in data:
            m.val[i] = f
            i = i + 1

        edje_object_message_send(self.obj, EDJE_MESSAGE_STRING_INT_SET, id,
                                 <void*>m)
        PyMem_Free(m)

    cdef void message_send_str_float_set(self, int id, s, data):
        cdef int count, i
        cdef Edje_Message_String_Float_Set *m

        count = len(data)
        m = <Edje_Message_String_Float_Set*>PyMem_Malloc(
            sizeof(Edje_Message_String_Float_Set) +
            (count - 1) * sizeof(double))

        m.str = _fruni(s)
        m.count = count
        i = 0
        for f in data:
            m.val[i] = f
            i = i + 1

        edje_object_message_send(self.obj, EDJE_MESSAGE_STRING_FLOAT_SET, id,
                                 <void*>m)
        PyMem_Free(m)

    cdef void message_send_int_set(self, int id, data):
        cdef int count, i
        cdef Edje_Message_Int_Set *m

        count = len(data)
        m = <Edje_Message_Int_Set*>PyMem_Malloc(
            sizeof(Edje_Message_Int_Set) + (count - 1) * sizeof(int))

        m.count = count
        i = 0
        for f in data:
            m.val[i] = f
            i = i + 1

        edje_object_message_send(self.obj, EDJE_MESSAGE_INT_SET, id,
                                 <void*>m)
        PyMem_Free(m)

    cdef void message_send_float_set(self, int id, data):
        cdef int count, i
        cdef Edje_Message_Float_Set *m

        count = len(data)
        m = <Edje_Message_Float_Set*>PyMem_Malloc(
            sizeof(Edje_Message_Float_Set) + (count - 1) * sizeof(double))

        m.count = count
        i = 0
        for f in data:
            m.val[i] = f
            i = i + 1

        edje_object_message_send(self.obj, EDJE_MESSAGE_FLOAT_SET, id,
                                 <void*>m)
        PyMem_Free(m)

    cdef message_send_set(self, int id, data):
        second_item = data[1]
        item_type = type(second_item)
        for e in data[2:]:
            if type(e) != item_type:
                raise TypeError("every element of data should be the "
                                "same type '%s'" % item_type.__name__)
        head = data[0]
        if isinstance(head, (int, long)):
            self.message_send_int_set(id, data)
        elif isinstance(head, float):
            self.message_send_float_set(id, data)
        elif isinstance(head, str):
            if issubclass(item_type, str):
                self.message_send_str_set(id, data)
            elif item_type == int or item_type == long:
                if len(data) == 2:
                    self.message_send_str_int(id, head, second_item)
                else:
                    self.message_send_str_int_set(id, head, data[2:])
            elif item_type == float:
                if len(data) == 2:
                    self.message_send_str_float(id, head, second_item)
                else:
                    self.message_send_str_float_set(id, head, data[2:])

    def message_send(self, int id, data):
        if isinstance(data, (long, int)):
            self.message_send_int(id, data)
        elif isinstance(data, float):
            self.message_send_float(id, data)
        elif isinstance(data, str):
            self.message_send_str(id, data)
        elif isinstance(data, (tuple, list)):
            if len(data) < 1:
                return
            if len(data) < 2:
                self.message_send(id, data[0])
                return

            if not isinstance(data[0], (long, int, float, str)):
                raise TypeError("invalid message list type '%s'" %
                                type(data[0]).__name__)

            self.message_send_set(id, data)
        else:
            raise TypeError("invalid message type '%s'" % type(data).__name__)

    def message_handler_set(self, func, *args, **kargs):
        if func is None:
            self._message_handler_cb = None
            edje_object_message_handler_set(self.obj, NULL, NULL)
        elif callable(func):
            self._message_handler_cb = (func, args, kargs)
            edje_object_message_handler_set(self.obj, message_handler_cb,
                                           <void*>self)
        else:
            raise TypeError("func must be callable or None")

    def message_signal_process(self):
        edje_object_message_signal_process(self.obj)

    def signal_callback_add(self, emission, source, func,
                            *args, **kargs):
        if not callable(func):
            raise TypeError("func must be callable")

        d = self._signal_callbacks.setdefault(emission, {})
        lst = d.setdefault(source, [])
        if not lst:
            edje_object_signal_callback_add(self.obj, _cfruni(emission),
                                         _cfruni(source), signal_cb, <void*>lst)
        lst.append((func, args, kargs))

    def signal_callback_del(self, emission, source, func):
        try:
            d = self._signal_callbacks[emission]
            lst = d[source]
        except KeyError:
            raise ValueError(("function %s not associated with "
                              "emission %r, source %r") %
                             (func, emission, source))

        i = -1
        for i, (f, a, k) in enumerate(lst):
            if func == f:
                break
        else:
            raise ValueError(("function %s not associated with "
                              "emission %r, source %r") %
                             (func, emission, source))

        lst.pop(i)
        if lst:
            return
        d.pop(source)
        if not d:
            self._signal_callbacks.pop(emission)
        edje_object_signal_callback_del(self.obj, _cfruni(emission),
                                        _cfruni(source), signal_cb)

    def signal_emit(self, emission, source):
        edje_object_signal_emit(self.obj, _cfruni(emission), _cfruni(source))


_object_mapping_register("edje", Edje)