kuuko pushed a commit to branch master. http://git.enlightenment.org/bindings/python/python-efl.git/commit/?id=fbc22d850d600bcae4e145f81e2ce6c7c3b02d46
commit fbc22d850d600bcae4e145f81e2ce6c7c3b02d46 Author: Kai Huuhko <kai.huu...@gmail.com> Date: Mon Mar 9 19:36:42 2015 +0200 Make Evas.SO iterator a generic Eo iterator and move to efl.eo --- efl/eo/efl.eo.pyx | 33 ++++++++++++++++++++++++++--- efl/evas/efl.evas_object_smart.pxi | 28 ++---------------------- examples/elementary/test_core_evas_smart.py | 5 +++-- include/efl.c_eo.pxd | 4 +++- include/efl.eo.pxd | 9 ++++++++ 5 files changed, 47 insertions(+), 32 deletions(-) diff --git a/efl/eo/efl.eo.pyx b/efl/eo/efl.eo.pyx index 2c419c0..604ea1e 100644 --- a/efl/eo/efl.eo.pyx +++ b/efl/eo/efl.eo.pyx @@ -34,7 +34,8 @@ from cpython cimport PyObject, Py_INCREF, Py_DECREF, PyUnicode_AsUTF8String from libc.stdint cimport uintptr_t from efl.eina cimport Eina_Bool, \ Eina_Hash, eina_hash_string_superfast_new, eina_hash_add, eina_hash_del, \ - eina_hash_find, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO + eina_hash_find, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, \ + Eina_Iterator, eina_iterator_next, eina_iterator_free from efl.c_eo cimport Eo as cEo, eo_init, eo_shutdown, eo_del, eo_do, \ eo_do_ret, eo_class_name_get, eo_class_get, eo_base_class_get,\ eo_key_data_set, eo_key_data_get, eo_key_data_del, \ @@ -42,7 +43,8 @@ from efl.c_eo cimport Eo as cEo, eo_init, eo_shutdown, eo_del, eo_do, \ eo_parent_get, eo_parent_set, Eo_Event_Description, \ eo_event_freeze, eo_event_thaw, eo_event_freeze_count_get, \ eo_event_global_freeze, eo_event_global_thaw, \ - eo_event_global_freeze_count_get, EO_CALLBACK_STOP + eo_event_global_freeze_count_get, EO_CALLBACK_STOP, \ + eo_children_iterator_new from efl.utils.logger cimport add_logger @@ -200,6 +202,25 @@ cdef Eina_Bool _eo_event_del_cb(void *data, cEo *obj, return EO_CALLBACK_STOP +cdef class EoIterator: + + def __iter__(self): + return self + + def __next__(self): + cdef: + void* tmp + Eina_Bool result + + if not eina_iterator_next(self.itr, &tmp): + raise StopIteration + + return object_from_instance(<cEo *>tmp) + + def __dealloc__(self): + eina_iterator_free(self.itr) + + cdef class Eo(object): """ @@ -248,6 +269,12 @@ cdef class Eo(object): setattr(self, k, v) return 1 + def __iter__(self): + cdef: + void *tmp = NULL + eo_do_ret(self.obj, tmp, eo_children_iterator_new()) + return EoIterator.create(<Eina_Iterator *>tmp) + def delete(self): """Delete the object and free internal resources. @@ -300,7 +327,7 @@ cdef class Eo(object): :return: the freeze count :rtype: int - + """ cdef int fcount = 0 fcount = <int>eo_do_ret(self.obj, fcount, eo_event_freeze_count_get()) diff --git a/efl/evas/efl.evas_object_smart.pxi b/efl/evas/efl.evas_object_smart.pxi index 4958a66..c15fb48 100644 --- a/efl/evas/efl.evas_object_smart.pxi +++ b/efl/evas/efl.evas_object_smart.pxi @@ -17,7 +17,7 @@ from efl.utils.conversions cimport eina_list_objects_to_python_list from efl.c_eo cimport eo_do, eo_do_ret, eo_key_data_del, eo_key_data_set, eo_key_data_get -from efl.eo cimport Eo +from efl.eo cimport Eo, EoIterator from cpython cimport PyMem_Malloc, PyMethod_New, Py_INCREF, Py_DECREF @@ -548,30 +548,6 @@ cdef class Smart(object): pass -cdef class SmartObjectIterator: - - cdef Eina_Iterator *itr - - def __cinit__(self, SmartObject obj): - self.itr = evas_object_smart_iterator_new(obj.obj) - - def __iter__(self): - return self - - def __next__(self): - cdef: - void* tmp - Eina_Bool result - - if not eina_iterator_next(self.itr, &tmp): - raise StopIteration - - return <Object>tmp - - def __dealloc__(self): - eina_iterator_free(self.itr) - - cdef class SmartObject(Object): """ @@ -648,7 +624,7 @@ cdef class SmartObject(Object): return 1 def __iter__(self): - return SmartObjectIterator(self) + return EoIterator.create(evas_object_smart_iterator_new(self.obj)) # property parent: # def __get__(self): diff --git a/examples/elementary/test_core_evas_smart.py b/examples/elementary/test_core_evas_smart.py index ea5e410..2137f51 100644 --- a/examples/elementary/test_core_evas_smart.py +++ b/examples/elementary/test_core_evas_smart.py @@ -4,6 +4,7 @@ import os from random import randint +from efl.eo import Eo from efl.evas import SmartObject, Smart, EXPAND_BOTH, FILL_BOTH, Rectangle, \ Line, FilledImage, Polygon, Text from efl import elementary @@ -54,13 +55,13 @@ class MySmart(Smart): @staticmethod def show(smart_object): print("my show") - for o in smart_object.members: + for o in smart_object: o.show() @staticmethod def hide(smart_object): print("my hide") - for o in smart_object.members: + for o in smart_object: o.hide() @staticmethod diff --git a/include/efl.c_eo.pxd b/include/efl.c_eo.pxd index ae39a5e..bc80e62 100644 --- a/include/efl.c_eo.pxd +++ b/include/efl.c_eo.pxd @@ -15,7 +15,7 @@ # 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.eina cimport Eina_Bool +from efl.eina cimport Eina_Bool, Eina_Iterator cdef extern from "Eo.h": @@ -126,3 +126,5 @@ cdef extern from "Eo.h": void eo_event_callback_add(const Eo_Event_Description *desc, Eo_Event_Cb cb, const void *data) void eo_event_callback_del(const Eo_Event_Description *desc, Eo_Event_Cb cb, const void *data) + + Eina_Iterator * eo_children_iterator_new() diff --git a/include/efl.eo.pxd b/include/efl.eo.pxd index 4b3af1c..6d87428 100644 --- a/include/efl.eo.pxd +++ b/include/efl.eo.pxd @@ -15,6 +15,7 @@ # 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.eina cimport Eina_Iterator from efl.c_eo cimport Eo as cEo cdef: @@ -27,6 +28,14 @@ cdef: int _set_properties_from_keyword_args(self, dict kwargs) except 0 #_add_obj(self, Eo_Class *klass, cEo *parent) + class EoIterator: + cdef Eina_Iterator *itr + @staticmethod + cdef inline create(Eina_Iterator *itr): + cdef EoIterator obj = EoIterator.__new__(EoIterator) + obj.itr = itr + return obj + int PY_REFCOUNT(object o) --