summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2014-02-27 22:38:04 +0100
committerdavemds <dave@gurumeditation.it>2014-02-27 22:38:04 +0100
commit32448918f6ebe7578e29e7269881f954284ddf9b (patch)
tree3bbfdd9b3beec555e70fe01d5e24c0ceb6abae23
parentc2a34f20ad2ba457b768b66d2730617a1e0d7279 (diff)
Python-EFL: new 1.9 API Multibuttonentry.format_function_set()
Sadly this add 2 new points of reference leaks :(
Diffstat (limited to '')
-rw-r--r--TODO9
-rw-r--r--efl/elementary/multibuttonentry.pxd4
-rw-r--r--efl/elementary/multibuttonentry.pyx38
-rw-r--r--examples/elementary/test_multibuttonentry.py21
4 files changed, 69 insertions, 3 deletions
diff --git a/TODO b/TODO
index 39af69c..c1dfb72 100644
--- a/TODO
+++ b/TODO
@@ -3,8 +3,13 @@ BUGS
3==== 3====
4* EdjeEdit: PartState API does not work 4* EdjeEdit: PartState API does not work
5* Elm.Map: overlays_show segfaults, scrollers in examples are jumpy 5* Elm.Map: overlays_show segfaults, scrollers in examples are jumpy
6* Entry.markup_filter_append() and Fileselector.custom_filter_append() are 6* Elementary: when we use custom function callbacks we usually leak some
7 leaking badly, fix and check all other place that have the same issue. 7 reference around, some examples:
8 - Entry.markup_filter_append()
9 - Fileselector.custom_filter_append()
10 - Multibuttonentry.format_function_set()
11 - Multibuttonentry.filter_append()
12 - Multibuttonentry.filterprepend()
8 13
9Failing unit tests 14Failing unit tests
10------------------ 15------------------
diff --git a/efl/elementary/multibuttonentry.pxd b/efl/elementary/multibuttonentry.pxd
index db4282a..682b971 100644
--- a/efl/elementary/multibuttonentry.pxd
+++ b/efl/elementary/multibuttonentry.pxd
@@ -1,10 +1,11 @@
1from efl.evas cimport Eina_Bool, const_Eina_List, Evas_Object, const_Evas_Object, Evas_Smart_Cb 1from efl.evas cimport Eina_Bool, const_Eina_List, Evas_Object, const_Evas_Object, Evas_Smart_Cb
2from object_item cimport Elm_Object_Item, const_Elm_Object_Item, ObjectItem 2from object_item cimport Elm_Object_Item, const_Elm_Object_Item, ObjectItem
3from libc.string cimport const_char 3from libc.string cimport const_char, const_void
4 4
5cdef extern from "Elementary.h": 5cdef extern from "Elementary.h":
6 6
7 ctypedef Eina_Bool (*Elm_Multibuttonentry_Item_Filter_Cb)(Evas_Object *obj, const_char *item_label, void *item_data, void *data) 7 ctypedef Eina_Bool (*Elm_Multibuttonentry_Item_Filter_Cb)(Evas_Object *obj, const_char *item_label, void *item_data, void *data)
8 ctypedef char * (*Elm_Multibuttonentry_Format_Cb)(int count, void *data)
8 9
9 Evas_Object *elm_multibuttonentry_add(Evas_Object *parent) 10 Evas_Object *elm_multibuttonentry_add(Evas_Object *parent)
10 Evas_Object *elm_multibuttonentry_entry_get(const_Evas_Object *obj) 11 Evas_Object *elm_multibuttonentry_entry_get(const_Evas_Object *obj)
@@ -28,3 +29,4 @@ cdef extern from "Elementary.h":
28 # TODO: void elm_multibuttonentry_item_filter_remove(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data) 29 # TODO: void elm_multibuttonentry_item_filter_remove(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data)
29 void elm_multibuttonentry_editable_set(Evas_Object *obj, Eina_Bool editable) 30 void elm_multibuttonentry_editable_set(Evas_Object *obj, Eina_Bool editable)
30 Eina_Bool elm_multibuttonentry_editable_get(const_Evas_Object *obj) 31 Eina_Bool elm_multibuttonentry_editable_get(const_Evas_Object *obj)
32 void elm_multibuttonentry_format_function_set(Evas_Object *obj, Elm_Multibuttonentry_Format_Cb f_func, const_void *data)
diff --git a/efl/elementary/multibuttonentry.pyx b/efl/elementary/multibuttonentry.pyx
index 231c8fe..6e37d71 100644
--- a/efl/elementary/multibuttonentry.pyx
+++ b/efl/elementary/multibuttonentry.pyx
@@ -92,6 +92,18 @@ cdef Eina_Bool _multibuttonentry_filter_callback(Evas_Object *obj, \
92 92
93 return ret 93 return ret
94 94
95cdef char * _multibuttonentry_format_cb(int count, void *data) with gil:
96 (callback, a, ka) = <object>data
97
98 try:
99 ret = callback(count, *a, **ka)
100 except:
101 traceback.print_exc()
102
103 # TODO leak here
104 return strdup(ret)
105
106
95cdef class MultiButtonEntryItem(ObjectItem): 107cdef class MultiButtonEntryItem(ObjectItem):
96 108
97 """An item for the MultiButtonEntry widget.""" 109 """An item for the MultiButtonEntry widget."""
@@ -432,6 +444,32 @@ cdef class MultiButtonEntry(Object):
432 def editable_get(self): 444 def editable_get(self):
433 return bool(elm_multibuttonentry_editable_get(self.obj)) 445 return bool(elm_multibuttonentry_editable_get(self.obj))
434 446
447 def format_function_set(self, func, *args, **kwargs):
448 """format_function_set(func, *args, **kwargs)
449
450 Set a function to format the string that will be used to display
451 the hidden items counter.
452
453 :param func: The actual format function.
454 signature: (int count, args, kwargs)->string
455 :type func: callable
456
457 .. note:: Setting ``func`` to `None` will restore the default format.
458
459 .. versionadded:: 1.9
460
461 """
462 if func is None:
463 elm_multibuttonentry_format_function_set(self.obj, NULL, NULL)
464 return
465
466 cbdata = (func, args, kwargs)
467 elm_multibuttonentry_format_function_set(self.obj,
468 _multibuttonentry_format_cb,
469 <void *>cbdata)
470 # TODO leak here
471 Py_INCREF(cbdata)
472
435 def callback_item_selected_add(self, func, *args, **kwargs): 473 def callback_item_selected_add(self, func, *args, **kwargs):
436 self._callback_add("item,selected", func, *args, **kwargs) 474 self._callback_add("item,selected", func, *args, **kwargs)
437 475
diff --git a/examples/elementary/test_multibuttonentry.py b/examples/elementary/test_multibuttonentry.py
index ede1fdb..e401461 100644
--- a/examples/elementary/test_multibuttonentry.py
+++ b/examples/elementary/test_multibuttonentry.py
@@ -61,6 +61,10 @@ def cb_print(btn, mbe):
61 for i in mbe.items: 61 for i in mbe.items:
62 print(i.text) 62 print(i.text)
63 63
64def custom_format_func(count):
65 return "+ {} rabbits".format(count)
66
67
64def multibuttonentry_clicked(obj, item=None): 68def multibuttonentry_clicked(obj, item=None):
65 win = StandardWindow("multibuttonentry", "MultiButtonEntry test", 69 win = StandardWindow("multibuttonentry", "MultiButtonEntry test",
66 autodel=True, size=(320, 320)) 70 autodel=True, size=(320, 320))
@@ -148,6 +152,23 @@ def multibuttonentry_clicked(obj, item=None):
148 hbox.pack_end(bt) 152 hbox.pack_end(bt)
149 bt.show() 153 bt.show()
150 154
155
156 hbox = Box(win, horizontal=True, size_hint_weight=EXPAND_HORIZ)
157 vbox.pack_end(hbox)
158 hbox.show()
159
160 bt = Button(win, text="Change format function",
161 size_hint_align=FILL_HORIZ, size_hint_weight=EXPAND_HORIZ)
162 bt.callback_clicked_add(lambda b: mbe.format_function_set(custom_format_func))
163 hbox.pack_end(bt)
164 bt.show()
165
166 bt = Button(win, text="Unset format function",
167 size_hint_align=FILL_HORIZ, size_hint_weight=EXPAND_HORIZ)
168 bt.callback_clicked_add(lambda b: mbe.format_function_set(None))
169 hbox.pack_end(bt)
170 bt.show()
171
151 mbe.focus = True 172 mbe.focus = True
152 173
153 win.show() 174 win.show()