summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-03-09 19:36:42 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2015-03-09 19:36:42 +0200
commitfbc22d850d600bcae4e145f81e2ce6c7c3b02d46 (patch)
tree20fbd6d62d614b4e4dff081e6ad9bfa4579d9b12
parent16f04ee2ec91c86dfcbd36c28d727ea4441958c2 (diff)
Make Evas.SO iterator a generic Eo iterator and move to efl.eo
-rw-r--r--efl/eo/efl.eo.pyx33
-rw-r--r--efl/evas/efl.evas_object_smart.pxi28
-rw-r--r--examples/elementary/test_core_evas_smart.py5
-rw-r--r--include/efl.c_eo.pxd4
-rw-r--r--include/efl.eo.pxd9
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
34from libc.stdint cimport uintptr_t 34from libc.stdint cimport uintptr_t
35from efl.eina cimport Eina_Bool, \ 35from efl.eina cimport Eina_Bool, \
36 Eina_Hash, eina_hash_string_superfast_new, eina_hash_add, eina_hash_del, \ 36 Eina_Hash, eina_hash_string_superfast_new, eina_hash_add, eina_hash_del, \
37 eina_hash_find, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO 37 eina_hash_find, EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, \
38 Eina_Iterator, eina_iterator_next, eina_iterator_free
38from efl.c_eo cimport Eo as cEo, eo_init, eo_shutdown, eo_del, eo_do, \ 39from efl.c_eo cimport Eo as cEo, eo_init, eo_shutdown, eo_del, eo_do, \
39 eo_do_ret, eo_class_name_get, eo_class_get, eo_base_class_get,\ 40 eo_do_ret, eo_class_name_get, eo_class_get, eo_base_class_get,\
40 eo_key_data_set, eo_key_data_get, eo_key_data_del, \ 41 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, \
42 eo_parent_get, eo_parent_set, Eo_Event_Description, \ 43 eo_parent_get, eo_parent_set, Eo_Event_Description, \
43 eo_event_freeze, eo_event_thaw, eo_event_freeze_count_get, \ 44 eo_event_freeze, eo_event_thaw, eo_event_freeze_count_get, \
44 eo_event_global_freeze, eo_event_global_thaw, \ 45 eo_event_global_freeze, eo_event_global_thaw, \
45 eo_event_global_freeze_count_get, EO_CALLBACK_STOP 46 eo_event_global_freeze_count_get, EO_CALLBACK_STOP, \
47 eo_children_iterator_new
46 48
47from efl.utils.logger cimport add_logger 49from efl.utils.logger cimport add_logger
48 50
@@ -200,6 +202,25 @@ cdef Eina_Bool _eo_event_del_cb(void *data, cEo *obj,
200 return EO_CALLBACK_STOP 202 return EO_CALLBACK_STOP
201 203
202 204
205cdef class EoIterator:
206
207 def __iter__(self):
208 return self
209
210 def __next__(self):
211 cdef:
212 void* tmp
213 Eina_Bool result
214
215 if not eina_iterator_next(self.itr, &tmp):
216 raise StopIteration
217
218 return object_from_instance(<cEo *>tmp)
219
220 def __dealloc__(self):
221 eina_iterator_free(self.itr)
222
223
203cdef class Eo(object): 224cdef class Eo(object):
204 """ 225 """
205 226
@@ -248,6 +269,12 @@ cdef class Eo(object):
248 setattr(self, k, v) 269 setattr(self, k, v)
249 return 1 270 return 1
250 271
272 def __iter__(self):
273 cdef:
274 void *tmp = NULL
275 eo_do_ret(self.obj, tmp, eo_children_iterator_new())
276 return EoIterator.create(<Eina_Iterator *>tmp)
277
251 def delete(self): 278 def delete(self):
252 """Delete the object and free internal resources. 279 """Delete the object and free internal resources.
253 280
@@ -300,7 +327,7 @@ cdef class Eo(object):
300 327
301 :return: the freeze count 328 :return: the freeze count
302 :rtype: int 329 :rtype: int
303 330
304 """ 331 """
305 cdef int fcount = 0 332 cdef int fcount = 0
306 fcount = <int>eo_do_ret(self.obj, fcount, eo_event_freeze_count_get()) 333 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 @@
17 17
18from efl.utils.conversions cimport eina_list_objects_to_python_list 18from efl.utils.conversions cimport eina_list_objects_to_python_list
19from efl.c_eo cimport eo_do, eo_do_ret, eo_key_data_del, eo_key_data_set, eo_key_data_get 19from efl.c_eo cimport eo_do, eo_do_ret, eo_key_data_del, eo_key_data_set, eo_key_data_get
20from efl.eo cimport Eo 20from efl.eo cimport Eo, EoIterator
21 21
22from cpython cimport PyMem_Malloc, PyMethod_New, Py_INCREF, Py_DECREF 22from cpython cimport PyMem_Malloc, PyMethod_New, Py_INCREF, Py_DECREF
23 23
@@ -548,30 +548,6 @@ cdef class Smart(object):
548 pass 548 pass
549 549
550 550
551cdef class SmartObjectIterator:
552
553 cdef Eina_Iterator *itr
554
555 def __cinit__(self, SmartObject obj):
556 self.itr = evas_object_smart_iterator_new(obj.obj)
557
558 def __iter__(self):
559 return self
560
561 def __next__(self):
562 cdef:
563 void* tmp
564 Eina_Bool result
565
566 if not eina_iterator_next(self.itr, &tmp):
567 raise StopIteration
568
569 return <Object>tmp
570
571 def __dealloc__(self):
572 eina_iterator_free(self.itr)
573
574
575cdef class SmartObject(Object): 551cdef class SmartObject(Object):
576 552
577 """ 553 """
@@ -648,7 +624,7 @@ cdef class SmartObject(Object):
648 return 1 624 return 1
649 625
650 def __iter__(self): 626 def __iter__(self):
651 return SmartObjectIterator(self) 627 return EoIterator.create(evas_object_smart_iterator_new(self.obj))
652 628
653 # property parent: 629 # property parent:
654 # def __get__(self): 630 # 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 @@
4import os 4import os
5from random import randint 5from random import randint
6 6
7from efl.eo import Eo
7from efl.evas import SmartObject, Smart, EXPAND_BOTH, FILL_BOTH, Rectangle, \ 8from efl.evas import SmartObject, Smart, EXPAND_BOTH, FILL_BOTH, Rectangle, \
8 Line, FilledImage, Polygon, Text 9 Line, FilledImage, Polygon, Text
9from efl import elementary 10from efl import elementary
@@ -54,13 +55,13 @@ class MySmart(Smart):
54 @staticmethod 55 @staticmethod
55 def show(smart_object): 56 def show(smart_object):
56 print("my show") 57 print("my show")
57 for o in smart_object.members: 58 for o in smart_object:
58 o.show() 59 o.show()
59 60
60 @staticmethod 61 @staticmethod
61 def hide(smart_object): 62 def hide(smart_object):
62 print("my hide") 63 print("my hide")
63 for o in smart_object.members: 64 for o in smart_object:
64 o.hide() 65 o.hide()
65 66
66 @staticmethod 67 @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 @@
15# You should have received a copy of the GNU Lesser General Public License 15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>. 16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17 17
18from efl.eina cimport Eina_Bool 18from efl.eina cimport Eina_Bool, Eina_Iterator
19 19
20cdef extern from "Eo.h": 20cdef extern from "Eo.h":
21 21
@@ -126,3 +126,5 @@ cdef extern from "Eo.h":
126 126
127 void eo_event_callback_add(const Eo_Event_Description *desc, Eo_Event_Cb cb, const void *data) 127 void eo_event_callback_add(const Eo_Event_Description *desc, Eo_Event_Cb cb, const void *data)
128 void eo_event_callback_del(const Eo_Event_Description *desc, Eo_Event_Cb cb, const void *data) 128 void eo_event_callback_del(const Eo_Event_Description *desc, Eo_Event_Cb cb, const void *data)
129
130 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 @@
15# You should have received a copy of the GNU Lesser General Public License 15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>. 16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17 17
18from efl.eina cimport Eina_Iterator
18from efl.c_eo cimport Eo as cEo 19from efl.c_eo cimport Eo as cEo
19 20
20cdef: 21cdef:
@@ -27,6 +28,14 @@ cdef:
27 int _set_properties_from_keyword_args(self, dict kwargs) except 0 28 int _set_properties_from_keyword_args(self, dict kwargs) except 0
28 #_add_obj(self, Eo_Class *klass, cEo *parent) 29 #_add_obj(self, Eo_Class *klass, cEo *parent)
29 30
31 class EoIterator:
32 cdef Eina_Iterator *itr
33 @staticmethod
34 cdef inline create(Eina_Iterator *itr):
35 cdef EoIterator obj = EoIterator.__new__(EoIterator)
36 obj.itr = itr
37 return obj
38
30 39
31 int PY_REFCOUNT(object o) 40 int PY_REFCOUNT(object o)
32 41