kuuko pushed a commit to branch master.

http://git.enlightenment.org/bindings/python/python-efl.git/commit/?id=4fedd0722824b4d350447bf3a012aaf3abda4b0e

commit 4fedd0722824b4d350447bf3a012aaf3abda4b0e
Author: Kai Huuhko <[email protected]>
Date:   Mon Mar 2 10:16:34 2015 +0200

    Elementary.box: Add an iterator for Box's children
    
    Usage example:
    
      box = Box(parent)
      box.pack_end(mychild)
    
      for child in box:
          print(child)
---
 efl/elementary/box.pyx | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/efl/elementary/box.pyx b/efl/elementary/box.pyx
index 3e00c3c..3d1b99d 100644
--- a/efl/elementary/box.pyx
+++ b/efl/elementary/box.pyx
@@ -135,7 +135,8 @@ Inheritance diagram
 
 """
 
-from efl.eo cimport _object_mapping_register
+from efl.c_eo cimport Eo as cEo
+from efl.eo cimport _object_mapping_register, object_from_instance
 from efl.evas cimport Object as evasObject
 from object cimport Object
 
@@ -173,6 +174,21 @@ cdef Evas_Object_Box_Layout _py_elm_box_layout_resolv(int 
layout) with gil:
         return evas_object_box_layout_stack
     return evas_object_box_layout_vertical
 
+cdef class BoxIterator(object):
+    cdef const Eina_List *lst
+    def __cinit__(self, Box box):
+        self.lst = elm_box_children_get(box.obj)
+
+    def __iter__(self):
+        return self
+
+    def __next__(self):
+        if self.lst == NULL:
+            raise StopIteration
+        cdef cEo *ret = <cEo *>self.lst.data
+        self.lst = self.lst.next
+        return object_from_instance(ret)
+
 cdef class Box(Object):
     """
 
@@ -194,6 +210,9 @@ cdef class Box(Object):
         self._set_obj(elm_box_add(parent.obj))
         self._set_properties_from_keyword_args(kwargs)
 
+    def __iter__(self):
+        return BoxIterator(self)
+
     property horizontal:
         """The horizontal orientation.
 

-- 


Reply via email to