From: Enlightenment C. <no...@cv...> - 2007-09-01 15:59:33
|
Enlightenment CVS committal Author : barbieri Project : e17 Module : proto/python-efl Dir : e17/proto/python-efl/python-evas/evas Modified Files: __init__.py evas.c_evas.pyx evas.c_evas_canvas.pxi 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: Cleanup: simplify construction of wrappers for already existent objects. Before I had one class redefinition in __init__.py for each used class, this was used to have an end-user constructor that would call evas to create new objects, while the base class would start shallow and would accept Evas_Object with _set_obj(). Caio noticed that we should instead have end-user constructor in the base class and use Class.__new__() to avoid calling it when we require, like Object_from_instance(). Patch by Caio Marcelo with minor adjustments. =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/__init__.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -3 -r1.12 -r1.13 --- __init__.py 15 Aug 2007 14:01:54 -0000 1.12 +++ __init__.py 1 Sep 2007 15:59:30 -0000 1.13 @@ -2,13 +2,12 @@ import c_evas -shutdown = c_evas.shutdown -render_method_lookup = c_evas.render_method_lookup -render_method_list = c_evas.render_method_list -color_argb_premul = c_evas.color_argb_premul -color_argb_unpremul = c_evas.color_argb_unpremul -color_rgb_to_hsv = c_evas.color_rgb_to_hsv -color_hsv_to_rgb = c_evas.color_hsv_to_rgb +from c_evas import Canvas, SmartObject, Rectangle, Line, Image, \ + Gradient, Polygon, Text, Rect, EvasLoadError, \ + shutdown, render_method_lookup, render_method_list, \ + color_argb_premul, color_argb_unpremul, \ + color_rgb_to_hsv, color_hsv_to_rgb + EVAS_CALLBACK_MOUSE_IN = 0 EVAS_CALLBACK_MOUSE_OUT = 1 @@ -72,89 +71,5 @@ EVAS_OBJECT_POINTER_MODE_AUTOGRAB = 0 EVAS_OBJECT_POINTER_MODE_NOGRAB = 1 -EvasLoadError = c_evas.EvasLoadError -Rect = c_evas.Rect - -class Canvas(c_evas.Canvas): - def __init__(self, method=None, size=None, viewport=None): - c_evas.Canvas.__init__(self) - self._new_evas() - if method: - self.output_method_set(method) - if size: - self.size_set(*size) - if viewport: - self.viewport_set(*viewport) - - -class SmartObject(c_evas.SmartObject): - def __init__(self, canvas, size=None, pos=None, geometry=None, color=None, - name=None): - if type(self) is SmartObject or type(self) is c_evas.SmartObject: - raise TypeError("Must not instantiate SmartObject, but subclasses") - c_evas.SmartObject.__init__(self, canvas) - self._new_obj() - self._set_common_params(size=size, pos=pos, geometry=geometry, - color=color, name=name) - - -class Rectangle(c_evas.Rectangle): - def __init__(self, canvas, size=None, pos=None, geometry=None, color=None, - name=None): - c_evas.Rectangle.__init__(self, canvas) - self._new_obj() - self._set_common_params(size=size, pos=pos, geometry=geometry, - color=color, name=name) - - -class Line(c_evas.Line): - def __init__(self, canvas, start=None, end=None, size=None, pos=None, - geometry=None, color=None, name=None): - c_evas.Line.__init__(self, canvas) - self._new_obj() - self._set_common_params(start=start, end=end, size=size, pos=pos, - geometry=geometry, color=color, name=name) - - -class Image(c_evas.Image): - def __init__(self, canvas, file=None, size=None, pos=None, geometry=None, - color=None, name=None): - c_evas.Image.__init__(self, canvas) - self._new_obj() - self._set_common_params(file=file, size=size, pos=pos, - geometry=geometry, color=color, name=name) - - -class Gradient(c_evas.Gradient): - def __init__(self, canvas, size=None, pos=None, geometry=None, color=None, - name=None): - c_evas.Gradient.__init__(self, canvas) - self._new_obj() - self._set_common_params(size=size, pos=pos, geometry=geometry, - color=color, name=name) - - -class Polygon(c_evas.Polygon): - def __init__(self, canvas, points=None, size=None, pos=None, geometry=None, - color=None, name=None): - c_evas.Polygon.__init__(self, canvas) - self._new_obj() - self._set_common_params(points=points, size=size, pos=pos, - geometry=geometry, color=color, name=name) - - -class Text(c_evas.Text): - def __init__(self, canvas, text=None, font=None, font_source=None, - style=None, shadow_color=None, glow_color=None, - glow2_color=None, outline_color=None, size=None, pos=None, - geometry=None, color=None, name=None): - c_evas.Text.__init__(self, canvas) - self._new_obj() - self._set_common_params(text=text, font=font, font_source=font_source, - style=style, shadow_color=shadow_color, - glow_color=glow_color, glow2_color=glow2_color, - outline_color=outline_color, size=size, - pos=pos, geometry=geometry, color=color, - name=name) c_evas.init() =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas.pyx,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- evas.c_evas.pyx 12 Jul 2007 19:11:53 -0000 1.8 +++ evas.c_evas.pyx 1 Sep 2007 15:59:30 -0000 1.9 @@ -34,7 +34,7 @@ if evas == NULL: return None - c = Canvas() + c = Canvas.__new__(Canvas) c._set_obj(evas) return c @@ -84,7 +84,8 @@ t = evas_object_type_get(obj) c = Canvas_from_instance(evas_object_evas_get(obj)) cls = object_mapping.get(t, Object) - o = cls(c) + o = cls.__new__(cls) + o._set_evas(c) o._set_obj(obj) return o =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_canvas.pxi,v retrieving revision 1.9 retrieving revision 1.10 diff -u -3 -r1.9 -r1.10 --- evas.c_evas_canvas.pxi 1 Aug 2007 13:19:42 -0000 1.9 +++ evas.c_evas_canvas.pxi 1 Sep 2007 15:59:30 -0000 1.10 @@ -4,6 +4,15 @@ def __new__(self, *a, **ka): self.obj = NULL + def __init__(self, method=None, size=None, viewport=None): + self._new_evas() + if method: + self.output_method_set(method) + if size: + self.size_set(*size) + if viewport: + self.viewport_set(*viewport) + def __dealloc__(self): if self.obj: evas_free(self.obj) @@ -341,56 +350,20 @@ return evas_event_freeze_get(self.obj) # Factory - def Rectangle(self, size=None, pos=None, geometry=None, color=None, - name=None): - obj = Rectangle(self) - obj._new_obj() - obj._set_common_params(size=size, pos=pos, geometry=geometry, - color=color, name=name) - return obj - - def Line(self, start=None, end=None, size=None, pos=None, - geometry=None, color=None, name=None): - obj = Line(self) - obj._new_obj() - obj._set_common_params(start=start, end=end, size=size, pos=pos, - geometry=geometry, color=color, name=name) - return obj - - - def Image(self, file=None, size=None, pos=None, geometry=None, - color=None, name=None): - obj = Image(self) - obj._new_obj() - obj._set_common_params(file=file, size=size, pos=pos, - geometry=geometry, color=color, name=name) - return obj - - def Gradient(self, size=None, pos=None, geometry=None, color=None, - name=None): - obj = Gradient(self) - obj._new_obj() - obj._set_common_params(size=size, pos=pos, geometry=geometry, - color=color, name=name) - return obj - - def Polygon(self, points=None, size=None, pos=None, geometry=None, - color=None, name=None): - obj = Polygon(self) - obj._new_obj() - obj._set_common_params(points=points, size=size, pos=pos, - geometry=geometry, color=color, name=name) - return obj - - def Text(self, text=None, font=None, font_source=None, style=None, - shadow_color=None, glow_color=None, glow2_color=None, - outline_color=None, size=None, pos=None, geometry=None, - color=None, name=None): - obj = Text(self) - obj._new_obj() - obj._set_common_params(text=text, font=font, font_source=font_source, - style=style, shadow_color=shadow_color, - glow_color=glow_color, glow2_color=glow2_color, - outline_color=outline_color, size=size, pos=pos, - geometry=geometry, color=color, name=name) - return obj + def Rectangle(self, **kargs): + return Rectangle(self, **kargs) + + def Line(self, **kargs): + return Line(self, **kargs) + + def Image(self, **kargs): + return Image(self, **kargs) + + def Gradient(self, **kargs): + return Gradient(self, **kargs) + + def Polygon(self, **kargs): + return Polygon(self, **kargs) + + def Text(self, **kargs): + return Text(self, **kargs) =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object.pxi,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- evas.c_evas_object.pxi 22 Aug 2007 15:44:16 -0000 1.10 +++ evas.c_evas_object.pxi 1 Sep 2007 15:59:30 -0000 1.11 @@ -97,6 +97,9 @@ _register_decorated_callbacks(self) return 1 + def _set_evas(self, Canvas evas not None): + self._evas = evas + def __dealloc__(self): cdef void *data cdef Evas_Object *obj =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_gradient.pxi,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- evas.c_evas_object_gradient.pxi 11 May 2007 01:43:32 -0000 1.1 +++ evas.c_evas_object_gradient.pxi 1 Sep 2007 15:59:30 -0000 1.2 @@ -1,9 +1,11 @@ # This file is included verbatim by c_evas.pyx cdef class Gradient(Object): - def _new_obj(self): + def __init__(self, Canvas canvas not None, **kargs): + Object.__init__(self, canvas) if self.obj == NULL: self._set_obj(evas_object_gradient_add(self._evas.obj)) + self._set_common_params(**kargs) def color_stop_add(self, int r, int g, int b, int a, int delta): """Adds a color stop to the given evas gradient object. =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_image.pxi,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- evas.c_evas_object_image.pxi 6 May 2007 17:28:10 -0000 1.4 +++ evas.c_evas_object_image.pxi 1 Sep 2007 15:59:30 -0000 1.5 @@ -1,18 +1,18 @@ # This file is included verbatim by c_evas.pyx cdef class Image(Object): - def _new_obj(self): + def __init__(self, Canvas canvas not None, **kargs): + Object.__init__(self, canvas) if self.obj == NULL: self._set_obj(evas_object_image_add(self._evas.obj)) + self._set_common_params(**kargs) - def _set_common_params(self, file=None, size=None, pos=None, geometry=None, - color=None, name=None): + def _set_common_params(self, file=None, **kargs): if file: if isinstance(file, basestring): file = (file, None) self.file_set(*file) - Object._set_common_params(self, size=size, pos=pos, geometry=geometry, - color=color, name=name) + Object._set_common_params(self, **kargs) def file_set(self, char *filename, key=None): cdef char *k =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_line.pxi,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- evas.c_evas_object_line.pxi 5 May 2007 05:51:47 -0000 1.2 +++ evas.c_evas_object_line.pxi 1 Sep 2007 15:59:30 -0000 1.3 @@ -1,12 +1,13 @@ # This file is included verbatim by c_evas.pyx cdef class Line(Object): - def _new_obj(self): + def __init__(self, Canvas canvas not None, **kargs): + Object.__init__(self, canvas) if self.obj == NULL: self._set_obj(evas_object_line_add(self._evas.obj)) + self._set_common_params(**kargs) - def _set_common_params(self, start=None, end=None, size=None, pos=None, - geometry=None, color=None, name=None): + def _set_common_params(self, start=None, end=None, geometry=None, size=None, pos=None, **kargs): if start and end: x1 = start[0] y1 = start[1] @@ -39,8 +40,7 @@ self.start_set(*start) elif end: self.end_set(*end) - Object._set_common_params(self, size=size, pos=pos, geometry=geometry, - color=color, name=name) + Object._set_common_params(self, geometry=geometry, size=size, pos=pos, **kargs) def xy_set(self, int x1, int y1, int x2, int y2): evas_object_line_xy_set(self.obj, x1, y1, x2, y2) =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_polygon.pxi,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- evas.c_evas_object_polygon.pxi 11 May 2007 01:45:07 -0000 1.1 +++ evas.c_evas_object_polygon.pxi 1 Sep 2007 15:59:30 -0000 1.2 @@ -1,14 +1,14 @@ # This file is included verbatim by c_evas.pyx cdef class Polygon(Object): - def _new_obj(self): + def __init__(self, Canvas canvas not None, **kargs): + Object.__init__(self, canvas) if self.obj == NULL: self._set_obj(evas_object_polygon_add(self._evas.obj)) + self._set_common_params(**kargs) - def _set_common_params(self, points=None, size=None, pos=None, - geometry=None, color=None, name=None): - Object._set_common_params(self, size=size, pos=pos, geometry=geometry, - color=color, name=name) + def _set_common_params(self, points=None, **kargs): + Object._set_common_params(self, **kargs) if points: for x, y in points: self.point_add(x, y) =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_rectangle.pxi,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- evas.c_evas_object_rectangle.pxi 3 May 2007 14:29:22 -0000 1.1 +++ evas.c_evas_object_rectangle.pxi 1 Sep 2007 15:59:30 -0000 1.2 @@ -1,6 +1,8 @@ # This file is included verbatim by c_evas.pyx cdef class Rectangle(Object): - def _new_obj(self): + 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) =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_smart.pxi,v retrieving revision 1.13 retrieving revision 1.14 diff -u -3 -r1.13 -r1.14 --- evas.c_evas_object_smart.pxi 22 Aug 2007 14:54:13 -0000 1.13 +++ evas.c_evas_object_smart.pxi 1 Sep 2007 15:59:30 -0000 1.14 @@ -273,11 +273,15 @@ def __dealloc__(self): self._smart_callbacks = None - def _new_obj(self): + def __init__(self, Canvas canvas not None, **kargs): cdef Evas_Smart *cls + if type(self) is SmartObject: + raise TypeError("Must not instantiate SmartObject, but subclasses") + Object.__init__(self, canvas) if self.obj == NULL: cls = _smart_class_from_name(self.__class__.__name__) self._set_obj(evas_object_smart_add(self._evas.obj, cls)) + self._set_common_params(**kargs) def member_add(self, Object child): evas_object_smart_member_add(child.obj, self.obj) @@ -351,62 +355,32 @@ # Factory - def Rectangle(self, size=None, pos=None, geometry=None, color=None, - name=None): - obj = Rectangle(self.evas) - obj._new_obj() - obj._set_common_params(size=size, pos=pos, geometry=geometry, - color=color, name=name) + def Rectangle(self, **kargs): + obj = Rectangle(self.evas, **kargs) self.member_add(obj) return obj - def Line(self, start=None, end=None, size=None, pos=None, - geometry=None, color=None, name=None): - obj = Line(self.evas) - obj._new_obj() - obj._set_common_params(start=start, end=end, size=size, pos=pos, - geometry=geometry, color=color, name=name) + def Line(self, **kargs): + obj = Line(self.evas, **kargs) self.member_add(obj) return obj - - def Image(self, file=None, size=None, pos=None, geometry=None, - color=None, name=None): - obj = Image(self.evas) - obj._new_obj() - obj._set_common_params(file=file, size=size, pos=pos, - geometry=geometry, color=color, name=name) + def Image(self, **kargs): + obj = Image(self.evas, **kargs) self.member_add(obj) return obj - def Gradient(self, size=None, pos=None, geometry=None, color=None, - name=None): - obj = Gradient(self.evas) - obj._new_obj() - obj._set_common_params(size=size, pos=pos, geometry=geometry, - color=color, name=name) + def Gradient(self, **kargs): + obj = Gradient(self.evas, **kargs) self.member_add(obj) return obj - def Polygon(self, points=None, size=None, pos=None, geometry=None, - color=None, name=None): - obj = Polygon(self.evas) - obj._new_obj() - obj._set_common_params(points=points, size=size, pos=pos, - geometry=geometry, color=color, name=name) + def Polygon(self, **kargs): + obj = Polygon(self.evas, **kargs) self.member_add(obj) return obj - def Text(self, text=None, font=None, font_source=None, style=None, - shadow_color=None, glow_color=None, glow2_color=None, - outline_color=None, size=None, pos=None, geometry=None, - color=None, name=None): - obj = Text(self.evas) - obj._new_obj() - obj._set_common_params(text=text, font=font, font_source=font_source, - style=style, shadow_color=shadow_color, - glow_color=glow_color, glow2_color=glow2_color, - outline_color=outline_color, size=size, pos=pos, - geometry=geometry, color=color, name=name) + def Text(self, **kargs): + obj = Text(self.evas, **kargs) self.member_add(obj) return obj =================================================================== RCS file: /cvs/e/e17/proto/python-efl/python-evas/evas/evas.c_evas_object_text.pxi,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- evas.c_evas_object_text.pxi 22 Aug 2007 19:04:55 -0000 1.2 +++ evas.c_evas_object_text.pxi 1 Sep 2007 15:59:30 -0000 1.3 @@ -1,16 +1,16 @@ # This file is included verbatim by c_evas.pyx cdef class Text(Object): - def _new_obj(self): + def __init__(self, Canvas canvas not None, **kargs): + Object.__init__(self, canvas) if self.obj == NULL: self._set_obj(evas_object_text_add(self._evas.obj)) + self._set_common_params(**kargs) def _set_common_params(self, text=None, font=None, font_source=None, style=None, shadow_color=None, glow_color=None, - glow2_color=None, outline_color=None, size=None, - pos=None, geometry=None, color=None, name=None): - Object._set_common_params(self, size=size, pos=pos, geometry=geometry, - color=color, name=name) + glow2_color=None, outline_color=None, **kargs): + Object._set_common_params(self, **kargs) if text is not None: self.text_set(text) if font_source: |