Enlightenment CVS committal

Author  : ulisses
Project : e17
Module  : proto/python-efl

Dir     : e17/proto/python-efl/python-evas/evas


Modified Files:
        evas.c_evas.pyx evas.c_evas_object.pxi 
        evas.c_evas_object_gradient.pxi evas.c_evas_object_image.pxi 
        evas.c_evas_object_line.pxi evas.c_evas_object_polygon.pxi 
        evas.c_evas_object_rectangle.pxi evas.c_evas_object_smart.pxi 
        evas.c_evas_object_text.pxi 


Log Message:
Adding metaclass to extension types to optimize register of decorated methods.

===================================================================
RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas.pyx,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- evas.c_evas.pyx     28 Sep 2007 18:06:26 -0000      1.11
+++ evas.c_evas.pyx     8 Oct 2007 00:02:18 -0000       1.12
@@ -281,6 +281,11 @@
         Exception.__init__(self, "%s (file=%s, key=%s)" % (msg, filename, key))
 
 
+cdef void _install_metaclass(python.PyTypeObject *ctype, object metaclass):
+    python.Py_INCREF(metaclass)
+    ctype.ob_type = <python.PyTypeObject*>metaclass
+
+
 include "evas.c_evas_rect.pxi"
 include "evas.c_evas_canvas.pxi"
 include "evas.c_evas_object_events.pxi"
@@ -293,3 +298,36 @@
 include "evas.c_evas_object_gradient.pxi"
 include "evas.c_evas_object_polygon.pxi"
 include "evas.c_evas_object_text.pxi"
+
+
+class EvasMeta(type):
+    def __init__(cls, name, bases, dict_):
+        type.__init__(cls, name, bases, dict_)
+        cls._fetch_evt_callbacks()
+
+    def _fetch_evt_callbacks(cls):
+        if "__evas_event_callbacks__" in cls.__dict__:
+            return
+
+        cls.__evas_event_callbacks__ = []
+        append = cls.__evas_event_callbacks__.append
+
+        for name in dir(cls):
+            val = getattr(cls, name)
+            if not callable(val) or not hasattr(val, "evas_event_callback"):
+                continue
+            evt = getattr(val, "evas_event_callback")
+            append((name, evt))
+
+
+# installing metaclass for all extension types
+_object_install_metaclass(EvasMeta)
+_smartobj_install_metaclass(EvasMeta)
+_clippedsmartobj_install_metaclass(EvasMeta)
+_rectangle_install_metaclass(EvasMeta)
+_line_install_metaclass(EvasMeta)
+_image_install_metaclass(EvasMeta)
+_filledimage_install_metaclass(EvasMeta)
+_gradient_install_metaclass(EvasMeta)
+_polygon_install_metaclass(EvasMeta)
+_text_install_metaclass(EvasMeta)
===================================================================
RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object.pxi,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- evas.c_evas_object.pxi      3 Oct 2007 04:44:24 -0000       1.18
+++ evas.c_evas_object.pxi      8 Oct 2007 00:02:18 -0000       1.19
@@ -41,11 +41,12 @@
 
 
 cdef _register_decorated_callbacks(obj):
-    for attr_name in dir(obj):
+    if not hasattr(obj, "__evas_event_callbacks__"):
+        return
+
+    for attr_name, evt in obj.__evas_event_callbacks__:
         attr_value = getattr(obj, attr_name)
-        if callable(attr_value) and hasattr(attr_value, "evas_event_callback"):
-            t = getattr(attr_value, "evas_event_callback")
-            obj.event_callback_add(t, attr_value)
+        obj.event_callback_add(evt, attr_value)
 
 
 cdef _add_callback_to_list(Object obj, int type, func, args, kargs):
@@ -1195,3 +1196,10 @@
     property parent:
         def __get__(self):
             return self.parent_get()
+
+
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasObject_Type # hack to install metaclass
+
+cdef void _object_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasObject_Type, metaclass)
===================================================================
RCS file: 
/cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_gradient.pxi,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- evas.c_evas_object_gradient.pxi     5 Oct 2007 18:37:52 -0000       1.4
+++ evas.c_evas_object_gradient.pxi     8 Oct 2007 00:02:18 -0000       1.5
@@ -1,6 +1,7 @@
 # This file is included verbatim by c_evas.pyx
 
-cdef class Gradient(Object):
+cdef public class Gradient(Object) [object PyEvasGradient,
+                                    type PyEvasGradient_Type]:
     "Rectangular area with gradient filling"
     def __init__(self, Canvas canvas not None, **kargs):
         Object.__init__(self, canvas)
@@ -220,3 +221,10 @@
 
         def __set__(self, float value):
             self.offset_set(value)
+
+
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasGradient_Type # hack to install metaclass
+
+cdef void _gradient_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasGradient_Type, metaclass)
===================================================================
RCS file: 
/cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_image.pxi,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- evas.c_evas_object_image.pxi        5 Oct 2007 18:37:52 -0000       1.8
+++ evas.c_evas_object_image.pxi        8 Oct 2007 00:02:18 -0000       1.9
@@ -1,6 +1,6 @@
 # This file is included verbatim by c_evas.pyx
 
-cdef class Image(Object):
+cdef public class Image(Object) [object PyEvasImage, type PyEvasImage_Type]:
     """Image from file or buffer.
 
     @note: if an image is resized it will B{tile} it's contents respecting
@@ -344,6 +344,12 @@
         evas_object_image_save(self.obj, filename, key, flags)
 
 
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasImage_Type # hack to install metaclass
+
+cdef void _image_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasImage_Type, metaclass)
+
 
 cdef void _cb_on_filled_image_resize(void *data, Evas *e,
                                      Evas_Object *obj,
@@ -352,7 +358,8 @@
     evas_object_geometry_get(obj, NULL, NULL, &w, &h)
     evas_object_image_fill_set(obj, 0, 0, w, h)
 
-cdef class FilledImage(Image):
+cdef public class FilledImage(Image) [object PyEvasFilledImage,
+                                      type PyEvasFilledImage_Type]:
     """Image that automatically resize it's contents to fit object size.
 
     This L{Image} subclass already calls L{Image.fill_set()} on resize so
