davemds pushed a commit to branch master. http://git.enlightenment.org/bindings/python/python-efl.git/commit/?id=a97e61dd4ffceb30e62cc0973e879e60a8d43169
commit a97e61dd4ffceb30e62cc0973e879e60a8d43169 Author: davemds <d...@gurumeditation.it> Date: Thu Jul 31 22:18:41 2014 +0200 Ctxpopup: new getters for items and the item_prepend method, with tests --- efl/elementary/ctxpopup.pxd | 8 +- efl/elementary/ctxpopup.pyx | 142 ++++++++++++++++++++++++++++++++++- examples/elementary/test_ctxpopup.py | 23 ++++++ 3 files changed, 169 insertions(+), 4 deletions(-) diff --git a/efl/elementary/ctxpopup.pxd b/efl/elementary/ctxpopup.pxd index a976554..31ab98f 100644 --- a/efl/elementary/ctxpopup.pxd +++ b/efl/elementary/ctxpopup.pxd @@ -1,4 +1,4 @@ -from efl.evas cimport Eina_Bool, Evas_Object, Evas_Smart_Cb +from efl.evas cimport Eina_Bool, Eina_List, Evas_Object, Evas_Smart_Cb from object_item cimport Elm_Object_Item from enums cimport Elm_Ctxpopup_Direction @@ -10,10 +10,16 @@ cdef extern from "Elementary.h": void elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal) Eina_Bool elm_ctxpopup_horizontal_get(const Evas_Object *obj) Elm_Object_Item *elm_ctxpopup_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, void *data) + Elm_Object_Item *elm_ctxpopup_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, void *data) void elm_ctxpopup_direction_priority_set(Evas_Object *obj, Elm_Ctxpopup_Direction first, Elm_Ctxpopup_Direction second, Elm_Ctxpopup_Direction third, Elm_Ctxpopup_Direction fourth) void elm_ctxpopup_direction_priority_get(const Evas_Object *obj, Elm_Ctxpopup_Direction *first, Elm_Ctxpopup_Direction *second, Elm_Ctxpopup_Direction *third, Elm_Ctxpopup_Direction *fourth) Elm_Ctxpopup_Direction elm_ctxpopup_direction_get(const Evas_Object *obj) void elm_ctxpopup_dismiss(Evas_Object *obj) void elm_ctxpopup_auto_hide_disabled_set(Evas_Object *obj, Eina_Bool disabled) Eina_Bool elm_ctxpopup_auto_hide_disabled_get(const Evas_Object *obj) + Eina_List *elm_ctxpopup_items_get(const Evas_Object *obj) + Elm_Object_Item *elm_ctxpopup_first_item_get(const Evas_Object *obj) + 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) diff --git a/efl/elementary/ctxpopup.pyx b/efl/elementary/ctxpopup.pyx index 28e08d5..feba3a7 100644 --- a/efl/elementary/ctxpopup.pyx +++ b/efl/elementary/ctxpopup.pyx @@ -95,7 +95,7 @@ from efl.eo cimport _object_mapping_register, object_from_instance from efl.evas cimport Object as evasObject from layout_class cimport LayoutClass from object_item cimport ObjectItem, _object_item_callback, \ - _object_item_callback2 + _object_item_callback2, _object_item_to_python, _object_item_list_to_python cimport enums @@ -175,6 +175,63 @@ cdef class CtxpopupItem(ObjectItem): self._set_properties_from_keyword_args(self.kwargs) return self + def prepend_to(self, evasObject ctxpopup): + """Prepend a new item to a ctxpopup object. + + .. warning:: Ctxpopup can't hold both an item list and a content at the + same time. When an item is added, any previous content will be + removed. + + .. seealso:: :py:attr:`~efl.elementary.object.Object.content` + + :param ctxpopup: The Ctxpopup widget this item is to be prepended on + :type ctxpopup: :py:class:`Ctxpopup` + :return: The item added or ``None``, on errors + :rtype: :py:class:`CtxpopupItem` + + ..versionadded:: 1.11 + + """ + cdef Elm_Object_Item *item + cdef Evas_Smart_Cb cb = NULL + + if self.cb_func is not None: + cb = _object_item_callback2 + + item = elm_ctxpopup_item_prepend(ctxpopup.obj, + <const char *>self.label if self.label is not None else NULL, + self.icon.obj if self.icon is not None else NULL, + cb, <void*>self) + + if item == NULL: + raise RuntimeError("The item could not be added to the widget.") + + self._set_obj(item) + self._set_properties_from_keyword_args(self.kwargs) + return self + + property prev: + """ The previous item. + + :type: :py:class:`CtxpopupItem` + + ..versionadded:: 1.11 + + """ + def __get__(self): + return _object_item_to_python(elm_ctxpopup_item_prev_get(self.item)) + + property next: + """ The next item. + + :type: :py:class:`CtxpopupItem` + + ..versionadded:: 1.11 + + """ + def __get__(self): + return _object_item_to_python(elm_ctxpopup_item_next_get(self.item)) + cdef class Ctxpopup(LayoutClass): """This is the class that actually implements the widget. @@ -226,8 +283,8 @@ cdef class Ctxpopup(LayoutClass): def horizontal_get(self): return bool(elm_ctxpopup_horizontal_get(self.obj)) - def item_append(self, label, evasObject icon = None, func = None, - *args, **kwargs): + def item_append(self, label, evasObject icon=None, + func=None, *args, **kwargs): """A constructor for a :py:class:`CtxpopupItem`. :see: :py:func:`CtxpopupItem.append_to` @@ -257,6 +314,85 @@ cdef class Ctxpopup(LayoutClass): else: return None + def item_prepend(self, label, evasObject icon=None, + func=None, *args, **kwargs): + """A constructor for a :py:class:`CtxpopupItem`. + + :see: :py:func:`CtxpopupItem.prepend_to` + + ..versionadded:: 1.11 + + """ + 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_prepend(self.obj, + <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 + + property items: + """ Get the list of items in the ctxpopup widget. + + This list is not to be modified in any way and is only valid until + the object internal items list is changed. It should be fetched again + with another call to this function when changes happen. + + :type: list of :py:class:`CtxpopupItem` + + ..versionadded:: 1.11 + + """ + def __get__(self): + return _object_item_list_to_python(elm_ctxpopup_items_get(self.obj)) + + def items_get(self): + return _object_item_list_to_python(elm_ctxpopup_items_get(self.obj)) + + property first_item: + """ The first item of the Ctxpopup. + + :type: :py:class:`CtxpopupItem` + + ..versionadded:: 1.11 + + """ + def __get__(self): + return _object_item_to_python(elm_ctxpopup_first_item_get(self.obj)) + + def first_item_get(self): + return _object_item_to_python(elm_ctxpopup_first_item_get(self.obj)) + + property last_item: + """ The last item of the Ctxpopup. + + :type: :py:class:`CtxpopupItem` + + ..versionadded:: 1.11 + + """ + def __get__(self): + return _object_item_to_python(elm_ctxpopup_last_item_get(self.obj)) + + def last_item_get(self): + return _object_item_to_python(elm_ctxpopup_last_item_get(self.obj)) + property direction_priority: """The direction priority order of a ctxpopup. diff --git a/examples/elementary/test_ctxpopup.py b/examples/elementary/test_ctxpopup.py index ce1120f..af874a0 100644 --- a/examples/elementary/test_ctxpopup.py +++ b/examples/elementary/test_ctxpopup.py @@ -59,10 +59,33 @@ def cb_item1(li, item): it = item_new(cp, "Sate date and time", "clock") it.disabled = True + ic = Icon(cp, standard="home", resizable=(False,False)) + cp.item_prepend("Prepended item", ic, cb_items) + (x, y) = li.evas.pointer_canvas_xy_get() cp.move(x, y) cp.show() + print("\n### Testing items getters 1") + for it in cp.items: + print("ITEM: " + it.text) + + print("\n### Testing items getters 2") + print("FIRST ITEM: " + cp.first_item.text) + print("LAST ITEM: " + cp.last_item.text) + + print("\n### Testing items getters 3") + it = cp.first_item + while it: + print("ITEM: " + it.text) + it = it.next + + print("\n### Testing items getters 4") + it = cp.last_item + while it: + print("ITEM: " + it.text) + it = it.prev + def cb_item2(li, item): cp = Ctxpopup(li) it = item_new(cp, "", "home") --