summaryrefslogtreecommitdiff
path: root/efl
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2016-02-02 21:23:02 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2016-02-02 21:23:02 +0200
commit523fe8ad4dc3e271586ade9972faec24a69e0a2c (patch)
treed74ec17252f8020d93d4397a530c59a06194c741 /efl
parent3661a78c96a6a264f131d5b9d344248180b68c6b (diff)
Elm.MultiButtonEntry: Fix filter callback
Diffstat (limited to 'efl')
-rw-r--r--efl/elementary/multibuttonentry.pxi31
-rw-r--r--efl/elementary/multibuttonentry_cdef.pxi2
2 files changed, 7 insertions, 26 deletions
diff --git a/efl/elementary/multibuttonentry.pxi b/efl/elementary/multibuttonentry.pxi
index 13c28e3..8c6e272 100644
--- a/efl/elementary/multibuttonentry.pxi
+++ b/efl/elementary/multibuttonentry.pxi
@@ -18,45 +18,26 @@
18 18
19include "multibuttonentry_cdef.pxi" 19include "multibuttonentry_cdef.pxi"
20 20
21class MultiButtonEntryFilterOut(Exception):
22 """An exception you may raise in an item filter callback if you wish to prevent addition of the item"""
23 pass
24
25cdef Eina_Bool _multibuttonentry_filter_callback(Evas_Object *obj, \ 21cdef Eina_Bool _multibuttonentry_filter_callback(Evas_Object *obj, \
26 char *item_label, void *item_data, void *data) with gil: 22 const char *item_label, void *item_data, void *data) with gil:
27 23
28 cdef: 24 cdef:
29 MultiButtonEntry mbe = object_from_instance(obj) 25 MultiButtonEntry mbe = object_from_instance(obj)
30 object ret 26 bint ret
31 list callbacks = mbe._item_filters 27 list callbacks = mbe._item_filters
32 28
33 for func, args, kargs in callbacks: 29 for func, args, kargs in callbacks:
34 try: 30 try:
35 # raise MultiButtonEntryFilterOut -> cancels item add
36 # ret is None -> no change, continue to next filter
37 # ret is not None -> change label to value of ret, continue to next filter
38 ret = func(mbe, _ctouni(item_label), *args, **kargs) 31 ret = func(mbe, _ctouni(item_label), *args, **kargs)
39 except MultiButtonEntryFilterOut:
40 #free(item_label) # FIXME: This will result in a double free, find out if it's bad elm documentation
41 # or wrong ref handling on our side.
42
43 #item_label = NULL
44 return 0
45 except Exception: 32 except Exception:
46 traceback.print_exc() 33 traceback.print_exc()
47 continue 34 continue
48 35
49 if ret: 36 if ret:
50 if not isinstance(ret, basestring): 37 continue
51 EINA_LOG_DOM_WARN(PY_EFL_ELM_LOG_DOMAIN, 38 else:
52 "Ignoring invalid return value from MultiButtonEntry item filter callback!", NULL) 39 return 0 # This emulates the behavior of C code where callbacks
53 continue 40 # are iterated until EINA_FALSE is returned by user
54 if isinstance(ret, unicode): ret = PyUnicode_AsUTF8String(ret)
55 #free(item_label) # FIXME: This will result in a double free, find out if it's bad elm documentation
56 # or wrong ref handling on our side.
57
58 item_label = strdup(ret) # Elm will manage the string
59 # FIXME: This doesn't apply, why?
60 41
61 return 1 42 return 1
62 43
diff --git a/efl/elementary/multibuttonentry_cdef.pxi b/efl/elementary/multibuttonentry_cdef.pxi
index 5b2aa34..f8b8218 100644
--- a/efl/elementary/multibuttonentry_cdef.pxi
+++ b/efl/elementary/multibuttonentry_cdef.pxi
@@ -1,6 +1,6 @@
1cdef extern from "Elementary.h": 1cdef extern from "Elementary.h":
2 2
3 ctypedef Eina_Bool (*Elm_Multibuttonentry_Item_Filter_Cb)(Evas_Object *obj, char *item_label, void *item_data, void *data) 3 ctypedef Eina_Bool (*Elm_Multibuttonentry_Item_Filter_Cb)(Evas_Object *obj, const char *item_label, void *item_data, void *data)
4 ctypedef char * (*Elm_Multibuttonentry_Format_Cb)(int count, void *data) 4 ctypedef char * (*Elm_Multibuttonentry_Format_Cb)(int count, void *data)
5 5
6 Evas_Object *elm_multibuttonentry_add(Evas_Object *parent) 6 Evas_Object *elm_multibuttonentry_add(Evas_Object *parent)