@@ -367,3 +374,9 @@
         "Not available for this class."
         raise NotImplementedError("FilledImage doesn't support fill_set()")
 
+
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasFilledImage_Type # hack to install metaclass
+
+cdef void _filledimage_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasFilledImage_Type, metaclass)
===================================================================
RCS file: 
/cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_line.pxi,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- evas.c_evas_object_line.pxi 28 Sep 2007 18:06:26 -0000      1.4
+++ evas.c_evas_object_line.pxi 8 Oct 2007 00:02:18 -0000       1.5
@@ -1,6 +1,6 @@
 # This file is included verbatim by c_evas.pyx
 
-cdef class Line(Object):
+cdef public class Line(Object) [object PyEvasLine, type PyEvasLine_Type]:
     "Straight line."
     def __init__(self, Canvas canvas not None, **kargs):
         Object.__init__(self, canvas)
@@ -117,3 +117,9 @@
             evas_object_line_xy_get(self.obj, NULL, NULL, &x2, &y2)
             return (x2, y2)
 
+
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasLine_Type # hack to install metaclass
+
+cdef void _line_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasLine_Type, metaclass)
===================================================================
RCS file: 
/cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_polygon.pxi,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- evas.c_evas_object_polygon.pxi      28 Sep 2007 18:06:26 -0000      1.3
+++ evas.c_evas_object_polygon.pxi      8 Oct 2007 00:02:18 -0000       1.4
@@ -1,6 +1,7 @@
 # This file is included verbatim by c_evas.pyx
 
-cdef class Polygon(Object):
+cdef public class Polygon(Object) [object PyEvasPolygon,
+                                   type PyEvasPolygon_Type]:
     def __init__(self, Canvas canvas not None, **kargs):
         Object.__init__(self, canvas)
         if self.obj == NULL:
@@ -22,3 +23,10 @@
 
     def points_clear(self):
         evas_object_polygon_points_clear(self.obj)
+
+
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasPolygon_Type # hack to install metaclass
+
+cdef void _polygon_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasPolygon_Type, metaclass)
===================================================================
RCS file: 
/cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_rectangle.pxi,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- evas.c_evas_object_rectangle.pxi    28 Sep 2007 18:06:26 -0000      1.3
+++ evas.c_evas_object_rectangle.pxi    8 Oct 2007 00:02:18 -0000       1.4
@@ -1,8 +1,16 @@
 # This file is included verbatim by c_evas.pyx
 
-cdef class Rectangle(Object):
+cdef public class Rectangle(Object) [object PyEvasRectangle,
+                                     type PyEvasRectangle_Type]:
     def __init__(self, Canvas canvas not None, **kargs):
         Object.__init__(self, canvas)
         if self.obj == NULL:
             self._set_obj(evas_object_rectangle_add(self.evas.obj))
         self._set_common_params(**kargs)
+
+
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasRectangle_Type # hack to install metaclass
+
+cdef void _rectangle_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasRectangle_Type, metaclass)
===================================================================
RCS file: 
/cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_smart.pxi,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -3 -r1.19 -r1.20
--- evas.c_evas_object_smart.pxi        2 Oct 2007 19:44:16 -0000       1.19
+++ evas.c_evas_object_smart.pxi        8 Oct 2007 00:02:18 -0000       1.20
@@ -203,7 +203,8 @@
         return meth
 
 
-cdef class SmartObject(Object):
+cdef public class SmartObject(Object) [object PyEvasSmartObject,
+                                       type PyEvasSmartObject_Type]:
     """Smart Evas Objects.
 
     Smart objects are user-defined Evas components, often used to group
@@ -522,8 +523,15 @@
         return obj
 
 
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasSmartObject_Type # hack to install metaclass
 
-cdef class ClippedSmartObject(SmartObject):
+cdef void _smartobj_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasSmartObject_Type, metaclass)
+
+
+cdef public class ClippedSmartObject(SmartObject) \
+         [object PyEvasClippedSmartObject, type PyEvasClippedSmartObject_Type]:
     """SmartObject subclass that automatically handles an internal clipper.
 
     This class is optimized for the recommended SmartObject usage of
@@ -589,3 +597,10 @@
     def clip_unset(self):
         "Default implementation that acts on the the clipper."
         evas_object_clip_unset(self.clipper.obj)
+
+
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasClippedSmartObject_Type # hack to install 
metaclass
+
+cdef void _clippedsmartobj_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasClippedSmartObject_Type, metaclass)
===================================================================
RCS file: 
/cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_text.pxi,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- evas.c_evas_object_text.pxi 28 Sep 2007 18:06:26 -0000      1.4
+++ evas.c_evas_object_text.pxi 8 Oct 2007 00:02:18 -0000       1.5
@@ -1,6 +1,6 @@
 # This file is included verbatim by c_evas.pyx
 
-cdef class Text(Object):
+cdef public class Text(Object) [object PyEvasText, type PyEvasText_Type]:
     """Text object.
 
     @group Font settings: font_source_set, font_source_get, font_source,
@@ -331,3 +331,9 @@
         def __get__(self):
             return self.style_pad_get()
 
+
+cdef extern from "Python.h":
+    cdef python.PyTypeObject PyEvasText_Type # hack to install metaclass
+
+cdef void _text_install_metaclass(object metaclass):
+    _install_metaclass(&PyEvasText_Type, metaclass)



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to