summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-03-12 02:00:04 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2015-03-12 02:00:04 +0200
commit8b594d4bd889a24facf54b969ffda958b1180cce (patch)
tree7c9ae04c2e9f240d1e551b18f38946d61eeeb4b0
parent247eb9e452c2490ff1312e6ba2af63937f11a4c6 (diff)
Evas.SmartObject: Improve Smart cb handling
Calling custom callbacks with event_info was broken, fixed. A check was added for event_info pointer, a warning will emit when it's non-NULL and we don't have a conv function set. Small optimizations.
-rw-r--r--efl/evas/efl.evas_object_smart.pxi66
1 files changed, 41 insertions, 25 deletions
diff --git a/efl/evas/efl.evas_object_smart.pxi b/efl/evas/efl.evas_object_smart.pxi
index f22b4f1..129e46e 100644
--- a/efl/evas/efl.evas_object_smart.pxi
+++ b/efl/evas/efl.evas_object_smart.pxi
@@ -19,12 +19,16 @@ 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, PyMethod_New, Py_INCREF, Py_DECREF 22from cpython cimport PyMem_Malloc, Py_INCREF, Py_DECREF
23 23
24#cdef object _smart_classes 24#cdef object _smart_classes
25#_smart_classes = list() 25#_smart_classes = list()
26 26
27 27
28cdef object _smart_cb_pass_conv(void *addr):
29 return <object>addr
30
31
28cdef void _smart_object_delete(Evas_Object *o) with gil: 32cdef void _smart_object_delete(Evas_Object *o) with gil:
29 cdef: 33 cdef:
30 void *tmp 34 void *tmp
@@ -322,37 +326,49 @@ cdef void _smart_object_member_del(Evas_Object *o, Evas_Object *clip) with gil:
322cdef void _smart_callback(void *data, Evas_Object *o, void *event_info) with gil: 326cdef void _smart_callback(void *data, Evas_Object *o, void *event_info) with gil:
323 327
324 cdef: 328 cdef:
325 void *tmp = NULL
326 SmartObject obj 329 SmartObject obj
327 object ei
328 object(*event_conv)(void*) 330 object(*event_conv)(void*)
329 331 uintptr_t conv
330 eo_do_ret(o, tmp, eo_key_data_get("python-eo")) 332 object func
331 if tmp == NULL: 333 tuple args
332 EINA_LOG_DOM_ERR(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL) 334 dict kargs
333 return 335 tuple tmp
334 else:
335 obj = <SmartObject>tmp
336 336
337 if data == NULL: 337 if data == NULL:
338 EINA_LOG_DOM_ERR(PY_EFL_EVAS_LOG_DOMAIN, "data is NULL!", NULL) 338 EINA_LOG_DOM_ERR(PY_EFL_EVAS_LOG_DOMAIN, "data is NULL!", NULL)
339 return 339 return
340 else:
341 conv, func, args, kargs = <tuple>data
342 340
343 if conv != 0: 341 #obj, conv, func, args, kargs = <tuple>data
344 event_conv = <object(*)(void*)><void *><uintptr_t>conv
345 else:
346 event_conv = NULL
347 342
348 try: 343 tmp = <tuple>data
349 if event_conv is NULL: 344 obj = <SmartObject>tmp[0]
345 conv = <uintptr_t>tmp[1]
346 func = tmp[2]
347 args = <tuple>tmp[3]
348 kargs = <dict>tmp[4]
349
350 if event_info == NULL:
351 try:
350 func(obj, *args, **kargs) 352 func(obj, *args, **kargs)
351 else: 353 except Exception:
354 traceback.print_exc()
355 elif conv == 0:
356 EINA_LOG_DOM_WARN(
357 PY_EFL_EVAS_LOG_DOMAIN,
358 "event_info is not NULL and there is no event_conv!",
359 NULL
360 )
361 try:
362 func(obj, *args, **kargs)
363 except Exception:
364 traceback.print_exc()
365 else:
366 event_conv = <object(*)(void*)><void *>conv
367 try:
352 ei = event_conv(event_info) 368 ei = event_conv(event_info)
353 func(obj, ei, *args, **kargs) 369 func(obj, ei, *args, **kargs)
354 except Exception: 370 except Exception:
355 traceback.print_exc() 371 traceback.print_exc()
356 372
357 373
358cdef class Smart(object): 374cdef class Smart(object):
@@ -755,7 +771,7 @@ cdef class SmartObject(Object):
755 raise TypeError("func must be callable") 771 raise TypeError("func must be callable")
756 if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event) 772 if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event)
757 773
758 spec = (<uintptr_t><void *>event_conv, func, args, kargs) 774 spec = (self, <uintptr_t><void *>event_conv, func, args, kargs)
759 lst = self._smart_callback_specs.setdefault(event, []) 775 lst = self._smart_callback_specs.setdefault(event, [])
760 lst.append(spec) 776 lst.append(spec)
761 777
@@ -797,7 +813,7 @@ cdef class SmartObject(Object):
797 raise ValueError("No callbacks registered for the given event type") 813 raise ValueError("No callbacks registered for the given event type")
798 814
799 for i, spec in enumerate(lst): 815 for i, spec in enumerate(lst):
800 if spec[1] is func: 816 if spec[2] is func:
801 found = 1 817 found = 1
802 break 818 break
803 819
@@ -866,7 +882,7 @@ cdef class SmartObject(Object):
866 signal is provided by a C-only class, it will crash. 882 signal is provided by a C-only class, it will crash.
867 883
868 """ 884 """
869 self._callback_add_full(name, NULL, func, args, kargs) 885 self._callback_add_full(name, _smart_cb_pass_conv, func, args, kargs)
870 886
871 def callback_del(self, name, func): 887 def callback_del(self, name, func):
872 """Remove a smart callback. 888 """Remove a smart callback.
@@ -880,7 +896,7 @@ cdef class SmartObject(Object):
880 896
881 :raise ValueError: if there was no **func** connected with this event. 897 :raise ValueError: if there was no **func** connected with this event.
882 """ 898 """
883 self._callback_del_full(name, NULL, func) 899 self._callback_del_full(name, _smart_cb_pass_conv, func)
884 900
885 def callback_call(self, name, event_info=None): 901 def callback_call(self, name, event_info=None):
886 """Call any smart callbacks for event. 902 """Call any smart callbacks for event.