summaryrefslogtreecommitdiff
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
parent3661a78c96a6a264f131d5b9d344248180b68c6b (diff)
Elm.MultiButtonEntry: Fix filter callback
-rw-r--r--efl/elementary/multibuttonentry.pxi31
-rw-r--r--efl/elementary/multibuttonentry_cdef.pxi2
-rw-r--r--examples/elementary/test_multibuttonentry.py15
3 files changed, 14 insertions, 34 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)
diff --git a/examples/elementary/test_multibuttonentry.py b/examples/elementary/test_multibuttonentry.py
index 989598f..59681c4 100644
--- a/examples/elementary/test_multibuttonentry.py
+++ b/examples/elementary/test_multibuttonentry.py
@@ -6,7 +6,7 @@ from efl import elementary
6from efl.elementary import StandardWindow 6from efl.elementary import StandardWindow
7from efl.elementary import Box 7from efl.elementary import Box
8from efl.elementary import Button 8from efl.elementary import Button
9from efl.elementary import MultiButtonEntry, MultiButtonEntryFilterOut 9from efl.elementary import MultiButtonEntry
10from efl.elementary import Scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO 10from efl.elementary import Scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO
11 11
12SCROLL_POLICY_VERT = ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO 12SCROLL_POLICY_VERT = ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO
@@ -55,13 +55,13 @@ def cb_btn_clear2(btn, mbe):
55 55
56def cb_filter1(mbe, text): 56def cb_filter1(mbe, text):
57 print(text) 57 print(text)
58 return True
58 59
59def cb_filter2(mbe, text): 60def cb_filter2(mbe, text):
60 return text[:-2] 61 if text == "nope":
61 62 return False
62def cb_filter3(mbe, text): 63 else:
63 print(text) 64 return True
64 #raise MultiButtonEntryFilterOut
65 65
66def cb_print(btn, mbe): 66def cb_print(btn, mbe):
67 for i in mbe.items: 67 for i in mbe.items:
@@ -86,10 +86,9 @@ def multibuttonentry_clicked(obj, item=None):
86 mbe.callback_item_selected_add(cb_item_selected) 86 mbe.callback_item_selected_add(cb_item_selected)
87 mbe.callback_item_clicked_add(cb_item_clicked) 87 mbe.callback_item_clicked_add(cb_item_clicked)
88 mbe.callback_item_longpressed_add(cb_item_longpressed) 88 mbe.callback_item_longpressed_add(cb_item_longpressed)
89 mbe.part_text_set("guide", "Tap to add recipient") 89 mbe.part_text_set("guide", "Tap to add recipient. Type \"nope\" to test filter rejection.")
90 mbe.filter_append(cb_filter1) 90 mbe.filter_append(cb_filter1)
91 mbe.filter_append(cb_filter2) 91 mbe.filter_append(cb_filter2)
92 mbe.filter_append(cb_filter3)
93 mbe.show() 92 mbe.show()
94 93
95 sc = Scroller(win, bounce=(False, True), policy=SCROLL_POLICY_VERT, 94 sc = Scroller(win, bounce=(False, True), policy=SCROLL_POLICY_VERT,