aboutsummaryrefslogtreecommitdiffstats
path: root/efl/evas/efl.evas_object_smart.pxi
blob: f29bd9570f9515f5ca4e9e911e9083a6dfe06c8f (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
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
# Copyright (C) 2007-2014 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 3 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/>.

from efl.utils.conversions cimport eina_list_objects_to_python_list

from cpython cimport PyMethod_New
import types

#cdef object _smart_classes
#_smart_classes = list()


include "smart_object_metaclass.pxi"
_install_metaclass(EvasSmartObjectMeta, SmartObject)
_install_metaclass(EvasSmartObjectMeta, ClippedSmartObject)


cdef void _smart_object_delete(Evas_Object *o) with gil:
    cdef SmartObject obj
    obj = <SmartObject>evas_object_data_get(o, "python-eo")

    try:
        obj._m_delete(obj)
    except Exception, e:
        traceback.print_exc()

    if type(obj.delete) is types.MethodType:
        try:
            del obj.delete
        except AttributeError, e:
            pass
    if type(obj.move) is types.MethodType:
        try:
            del obj.move
        except AttributeError, e:
            pass
    if type(obj.resize) is types.MethodType:
        try:
            del obj.resize
        except AttributeError, e:
            pass
    if type(obj.show) is types.MethodType:
        try:
            del obj.show
        except AttributeError, e:
            pass
    if type(obj.hide) is types.MethodType:
        try:
            del obj.hide
        except AttributeError, e:
            pass
    if type(obj.color_set) is types.MethodType:
        try:
            del obj.color_set
        except AttributeError, e:
            pass
    if type(obj.clip_set) is types.MethodType:
        try:
            del obj.clip_set
        except AttributeError, e:
            pass
    if type(obj.clip_unset) is types.MethodType:
        try:
            del obj.clip_unset
        except AttributeError, e:
            pass
    if type(obj.calculate) is types.MethodType:
        try:
            del obj.calculate
        except AttributeError, e:
            pass
    if type(obj.member_add) is types.MethodType:
        try:
            del obj.member_add
        except AttributeError, e:
            pass
    if type(obj.member_del) is types.MethodType:
        try:
            del obj.member_del
        except AttributeError, e:
            pass

    obj._smart_callbacks = None
    obj._m_delete = None
    obj._m_move = None
    obj._m_resize = None
    obj._m_show = None
    obj._m_hide = None
    obj._m_color_set = None
    obj._m_clip_set = None
    obj._m_clip_unset = None
    obj._m_calculate = None
    obj._m_member_add = None
    obj._m_member_del = None


cdef void _smart_object_move(Evas_Object *o,
                             Evas_Coord x, Evas_Coord y) with gil:
    cdef SmartObject obj
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    if obj._m_move is not None:
        try:
            obj._m_move(obj, x, y)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_object_resize(Evas_Object *o,
                               Evas_Coord w, Evas_Coord h) with gil:
    cdef SmartObject obj
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    if obj._m_resize is not None:
        try:
            obj._m_resize(obj, w, h)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_object_show(Evas_Object *o) with gil:
    cdef SmartObject obj
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    if obj._m_show is not None:
        try:
            obj._m_show(obj)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_object_hide(Evas_Object *o) with gil:
    cdef SmartObject obj
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    if obj._m_hide is not None:
        try:
            obj._m_hide(obj)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_object_color_set(Evas_Object *o,
                                  int r, int g, int b, int a) with gil:
    cdef SmartObject obj
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    if obj._m_color_set is not None:
        try:
            obj._m_color_set(obj, r, g, b, a)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_object_clip_set(Evas_Object *o, Evas_Object *clip) with gil:
    cdef SmartObject obj
    cdef Object other
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    other = object_from_instance(clip)
    if obj._m_clip_set is not None:
        try:
            obj._m_clip_set(obj, other)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_object_clip_unset(Evas_Object *o) with gil:
    cdef SmartObject obj
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    if obj._m_clip_unset is not None:
        try:
            obj._m_clip_unset(obj)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_object_calculate(Evas_Object *o) with gil:
    cdef SmartObject obj
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    if obj._m_calculate is not None:
        try:
            obj._m_calculate(obj)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_object_member_add(Evas_Object *o, Evas_Object *clip) with gil:
    cdef SmartObject obj
    cdef Object other
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    other = object_from_instance(clip)
    if obj._m_member_add is not None:
        try:
            obj._m_member_add(obj, other)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_object_member_del(Evas_Object *o, Evas_Object *clip) with gil:
    cdef SmartObject obj
    cdef Object other
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    other = object_from_instance(clip)
    if obj._m_member_del is not None:
        try:
            obj._m_member_del(obj, other)
        except Exception, e:
            traceback.print_exc()


cdef void _smart_callback(void *data,
                          Evas_Object *o, void *event_info) with gil:
    cdef SmartObject obj
    cdef object event, ei
    obj = <SmartObject>evas_object_data_get(o, "python-eo")
    event = <object>data
    ei = <object>event_info
    lst = tuple(obj._smart_callbacks[event])
    for func, args, kargs in lst:
        try:
            func(obj, ei, *args, **kargs)
        except Exception, e:
            traceback.print_exc()


cdef object _smart_class_get_impl_method(object cls, name):
    meth = getattr(cls, name)
    orig = getattr(Object, name)
    if meth is orig:
        return None
    else:
        return meth


cdef object _smart_class_get_impl_method_cls(object cls, object parent_cls,
                                             name):
    meth = getattr(cls, name)
    orig = getattr(parent_cls, name)
    if meth is orig:
        return None
    else:
        return meth


cdef class SmartObject(Object):
    """Smart Evas Objects.

    Smart objects are user-defined Evas components, often used to group
    multiple basic elements, associate an object with a clip and deal with
    them as an unit. See evas documentation for more details.

    Recommended use is to create an **clipper** object and clip every other
    member to it, then you can have all your other members to be always
    visible and implement :py:func:`hide`, :py:func:`show`,
    :py:func:`color_set`, :py:func:`clip_set` and :py:func:`clip_unset` to
    just affect the **clipper**. See :py:class:`ClippedSmartObject`.

    **Pay attention that just creating an object within the SmartObject
    doesn't make it a member!** You must do :py:func:`member_add` or use one of
    the provided factories to ensure that. Failing to do so will leave
    created objects on different layer and no stacking will be done for you.

    Behavior is defined by defining the following methods:

    :py:func:`delete`
        called in order to remove object from canvas and deallocate its
        resources. Usually you delete object's children here. *Default
        implementation deletes all registered children.*

    :py:func:`move`
        called in order to move object to given position. Usually you move
        children here. *Default implementation calculates offset and move
        registered children by it.*

    :py:func:`resize`
        called in order to resize object. *No default implementation.*

    :py:func:`show`
        called in order to show the given element. Usually you call the same
        function on children. *No default implementation.*

    :py:func:`hide`
        called in order to hide the given element. Usually you call the same
        function on children. *No default implementation.*

    :py:func:`color_set`
        called in order to change object color. *No default implementation.*

    :py:func:`clip_set`
        called in order to limit object's visible area. *No default
        implementation.*

    :py:func:`clip_unset`
        called in order to unlimit object's visible area. *No default
        implementation.*

    :py:func:`calculate`
        called before object is used for rendering and it is marked as
        dirty/changed with :py:func:`changed`. *Default implementation does
        nothing.*

    :py:func:`member_add`
        called when children is added to object. *Default implementation
        does nothing.*

    :py:func:`member_del`
        called when children is removed from object. *Default implementation
        does nothing.*

    .. note::
        You should never instantiate the SmartObject base class directly,
        but inherit and implement methods, then instantiate this new subclass.

    .. note::
        If you redefine object's __init__(), you MUST call your parent!
        Failing to do so will result in objects that just work from Python
        and not from C, for instance, adding your object to Edje swallow
        that clips or set color it will not behave as expected.

    .. note::
        Do not call your parent on methods you want to replace the behavior
        instead of extending it. For example, some methods have default
        implementation, you may want to remove and replace it with something
        else.


    :seealso: :py:class:`ClippedSmartObject`

    :param canvas: Evas canvas for this object
    :type canvas: Canvas
    :keyword size: Width and height
    :type size: tuple of ints
    :keyword pos: X and Y
    :type pos: tuple of ints
    :keyword geometry: X, Y, width, height
    :type geometry: tuple of ints
    :keyword color: R, G, B, A
    :type color: tuple of ints
    :keyword name: Object name
    :type name: string

    """
    def __cinit__(self, *a, **ka):
        self._smart_callbacks = dict()
        cls = self.__class__
        self._m_delete = _smart_class_get_impl_method(cls, "delete")
        if self._m_delete is not None:
            self.delete = PyMethod_New(Object.delete, self, cls)
        self._m_move = _smart_class_get_impl_method(cls, "move")
        if self._m_move is not None:
            self.move = PyMethod_New(Object.move, self, cls)
        self._m_resize = _smart_class_get_impl_method(cls, "resize")
        if self._m_resize is not None:
            self.resize = PyMethod_New(Object.resize, self, cls)
        self._m_show = _smart_class_get_impl_method(cls, "show")
        if self._m_show is not None:
            self.show = PyMethod_New(Object.show, self, cls)
        self._m_hide = _smart_class_get_impl_method(cls, "hide")
        if self._m_hide is not None:
            self.hide = PyMethod_New(Object.hide, self, cls)
        self._m_color_set = _smart_class_get_impl_method(cls, "color_set")
        if self._m_color_set is not None:
            self.color_set = PyMethod_New(Object.color_set, self, cls)
        self._m_clip_set = _smart_class_get_impl_method(cls, "clip_set")
        if self._m_clip_set is not None:
            self.clip_set = PyMethod_New(Object.clip_set, self, cls)
        self._m_clip_unset = _smart_class_get_impl_method(cls, "clip_unset")
        if self._m_clip_unset is not None:
            self.clip_unset = PyMethod_New(Object.clip_unset, self, cls)
        self._m_calculate = _smart_class_get_impl_method_cls(
            cls, SmartObject, "calculate")
        if self._m_calculate is not None:
            self.calculate = PyMethod_New(
                SmartObject.calculate, self, cls)
        self._m_member_add = _smart_class_get_impl_method_cls(
            cls, SmartObject, "member_add")
        if self._m_member_add is not None:
            self.member_add = PyMethod_New(
                SmartObject.member_add, self, cls)
        self._m_member_del = _smart_class_get_impl_method_cls(
            cls, SmartObject, "member_del")
        if self._m_member_del is not None:
            self.member_del = PyMethod_New(
                SmartObject.member_del, self, cls)

    def __dealloc__(self):
        self._smart_callbacks = None

    def __init__(self, Canvas canvas not None, **kwargs):
        cdef uintptr_t addr
        if type(self) is SmartObject:
            raise TypeError("Must not instantiate SmartObject, but subclasses")
        if self.obj == NULL:
            addr = self.__evas_smart_class__
            self._set_obj(evas_object_smart_add(canvas.obj, <Evas_Smart*>addr))

        self._set_properties_from_keyword_args(kwargs)

    def member_add(self, Object child):
        """member_add(Object child)

        Set an evas object as a member of this object.

        Members will automatically be stacked and layered with the smart
        object. The various stacking function will operate on members relative
        to the other members instead of the entire canvas.

        Non-member objects can not interleave a smart object's members.

        :note: if **child** is already member of another SmartObject, it
           will be deleted from that membership and added to this object.
        """
        evas_object_smart_member_add(child.obj, self.obj)

    def member_del(self, Object child):
        """member_del(Object child)

        Removes a member object from a smart object.

        .. attention:: this will actually map to C API as
            ``evas_object_smart_member_del(child)``, so the object will loose
            it's parent **event if the object is not part of this object**.
        """
        evas_object_smart_member_del(child.obj)

    def members_get(self):
        """members_get() -> tuple

        :rtype: tuple of :py:class:`Object`

        """
        cdef:
            Eina_List *lst = evas_object_smart_members_get(self.obj)
            list ret = eina_list_objects_to_python_list(lst)
        eina_list_free(lst)
        return tuple(ret)

    property members:
        def __get__(self):
            return self.members_get()

    def callback_add(self, char *event, func, *args, **kargs):
        """callback_add(event, func, *args, **kargs)

        Add a callback for the smart event specified by event.

        :param event: Event name
        :param func:
            What to callback.
            Should have the signature::

                function(object, event_info, *args, **kargs)

        :raise TypeError: if **func** is not callable.

        .. warning::
            **event_info** will always be a python object, if the
            signal is provided by a C-only class, it will crash.

        """
        if not callable(func):
            raise TypeError("func must be callable")

        # FIXME: Why is this interned?
        #        What is the reason to use char * and cast it to void *?
        e = intern(event)
        lst = self._smart_callbacks.setdefault(e, [])
        if not lst:
            evas_object_smart_callback_add(self.obj, event, _smart_callback,
                                           <void *>e)
        lst.append((func, args, kargs))

    def callback_del(self, char *event, func):
        """callback_del(event, func)

        Remove a smart callback.

        Removes a callback that was added by :py:func:`callback_add()`.

        :param event: event name
        :param func: what to callback, should have be previously registered.
        :precond: **event** and **func** must be used as parameter for
           :py:func:`callback_add`.

        :raise ValueError: if there was no **func** connected with this event.
        """
        try:
            lst = self._smart_callbacks[event]
        except KeyError, e:
            raise ValueError("Unknown event %r" % event)

        i = -1
        f = None
        for i, (f, a, k) in enumerate(lst):
            if func == f:
                break

        if f != func:
            raise ValueError("Callback %s was not registered with event %r" %
                             (func, event))
        lst.pop(i)
        if lst:
            return
        self._smart_callbacks.pop(event)
        evas_object_smart_callback_del(self.obj, event, _smart_callback)

    def callback_call(self, char *event, event_info=None):
        """callback_call(event, event_info=None)

        Call any smart callbacks for event.

        :param event: the event name
        :param event_info: an event specific info to pass to the callback.

        This should be called internally in the smart object when some
        specific event has occurred. The documentation for the smart object
        should include a list of possible events and what type of
        **event_info** to expect.

        .. attention::
            **event_info** will always be a python object.
        """
        evas_object_smart_callback_call(self.obj, event, <void*>event_info)

    def delete(self):
        """delete()

        Default implementation to delete all children.

        """
        cdef Eina_List *lst, *itr
        lst = evas_object_smart_members_get(self.obj)
        itr = lst
        while itr:
            evas_object_del(<Evas_Object*>itr.data)
            itr = itr.next
        eina_list_free(lst)

    def move_children_relative(self, int dx, int dy):
        """move_children_relative(int dx, int dy)

        Move all children relatively.

        """
        evas_object_smart_move_children_relative(self.obj, dx, dy)

    def move(self, int x, int y):
        """move(int x, int y)

        Default implementation to move all children.

        """
        cdef int orig_x, orig_y, dx, dy
        evas_object_geometry_get(self.obj, &orig_x, &orig_y, NULL, NULL)
        dx = x - orig_x
        dy = y - orig_y
        self.move_children_relative(dx, dy)

    def resize(self, int w, int h):
        """resize(int w, int h)

        Abstract method.

        """
        raise NotImplementedError
        #print "%s.resize(w, h) not implemented." % self.__class__.__name__

    def show(self):
        """show()

        Abstract method.

        """
        raise NotImplementedError
        #print "%s.show() not implemented." % self.__class__.__name__

    def hide(self):
        """hide()

        Abstract method.

        """
        raise NotImplementedError
        #print "%s.hide() not implemented." % self.__class__.__name__

    def color_set(self, int r, int g, int b, int a):
        """color_set(int r, int g, int b, int a)

        Abstract method.

        """
        raise NotImplementedError
        #print "%s.color_set(r, g, b, a) not implemented." % \
              #self.__class__.__name__

    def clip_set(self, Object clip):
        """clip_set(Object clip)

        Abstract method.

        """
        raise NotImplementedError
        #print "%s.clip_set(object) not implemented." % self.__class__.__name__

    def clip_unset(self):
        """clip_unset()

        Abstract method.

        """
        raise NotImplementedError
        #print "%s.clip_unset() not implemented." % self.__class__.__name__

    def calculate(self):
        """calculate()

        Request object to recalculate it's internal state.

        """
        evas_object_smart_calculate(self.obj)

    def changed(self):
        """changed()

        Mark object as changed, so it's :py:func:`calculate()` will be called.

        If an object is changed and it provides a calculate() method,
        it will be called from :py:func:`Canvas.render()`, what we call pre-render
        calculate.

        This can be used to postpone heavy calculations until you need to
        display the object, example: layout calculations.
        """
        evas_object_smart_changed(self.obj)

    # TODO: Move docstrings to property; What is the actual type of value?
    def need_recalculate_set(self, unsigned int value):
        """Set need_recalculate flag.

        Set the need_recalculate flag of given smart object.

        If this flag is set then calculate() callback (method) of the
        given smart object will be called, if one is provided, during
        render phase usually evas_render(). After this step, this flag
        will be automatically unset.

        If no calculate() is provided, this flag will be left unchanged.

        .. note::
            Just setting this flag will not make scene dirty and
            evas_render() will have no effect. To do that, use
            evas_object_smart_changed(), that will automatically call this
            function with 1 as parameter.

        """
        evas_object_smart_need_recalculate_set(self.obj, value)

    def need_recalculate_get(self):
        """Get the current value of need_recalculate flag.

        .. note::
            This flag will be unset during the render phase, after
            calculate() is called if one is provided.  If no calculate()
            is provided, then the flag will be left unchanged after render
            phase.

        """
        return evas_object_smart_need_recalculate_get(self.obj)

    property need_recalculate:
        def __set__(self, value):
            self.need_recalculate_set(value)

        def __get__(self):
            self.need_recalculate_get()

    # Factory
    def Rectangle(self, **kargs):
        """Factory of children :py:class:`~efl.evas.Rectangle`.

        :rtype: :py:class:`~efl.evas.Rectangle`

        """
        obj = Rectangle(self.evas, **kargs)
        self.member_add(obj)
        return obj

    def Line(self, **kargs):
        """Factory of children :py:class:`~efl.evas.Line`.

        :rtype: :py:class:`~efl.evas.Line`

        """
        obj = Line(self.evas, **kargs)
        self.member_add(obj)
        return obj

    def Image(self, **kargs):
        """Factory of children :py:class:`evas.Image`.

        :rtype: :py:class:`Image<evas.Image>`

        """
        obj = Image(self.evas, **kargs)
        self.member_add(obj)
        return obj

    def FilledImage(self, **kargs):
        """Factory of :py:class:`evas.FilledImage` associated with this canvas.

        :rtype: :py:class:`FilledImage<evas.FilledImage>`

        """
        obj = FilledImage(self.evas, **kargs)
        self.member_add(obj)
        return obj

    def Polygon(self, **kargs):
        """Factory of children :py:class:`evas.Polygon`.

        :rtype: :py:class:`Polygon<evas.Polygon>`

        """
        obj = Polygon(self.evas, **kargs)
        self.member_add(obj)
        return obj

    def Text(self, **kargs):
        """Factory of children :py:class:`evas.Text`.

        :rtype: :py:class:`Text<evas.Text>`

        """
        obj = Text(self.evas, **kargs)
        self.member_add(obj)
        return obj

    def Textblock(self, **kargs):
        """Factory of children :py:class:`evas.Textblock`.

        :rtype: :py:class:`Textblock<evas.Textblock>`

        """
        obj = Textblock(self.evas, **kargs)
        self.member_add(obj)
        return obj

_object_mapping_register("Evas_Smart", SmartObject)



cdef class ClippedSmartObject(SmartObject):
    """SmartObject subclass that automatically handles an internal clipper.

    This class is optimized for the recommended SmartObject usage of
    having an internal clipper, with all member objects clipped to it and
    operations like :py:func:`hide()`, :py:func:`show()`, :py:func:`color_set()`, :py:func:`clip_set()` and
    :py:func:`clip_unset()` operating on it.

    This internal clipper size is huge by default (and not the same as the
    object size), this means that you should clip this object to another
    object clipper to get its contents restricted. This is the default
    because many times what we want are contents that can overflow SmartObject
    boudaries (ie: members with animations coming in from outside).

    :ivar clipper: the internal object used for clipping. You shouldn't
       mess with it.

    :todo: remove current code and wrap C version (now it's in evas).

    :param canvas: Evas canvas for this object
    :type canvas: Canvas
    :keyword size: Width and height
    :type size: tuple of ints
    :keyword pos: X and Y
    :type pos: tuple of ints
    :keyword geometry: X, Y, width, height
    :type geometry: tuple of ints
    :keyword color: R, G, B, A
    :type color: tuple of ints
    :keyword name: Object name
    :type name: string
    :keyword file: File name
    :type file: string

    """
    def __init__(self, Canvas canvas not None, **kargs):
        if type(self) is ClippedSmartObject:
            raise TypeError("Must not instantiate ClippedSmartObject, but "
                            "subclasses")
        SmartObject.__init__(self, canvas, **kargs)
        if self.clipper is None:
            self.clipper = Rectangle(canvas)
            evas_object_move(self.clipper.obj, -100000, -100000);
            evas_object_resize(self.clipper.obj, 200000, 200000);
            evas_object_static_clip_set(self.clipper.obj, 1);
            evas_object_pass_events_set(self.clipper.obj, 1);
            evas_object_smart_member_add(self.clipper.obj, self.obj)

    def member_add(self, Object child):
        """Set an evas object as a member of this object, already clipping."""
        if self.clipper is None or self.clipper is child:
            return
        evas_object_clip_set(child.obj, self.clipper.obj)
        if evas_object_visible_get(self.obj):
            evas_object_show(self.clipper.obj)

    def member_del(self, Object child):
        """Removes a member object from a smart object, already unsets its clip."""
        if self.clipper is child:
            return
        evas_object_clip_unset(child.obj)
        if evas_object_clipees_get(self.clipper.obj) == NULL:
            evas_object_hide(self.clipper.obj)

    def show(self):
        """Default implementation that acts on the the clipper."""
        if evas_object_clipees_get(self.clipper.obj) != NULL:
            evas_object_show(self.clipper.obj)

    def hide(self):
        """Default implementation that acts on the the clipper."""
        evas_object_hide(self.clipper.obj)

    def color_set(self, int r, int g, int b, int a):
        """Default implementation that acts on the the clipper."""
        evas_object_color_set(self.clipper.obj, r, g, b, a)

    def clip_set(self, Object clip):
        """Default implementation that acts on the the clipper."""
        evas_object_clip_set(self.clipper.obj, clip.obj)

    def clip_unset(self):
        """Default implementation that acts on the the clipper."""
        evas_object_clip_unset(self.clipper.obj)

_object_mapping_register("Evas_Smart_Clipped", ClippedSmartObject)