summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-03-12 18:22:46 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2015-03-12 18:22:46 +0200
commit6fa1b78256fee7fdb237bb20b9788e63d4e1d895 (patch)
tree3c0cceef2dc5b684ac597d863c2472a999b7e98c
parent270ac10e0909b63f8aa8a935b3876a43fabf212e (diff)
Evas.SmartObject: Keep reference to Smart in the SO object
Smart gets freed automatically when no SO or user has references to it.
-rw-r--r--efl/evas/efl.evas_object_smart.pxi24
-rw-r--r--include/efl.evas.pxd3
2 files changed, 12 insertions, 15 deletions
diff --git a/efl/evas/efl.evas_object_smart.pxi b/efl/evas/efl.evas_object_smart.pxi
index 4cd32d0..785e36c 100644
--- a/efl/evas/efl.evas_object_smart.pxi
+++ b/efl/evas/efl.evas_object_smart.pxi
@@ -19,7 +19,8 @@ from 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, EoIterator 20from efl.eo cimport Eo, EoIterator
21 21
22from cpython cimport PyMem_Malloc, Py_INCREF, Py_DECREF, PyObject_Call 22from cpython cimport Py_INCREF, Py_DECREF, PyObject_Call, \
23 PyMem_Malloc, PyMem_Free
23 24
24#cdef object _smart_classes 25#cdef object _smart_classes
25#_smart_classes = list() 26#_smart_classes = list()
@@ -376,8 +377,6 @@ cdef class Smart(object):
376 """ 377 """
377 An abstract class with callback methods. 378 An abstract class with callback methods.
378 379
379 Use :meth:`free` to delete the instance.
380
381 :param clipped: Make this Smart use a clipped class, ignoring the provided 380 :param clipped: Make this Smart use a clipped class, ignoring the provided
382 callback methods. 381 callback methods.
383 :type clipped: bool 382 :type clipped: bool
@@ -396,14 +395,12 @@ cdef class Smart(object):
396 .. versionadded:: 1.14 395 .. versionadded:: 1.14
397 """ 396 """
398 397
399 cdef Evas_Smart *cls
400
401 def __cinit__(self, bint clipped=False): 398 def __cinit__(self, bint clipped=False):
402 cdef Evas_Smart_Class *cls_def 399 cdef Evas_Smart_Class *cls_def
403 400
404 cls_def = <Evas_Smart_Class*>PyMem_Malloc(sizeof(Evas_Smart_Class)) 401 cls_def = <Evas_Smart_Class*>PyMem_Malloc(sizeof(Evas_Smart_Class))
405 if cls_def == NULL: 402 if cls_def == NULL:
406 return # raise MemoryError 403 raise MemoryError
407 404
408 name = self.__class__.__name__ 405 name = self.__class__.__name__
409 if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name) 406 if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
@@ -433,13 +430,13 @@ cdef class Smart(object):
433 cls_def.data = <void *>self 430 cls_def.data = <void *>self
434 431
435 self.cls = evas_smart_class_new(cls_def) 432 self.cls = evas_smart_class_new(cls_def)
436 Py_INCREF(self)
437 433
438 def free(self): 434 def __dealloc__(self):
439 """Deletes this Smart instance and frees the C resources.""" 435 cdef const Evas_Smart_Class *cls_def
436 cls_def = evas_smart_class_get(self.cls)
437 PyMem_Free(<void*>cls_def)
440 evas_smart_free(self.cls) 438 evas_smart_free(self.cls)
441 self.cls = NULL 439 self.cls = NULL
442 Py_DECREF(self)
443 440
444 @staticmethod 441 @staticmethod
445 def delete(obj): 442 def delete(obj):
@@ -620,6 +617,7 @@ cdef class SmartObject(Object):
620 #_smart_classes.append(<uintptr_t>cls_def) 617 #_smart_classes.append(<uintptr_t>cls_def)
621 self._set_obj(evas_object_smart_add(canvas.obj, smart.cls)) 618 self._set_obj(evas_object_smart_add(canvas.obj, smart.cls))
622 self._set_properties_from_keyword_args(kwargs) 619 self._set_properties_from_keyword_args(kwargs)
620 self.smart = smart
623 621
624 cdef int _set_obj(self, cEo *obj) except 0: 622 cdef int _set_obj(self, cEo *obj) except 0:
625 assert self.obj == NULL, "Object must be clean" 623 assert self.obj == NULL, "Object must be clean"
@@ -680,12 +678,8 @@ cdef class SmartObject(Object):
680 eina_list_free(lst) 678 eina_list_free(lst)
681 return tuple(ret) 679 return tuple(ret)
682 680
683 property smart:
684 def __get__(self):
685 return <Smart>evas_smart_data_get(evas_object_smart_smart_get(self.obj))
686
687 def smart_get(self): 681 def smart_get(self):
688 return <Smart>evas_smart_data_get(evas_object_smart_smart_get(self.obj)) 682 return self.smart
689 683
690 def move_children_relative(self, int dx, int dy): 684 def move_children_relative(self, int dx, int dy):
691 """Move all children relatively.""" 685 """Move all children relatively."""
diff --git a/include/efl.evas.pxd b/include/efl.evas.pxd
index f9326b8..1ca573f 100644
--- a/include/efl.evas.pxd
+++ b/include/efl.evas.pxd
@@ -1209,9 +1209,12 @@ cdef class Textblock(Object):
1209# cdef extern from *: 1209# cdef extern from *:
1210# ctypedef object(*Smart_Conv_Func)(void *) 1210# ctypedef object(*Smart_Conv_Func)(void *)
1211 1211
1212cdef class Smart:
1213 cdef Evas_Smart *cls
1212 1214
1213cdef class SmartObject(Object): 1215cdef class SmartObject(Object):
1214 cdef: 1216 cdef:
1217 public Smart smart
1215 dict _smart_callback_specs 1218 dict _smart_callback_specs
1216 int _set_obj(self, cEo *obj) except 0 1219 int _set_obj(self, cEo *obj) except 0
1217 int _callback_add_full(self, event, object(*)(void*), func, tuple args, dict kargs) except 0 1220 int _callback_add_full(self, event, object(*)(void*), func, tuple args, dict kargs) except 0