New 1.21 API: Ctxpopup item_insert_before/after

with test
This commit is contained in:
Davide Andreoli 2018-07-16 20:00:50 +02:00
parent 006052543f
commit 18ca98e66f
3 changed files with 92 additions and 3 deletions

View File

@ -142,6 +142,7 @@ cdef class CtxpopupItem(ObjectItem):
def __get__(self):
return _object_item_to_python(elm_ctxpopup_item_next_get(self.item))
cdef class Ctxpopup(LayoutClass):
"""
@ -234,6 +235,86 @@ cdef class Ctxpopup(LayoutClass):
else:
return None
def item_insert_before(self, CtxpopupItem before, label, evasObject icon=None,
func=None, *args, **kwargs):
"""Add a new item to the list before the indicated item
:param CtxpopupItem before: The item before which to add it
:param string label: The label of new item
:param evasObject icon: The icon of new item
:param func: The callback function to be invoked when this item is selected.
:param \*args: The data to be attached for callback
:param \*\*kwargs: The data to be attached for callback
:return: :class:`CtxpopupItem`
.. versionadded:: 1.21
"""
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
CtxpopupItem ret = CtxpopupItem.__new__(CtxpopupItem)
if func is not None and callable(func):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_ctxpopup_item_insert_before(self.obj,
before.item if before is not None else NULL,
<const char *>label if label is not None else NULL,
icon.obj if icon is not None else NULL,
cb, <void*>ret)
if item != NULL:
ret._set_obj(item)
ret.cb_func = func
ret.args = args
ret.kwargs = kwargs
return ret
else:
return None
def item_insert_after(self, CtxpopupItem after, label, evasObject icon=None,
func=None, *args, **kwargs):
"""Add a new item to the list after the indicated item
:param CtxpopupItem after: The item after which to add it
:param string label: The label of new item
:param evasObject icon: The icon of new item
:param func: The callback function to be invoked when this item is selected.
:param \*args: The data to be attached for callback
:param \*\*kwargs: The data to be attached for callback
:return: :class:`CtxpopupItem`
.. versionadded:: 1.21
"""
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
CtxpopupItem ret = CtxpopupItem.__new__(CtxpopupItem)
if func is not None and callable(func):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_ctxpopup_item_insert_after(self.obj,
after.item if after is not None else NULL,
<const char *>label if label is not None else NULL,
icon.obj if icon is not None else NULL,
cb, <void*>ret)
if item != NULL:
ret._set_obj(item)
ret.cb_func = func
ret.args = args
ret.kwargs = kwargs
return ret
else:
return None
def item_prepend(self, label, evasObject icon=None,
func=None, *args, **kwargs):
"""A constructor for a :py:class:`CtxpopupItem`.

View File

@ -20,3 +20,5 @@ cdef extern from "Elementary.h":
Elm_Object_Item *elm_ctxpopup_last_item_get(const Evas_Object *obj)
Elm_Object_Item *elm_ctxpopup_item_prev_get(const Elm_Object_Item *it)
Elm_Object_Item *elm_ctxpopup_item_next_get(const Elm_Object_Item *it)
Elm_Object_Item *elm_ctxpopup_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
Elm_Object_Item *elm_ctxpopup_item_insert_after(Evas_Object *obj, Elm_Object_Item *before, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)

View File

@ -58,12 +58,18 @@ def cb_item1(li, item):
it = item_new(cp, "Delete file", "user-trash")
it = item_new(cp, "Navigate to folder", "folder")
it.disabled = True
it = item_new(cp, "Edit entry", "list-add")
it = item_new(cp, "Edit entry", "document-edit")
it = item_new(cp, "Sate date and time", "list-remove")
it.disabled = True
ic = Icon(cp, standard="user-home", resizable=(False,False))
cp.item_prepend("Prepended item", ic, cb_items)
ic = Icon(cp, standard="list-add", resizable=(False,False))
it2 = cp.item_prepend("Prepended item", ic, cb_items)
ic = Icon(cp, standard="list-add", resizable=(False,False))
cp.item_insert_before(it2, "Before the Prepended", ic)
ic = Icon(cp, standard="list-add", resizable=(False,False))
cp.item_insert_after(it2, "After the Prepended", ic)
(x, y) = li.evas.pointer_canvas_xy_get()
cp.move(x, y)