summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-03-13 02:40:39 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2015-03-13 02:40:39 +0200
commit3120e56250e2ec87b74c0c01f8a53234fa8610b7 (patch)
tree677bc8509e82d058bcc2698d5737faa222dad3b4
parent807f0417db9c639ee6e92b59bf9a20f4973f4cbc (diff)
Evas.SmartObject: Go back to the old cb system
Turns out the C calls are awfully slow. Dave, good work with the tests!
-rw-r--r--efl/evas/efl.evas_object_smart.pxi119
1 files changed, 72 insertions, 47 deletions
diff --git a/efl/evas/efl.evas_object_smart.pxi b/efl/evas/efl.evas_object_smart.pxi
index 785e36c..998a6a2 100644
--- a/efl/evas/efl.evas_object_smart.pxi
+++ b/efl/evas/efl.evas_object_smart.pxi
@@ -340,36 +340,52 @@ cdef void _smart_callback(void *data, Evas_Object *o, void *event_info) with gil
340 EINA_LOG_DOM_ERR(PY_EFL_EVAS_LOG_DOMAIN, "data is NULL!", NULL) 340 EINA_LOG_DOM_ERR(PY_EFL_EVAS_LOG_DOMAIN, "data is NULL!", NULL)
341 return 341 return
342 342
343 cdef _SmartCb spec = <_SmartCb>data 343 cdef:
344 cdef list tmp_args 344 void *tmp = NULL
345 SmartObject obj
346 object event, ei
347 _SmartCb spec
348 list tmp_args
349 list lst
345 350
346 if event_info == NULL: 351 eo_do_ret(o, tmp, eo_key_data_get("python-eo"))
347 try: 352 if tmp == NULL:
348 tmp_args = [spec.obj] 353 EINA_LOG_DOM_ERR(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL)
349 tmp_args.extend(spec.args) 354 return
350 PyObject_Call(spec.func, tuple(tmp_args), spec.kargs)
351 except Exception:
352 traceback.print_exc()
353 elif spec.event_conv == NULL:
354 EINA_LOG_DOM_WARN(
355 PY_EFL_EVAS_LOG_DOMAIN,
356 'event_info for event "%s" is not NULL and there is no event_conv!',
357 spec.event
358 )
359 try:
360 tmp_args = [spec.obj]
361 tmp_args.extend(spec.args)
362 PyObject_Call(spec.func, tuple(tmp_args), spec.kargs)
363 except Exception:
364 traceback.print_exc()
365 else: 355 else:
366 try: 356 obj = <SmartObject>tmp
367 tmp_args = [spec.obj] 357
368 tmp_args.append(spec.event_conv(event_info)) 358 event = <object>data
369 tmp_args.extend(spec.args) 359 lst = <list>obj._smart_callback_specs[event]
370 PyObject_Call(spec.func, tuple(tmp_args), spec.kargs) 360
371 except Exception: 361 for spec in lst:
372 traceback.print_exc() 362 if event_info == NULL:
363 try:
364 tmp_args = [spec.obj]
365 tmp_args.extend(spec.args)
366 PyObject_Call(spec.func, tuple(tmp_args), spec.kargs)
367 except Exception:
368 traceback.print_exc()
369 elif spec.event_conv == NULL:
370 EINA_LOG_DOM_WARN(
371 PY_EFL_EVAS_LOG_DOMAIN,
372 'event_info for event "%s" is not NULL and there is no event_conv!',
373 spec.event
374 )
375 try:
376 tmp_args = [spec.obj]
377 tmp_args.extend(spec.args)
378 PyObject_Call(spec.func, tuple(tmp_args), spec.kargs)
379 except Exception:
380 traceback.print_exc()
381 else:
382 try:
383 tmp_args = [spec.obj]
384 tmp_args.append(spec.event_conv(event_info))
385 tmp_args.extend(spec.args)
386 PyObject_Call(spec.func, tuple(tmp_args), spec.kargs)
387 except Exception:
388 traceback.print_exc()
373 389
374 390
375cdef class Smart(object): 391cdef class Smart(object):
@@ -764,9 +780,14 @@ cdef class SmartObject(Object):
764 if not callable(func): 780 if not callable(func):
765 raise TypeError("func must be callable") 781 raise TypeError("func must be callable")
766 782
783 cdef:
784 list lst
785 _SmartCb spec
786 object e = intern(event)
787
767 if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event) 788 if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event)
768 789
769 cdef _SmartCb spec = _SmartCb() 790 spec = _SmartCb.__new__(_SmartCb)
770 spec.event = event 791 spec.event = event
771 spec.obj = self 792 spec.obj = self
772 spec.event_conv = event_conv 793 spec.event_conv = event_conv
@@ -774,13 +795,15 @@ cdef class SmartObject(Object):
774 spec.args = args 795 spec.args = args
775 spec.kargs = kargs 796 spec.kargs = kargs
776 797
777 lst = self._smart_callback_specs.setdefault(event, []) 798 lst = <list>self._smart_callback_specs.setdefault(e, [])
799 if not lst:
800 evas_object_smart_callback_add(self.obj,
801 spec.event,
802 _smart_callback,
803 <void *>e
804 )
778 lst.append(spec) 805 lst.append(spec)
779 806
780 evas_object_smart_callback_add(self.obj,
781 <const char *>event if event is not None else NULL,
782 _smart_callback, <void *>spec)
783
784 return 1 807 return 1
785 808
786 cdef int _callback_del_full(self, event, object(*event_conv)(void *), func) except 0: 809 cdef int _callback_del_full(self, event, object(*event_conv)(void *), func) except 0:
@@ -806,10 +829,9 @@ cdef class SmartObject(Object):
806 int found = 0 829 int found = 0
807 int i 830 int i
808 void *tmp 831 void *tmp
832 list lst
809 833
810 if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event) 834 lst = <list>self._smart_callback_specs.get(event, None)
811
812 lst = self._smart_callback_specs.get(event, None)
813 835
814 if lst is None: 836 if lst is None:
815 raise ValueError("No callbacks registered for the given event type") 837 raise ValueError("No callbacks registered for the given event type")
@@ -822,17 +844,17 @@ cdef class SmartObject(Object):
822 if found == 0: 844 if found == 0:
823 raise ValueError("func not registered") 845 raise ValueError("func not registered")
824 846
825 tmp = evas_object_smart_callback_del_full(self.obj,
826 <const char *>event if event is not None else NULL,
827 _smart_callback,
828 <void *>spec
829 )
830
831 if tmp == NULL:
832 raise RuntimeError("Something went wrong while unregistering!")
833
834 lst.pop(i) 847 lst.pop(i)
835 848
849 if not lst:
850 if isinstance(event, unicode): event = PyUnicode_AsUTF8String(event)
851 tmp = evas_object_smart_callback_del(self.obj,
852 event,
853 _smart_callback
854 )
855 if tmp == NULL:
856 raise RuntimeError("Something went wrong while unregistering!")
857
836 return 1 858 return 1
837 859
838 cdef int _callback_add(self, event, func, args, kargs) except 0: 860 cdef int _callback_add(self, event, func, args, kargs) except 0:
@@ -915,7 +937,10 @@ cdef class SmartObject(Object):
915 **event_info** will always be a python object. 937 **event_info** will always be a python object.
916 """ 938 """
917 if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name) 939 if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
918 evas_object_smart_callback_call(self.obj, name, <void*>event_info) 940 evas_object_smart_callback_call(
941 self.obj, name,
942 <void*>event_info if event_info is not None else NULL
943 )
919 944
920 945
921_object_mapping_register("Evas_Smart", SmartObject) 946_object_mapping_register("Evas_Smart", SmartObject)