Elm.MultiButtonEntry: Fix filter callback
This commit is contained in:
parent
3661a78c96
commit
523fe8ad4d
|
@ -18,45 +18,26 @@
|
||||||
|
|
||||||
include "multibuttonentry_cdef.pxi"
|
include "multibuttonentry_cdef.pxi"
|
||||||
|
|
||||||
class MultiButtonEntryFilterOut(Exception):
|
|
||||||
"""An exception you may raise in an item filter callback if you wish to prevent addition of the item"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
cdef Eina_Bool _multibuttonentry_filter_callback(Evas_Object *obj, \
|
cdef Eina_Bool _multibuttonentry_filter_callback(Evas_Object *obj, \
|
||||||
char *item_label, void *item_data, void *data) with gil:
|
const char *item_label, void *item_data, void *data) with gil:
|
||||||
|
|
||||||
cdef:
|
cdef:
|
||||||
MultiButtonEntry mbe = object_from_instance(obj)
|
MultiButtonEntry mbe = object_from_instance(obj)
|
||||||
object ret
|
bint ret
|
||||||
list callbacks = mbe._item_filters
|
list callbacks = mbe._item_filters
|
||||||
|
|
||||||
for func, args, kargs in callbacks:
|
for func, args, kargs in callbacks:
|
||||||
try:
|
try:
|
||||||
# raise MultiButtonEntryFilterOut -> cancels item add
|
|
||||||
# ret is None -> no change, continue to next filter
|
|
||||||
# ret is not None -> change label to value of ret, continue to next filter
|
|
||||||
ret = func(mbe, _ctouni(item_label), *args, **kargs)
|
ret = func(mbe, _ctouni(item_label), *args, **kargs)
|
||||||
except MultiButtonEntryFilterOut:
|
|
||||||
#free(item_label) # FIXME: This will result in a double free, find out if it's bad elm documentation
|
|
||||||
# or wrong ref handling on our side.
|
|
||||||
|
|
||||||
#item_label = NULL
|
|
||||||
return 0
|
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if ret:
|
if ret:
|
||||||
if not isinstance(ret, basestring):
|
continue
|
||||||
EINA_LOG_DOM_WARN(PY_EFL_ELM_LOG_DOMAIN,
|
else:
|
||||||
"Ignoring invalid return value from MultiButtonEntry item filter callback!", NULL)
|
return 0 # This emulates the behavior of C code where callbacks
|
||||||
continue
|
# are iterated until EINA_FALSE is returned by user
|
||||||
if isinstance(ret, unicode): ret = PyUnicode_AsUTF8String(ret)
|
|
||||||
#free(item_label) # FIXME: This will result in a double free, find out if it's bad elm documentation
|
|
||||||
# or wrong ref handling on our side.
|
|
||||||
|
|
||||||
item_label = strdup(ret) # Elm will manage the string
|
|
||||||
# FIXME: This doesn't apply, why?
|
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
cdef extern from "Elementary.h":
|
cdef extern from "Elementary.h":
|
||||||
|
|
||||||
ctypedef Eina_Bool (*Elm_Multibuttonentry_Item_Filter_Cb)(Evas_Object *obj, char *item_label, void *item_data, void *data)
|
ctypedef Eina_Bool (*Elm_Multibuttonentry_Item_Filter_Cb)(Evas_Object *obj, const char *item_label, void *item_data, void *data)
|
||||||
ctypedef char * (*Elm_Multibuttonentry_Format_Cb)(int count, void *data)
|
ctypedef char * (*Elm_Multibuttonentry_Format_Cb)(int count, void *data)
|
||||||
|
|
||||||
Evas_Object *elm_multibuttonentry_add(Evas_Object *parent)
|
Evas_Object *elm_multibuttonentry_add(Evas_Object *parent)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from efl import elementary
|
||||||
from efl.elementary import StandardWindow
|
from efl.elementary import StandardWindow
|
||||||
from efl.elementary import Box
|
from efl.elementary import Box
|
||||||
from efl.elementary import Button
|
from efl.elementary import Button
|
||||||
from efl.elementary import MultiButtonEntry, MultiButtonEntryFilterOut
|
from efl.elementary import MultiButtonEntry
|
||||||
from efl.elementary import Scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO
|
from efl.elementary import Scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO
|
||||||
|
|
||||||
SCROLL_POLICY_VERT = ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO
|
SCROLL_POLICY_VERT = ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO
|
||||||
|
@ -55,13 +55,13 @@ def cb_btn_clear2(btn, mbe):
|
||||||
|
|
||||||
def cb_filter1(mbe, text):
|
def cb_filter1(mbe, text):
|
||||||
print(text)
|
print(text)
|
||||||
|
return True
|
||||||
|
|
||||||
def cb_filter2(mbe, text):
|
def cb_filter2(mbe, text):
|
||||||
return text[:-2]
|
if text == "nope":
|
||||||
|
return False
|
||||||
def cb_filter3(mbe, text):
|
else:
|
||||||
print(text)
|
return True
|
||||||
#raise MultiButtonEntryFilterOut
|
|
||||||
|
|
||||||
def cb_print(btn, mbe):
|
def cb_print(btn, mbe):
|
||||||
for i in mbe.items:
|
for i in mbe.items:
|
||||||
|
@ -86,10 +86,9 @@ def multibuttonentry_clicked(obj, item=None):
|
||||||
mbe.callback_item_selected_add(cb_item_selected)
|
mbe.callback_item_selected_add(cb_item_selected)
|
||||||
mbe.callback_item_clicked_add(cb_item_clicked)
|
mbe.callback_item_clicked_add(cb_item_clicked)
|
||||||
mbe.callback_item_longpressed_add(cb_item_longpressed)
|
mbe.callback_item_longpressed_add(cb_item_longpressed)
|
||||||
mbe.part_text_set("guide", "Tap to add recipient")
|
mbe.part_text_set("guide", "Tap to add recipient. Type \"nope\" to test filter rejection.")
|
||||||
mbe.filter_append(cb_filter1)
|
mbe.filter_append(cb_filter1)
|
||||||
mbe.filter_append(cb_filter2)
|
mbe.filter_append(cb_filter2)
|
||||||
mbe.filter_append(cb_filter3)
|
|
||||||
mbe.show()
|
mbe.show()
|
||||||
|
|
||||||
sc = Scroller(win, bounce=(False, True), policy=SCROLL_POLICY_VERT,
|
sc = Scroller(win, bounce=(False, True), policy=SCROLL_POLICY_VERT,
|
||||||
|
|
Loading…
Reference in New Issue