Elementary: New dispatcher for object item selection callbacks.

This is cleaner and allows us to use properties_from_kwargs,
and should have better forward compatibility by allowing more
positional arguments to be added as *args is now unused.
This commit is contained in:
Kai Huuhko 2013-11-14 12:31:41 +02:00
parent ad630770b5
commit 2231ce4f13
28 changed files with 696 additions and 212 deletions

3
TODO
View File

@ -41,9 +41,6 @@ Elementary
* Fix Theme API, add a test
* ObjectItem.data changed to dict (like in Eo). Find out what this affects
and document it.
* Item add methods (constructors) should be changed to have cb_data in a
single argument, not args, kwargs. The callback signatures need to be
changed as well.
* Get rid of enums in __init__.py
* Automate compilation of the example edje files.

View File

@ -86,9 +86,8 @@ Actionslider positions
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String
from libc.string cimport const_char
from efl.eo cimport _object_mapping_register
from efl.utils.conversions cimport _ctouni
@ -103,6 +102,10 @@ ELM_ACTIONSLIDER_CENTER = enums.ELM_ACTIONSLIDER_CENTER
ELM_ACTIONSLIDER_RIGHT = enums.ELM_ACTIONSLIDER_RIGHT
ELM_ACTIONSLIDER_ALL = enums.ELM_ACTIONSLIDER_ALL
def _cb_string_conv(long addr):
cdef const_char *s = <const_char *>addr
return _ctouni(s) if s is not NULL else None
cdef class Actionslider(LayoutClass):
"""This is the class that actually implements the widget."""

View File

@ -1,11 +0,0 @@
from libc.string cimport const_char
from object_item cimport Elm_Object_Item
from object_item cimport _object_item_to_python
def _cb_string_conv(long addr):
cdef const_char *s = <const_char *>addr
return _ctouni(s) if s is not NULL else None
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)

View File

@ -67,15 +67,12 @@ Colorselector modes
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String, Py_DECREF
from efl.eo cimport _object_mapping_register
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object_item cimport ObjectItem
from object_item cimport ObjectItem, _object_item_to_python
from layout_class cimport LayoutClass
cimport enums
@ -84,16 +81,31 @@ ELM_COLORSELECTOR_PALETTE = enums.ELM_COLORSELECTOR_PALETTE
ELM_COLORSELECTOR_COMPONENTS = enums.ELM_COLORSELECTOR_COMPONENTS
ELM_COLORSELECTOR_BOTH = enums.ELM_COLORSELECTOR_BOTH
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef class ColorselectorPaletteItem(ObjectItem):
cdef int r, g, b, a
"""An item for the :py:class:`Colorselector` widget."""
def __init__(self, evasObject cs, r, g, b, a):
cdef Elm_Object_Item *item = elm_colorselector_palette_color_add(cs.obj, r, g, b, a)
def __init__(self, int r, int g, int b, int a, *args, **kwargs):
self.r, self.g, self.b, self.a = r, g, b, a
self.args, self.kwargs = args, kwargs
def add_to(self, evasObject cs):
cdef Elm_Object_Item *item
item = elm_colorselector_palette_color_add(
cs.obj, self.r, self.g, self.b, self.a)
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
property color:
"""The palette items color.
@ -182,7 +194,7 @@ cdef class Colorselector(LayoutClass):
:rtype: :py:class:`ColorselectorPaletteItem`
"""
return ColorselectorPaletteItem(self, r, g, b, a)
return ColorselectorPaletteItem(r, g, b, a).add_to(self)
def palette_clear(self):
"""palette_clear()

View File

@ -93,7 +93,8 @@ from efl.eo cimport _object_mapping_register, object_from_instance
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from layout_class cimport LayoutClass
from object_item cimport ObjectItem, _object_item_callback
from object_item cimport ObjectItem, _object_item_callback, \
_object_item_callback2
cimport enums
@ -109,7 +110,8 @@ cdef class CtxpopupItem(ObjectItem):
bytes label
evasObject icon
def __init__(self, label = None, evasObject icon = None, callback = None, *args, **kargs):
def __init__(self, label = None, evasObject icon = None,
callback = None, cb_data = None, *args, **kargs):
"""
.. 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
@ -133,6 +135,7 @@ cdef class CtxpopupItem(ObjectItem):
self.label = label
self.icon = icon
self.cb_func = callback
self.cb_data = cb_data
self.args = args
self.kwargs = kargs
@ -157,7 +160,7 @@ cdef class CtxpopupItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_ctxpopup_item_append(ctxpopup.obj,
<const_char *>self.label if self.label is not None else NULL,
@ -166,9 +169,11 @@ cdef class CtxpopupItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
cdef class Ctxpopup(LayoutClass):
@ -216,7 +221,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):
"""item_append(unicode label, evas.Object icon, func, *args, **kwargs) -> CtxpopupItem
A constructor for a :py:class:`CtxpopupItem`.
@ -224,7 +230,29 @@ cdef class Ctxpopup(LayoutClass):
:see: :py:func:`CtxpopupItem.append_to`
"""
return CtxpopupItem(label, icon, func, *args, **kwargs).append_to(self)
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_append(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 direction_priority:
"""The direction priority order of a ctxpopup.

View File

@ -71,10 +71,6 @@ using multiple inheritance, for example::
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String, Py_DECREF
from efl.eo cimport _object_mapping_register
@ -82,12 +78,16 @@ from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object cimport Object
from object_item cimport ObjectItem, _object_item_callback, \
_object_item_to_python, _object_item_list_to_python
_object_item_to_python, _object_item_list_to_python, _object_item_callback2
from efl.utils.deprecated cimport DEPRECATED
from scroller cimport elm_scroller_policy_get, elm_scroller_policy_set, \
elm_scroller_bounce_get, elm_scroller_bounce_set, Elm_Scroller_Policy
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef class DiskselectorItem(ObjectItem):
"""An item for the Diskselector widget.
@ -126,7 +126,8 @@ cdef class DiskselectorItem(ObjectItem):
bytes label
evasObject icon
def __init__(self, label, evasObject icon=None, callback=None, *args, **kargs):
def __init__(self, label=None, evasObject icon=None, callback=None,
cb_data=None, *args, **kargs):
"""
:param label: The label of the diskselector item.
@ -147,6 +148,7 @@ cdef class DiskselectorItem(ObjectItem):
self.label = label
self.icon = icon
self.cb_func = callback
self.cb_data = cb_data
self.args = args
self.kwargs = kargs
@ -162,7 +164,7 @@ cdef class DiskselectorItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_diskselector_item_append(diskselector.obj,
<const_char *>self.label if self.label is not None else NULL,
@ -171,6 +173,7 @@ cdef class DiskselectorItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -343,7 +346,8 @@ cdef class Diskselector(Object):
def __get__(self):
return _object_item_list_to_python(elm_diskselector_items_get(self.obj))
def item_append(self, label, evasObject icon = None, callback = None, *args, **kwargs):
def item_append(self, label, evasObject icon = None, callback = None,
*args, **kwargs):
"""item_append(self, unicode label, evas.Object icon = None, callback = None, *args, **kwargs) -> DiskselectorItem
A constructor for :py:class:`DiskselectorItem`
@ -351,7 +355,29 @@ cdef class Diskselector(Object):
:see: :py:func`DiskselectorItem.append_to`
"""
return DiskselectorItem(label, icon, callback, *args, **kwargs).append_to(self)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
DiskselectorItem ret = DiskselectorItem.__new__(DiskselectorItem)
if callback is not None and callable(callback):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_diskselector_item_append(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 = callback
ret.args = args
ret.kwargs = kwargs
return ret
else:
return None
property selected_item:
"""Get the selected item.

View File

@ -77,8 +77,6 @@ Fileselector modes
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String
from efl.eo cimport _object_mapping_register
@ -91,6 +89,10 @@ cimport enums
ELM_FILESELECTOR_LIST = enums.ELM_FILESELECTOR_LIST
ELM_FILESELECTOR_GRID = enums.ELM_FILESELECTOR_GRID
def _cb_string_conv(long addr):
cdef const_char *s = <const_char *>addr
return _ctouni(s) if s is not NULL else None
cdef class Fileselector(LayoutClass):
"""This is the class that actually implements the widget."""

View File

@ -60,9 +60,6 @@ for are:
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String
from efl.eo cimport _object_mapping_register
@ -71,6 +68,10 @@ from efl.evas cimport Object as evasObject
cimport enums
def _cb_string_conv(long addr):
cdef const_char *s = <const_char *>addr
return _ctouni(s) if s is not NULL else None
cdef class FileselectorButton(Button):
"""This is the class that actually implements the widget."""

View File

@ -74,9 +74,6 @@ are:
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String
from efl.eo cimport _object_mapping_register
@ -86,6 +83,10 @@ from object cimport Object
cimport enums
def _cb_string_conv(long addr):
cdef const_char *s = <const_char *>addr
return _ctouni(s) if s is not NULL else None
cdef class FileselectorEntry(Object):
"""This is the class that actually implements the widget."""

View File

@ -59,16 +59,18 @@ Default text parts of the flipselector items that you can use for are:
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String
from efl.eo cimport _object_mapping_register
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object cimport Object
from object_item cimport _object_item_to_python, _object_item_callback, _object_item_list_to_python
from object_item cimport _object_item_to_python, _object_item_callback, \
_object_item_list_to_python, _object_item_callback2
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef class FlipSelectorItem(ObjectItem):
@ -88,7 +90,8 @@ cdef class FlipSelectorItem(ObjectItem):
cdef:
bytes label
def __init__(self, label = None, callback = None, *args, **kwargs):
def __init__(self, label = None, callback = None, cb_data = None,
*args, **kwargs):
"""
The widget's list of labels to show will be appended with the
@ -133,7 +136,7 @@ cdef class FlipSelectorItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_flipselector_item_append(flipselector.obj,
<const_char *>self.label if self.label is not None else NULL,
@ -141,9 +144,10 @@ cdef class FlipSelectorItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
return
return None
def prepend_to(self, FlipSelector flipselector not None):
"""prepend_to(FlipSelector flipselector) -> FlipSelectorItem
@ -161,7 +165,7 @@ cdef class FlipSelectorItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_flipselector_item_prepend(flipselector.obj,
<const_char *>self.label if self.label is not None else NULL,
@ -169,6 +173,7 @@ cdef class FlipSelectorItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
return
@ -270,7 +275,28 @@ cdef class FlipSelector(Object):
:see: :py:func:`FlipSelectorItem.append_to`
"""
return FlipSelectorItem(label, callback, *args, **kwargs).append_to(self)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
FlipSelectorItem ret = FlipSelectorItem.__new__(FlipSelectorItem)
if callback is not None and callable(callback):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_flipselector_item_append(self.obj,
<const_char *>label if label is not None else NULL,
cb, <void*>ret)
if item != NULL:
ret._set_obj(item)
ret.cb_func = callback
ret.args = args
ret.kwargs = kwargs
return ret
else:
return None
def item_prepend(self, label = None, callback = None, *args, **kwargs):
"""item_prepend(unicode label = None, callback = None, *args, **kwargs) -> FlipSelectorItem
@ -280,7 +306,28 @@ cdef class FlipSelector(Object):
:see: :py:func:`FlipSelectorItem.prepend_to`
"""
return FlipSelectorItem(label, callback, *args, **kwargs).prepend_to(self)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
FlipSelectorItem ret = FlipSelectorItem.__new__(FlipSelectorItem)
if callback is not None and callable(callback):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_flipselector_item_prepend(self.obj,
<const_char *>label if label is not None else NULL,
cb, <void*>ret)
if item != NULL:
ret._set_obj(item)
ret.cb_func = callback
ret.args = args
ret.kwargs = kwargs
return ret
else:
return None
property items:
"""Get the internal list of items in a given flip selector widget.

View File

@ -123,3 +123,5 @@ cdef extern from "Elementary.h":
# Debug
void elm_object_tree_dump(const_Evas_Object *top)
void elm_object_tree_dot_dump(const_Evas_Object *top, const_char *file)
cdef int PY_EFL_ELM_LOG_DOMAIN

View File

@ -276,7 +276,6 @@ Items' scroll to types
"""
include "callback_conversions.pxi"
include "tooltips.pxi"
from libc.string cimport strdup
@ -303,6 +302,10 @@ ELM_GENLIST_ITEM_SCROLLTO_IN = enums.ELM_GENLIST_ITEM_SCROLLTO_IN
ELM_GENLIST_ITEM_SCROLLTO_TOP = enums.ELM_GENLIST_ITEM_SCROLLTO_TOP
ELM_GENLIST_ITEM_SCROLLTO_MIDDLE = enums.ELM_GENLIST_ITEM_SCROLLTO_MIDDLE
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef char *_py_elm_gengrid_item_text_get(void *data, Evas_Object *obj, const_char *part) with gil:
cdef GengridItem item = <object>data
cdef GengridItemClass itc = item.cls

View File

@ -504,8 +504,6 @@ Selection modes
"""
include "callback_conversions.pxi"
include "tooltips.pxi"
from cpython cimport PyUnicode_AsUTF8String, Py_DECREF, Py_INCREF
@ -522,6 +520,11 @@ from object_item cimport ObjectItem, _object_item_to_python, \
elm_object_item_widget_get, _object_item_from_python, \
_object_item_list_to_python, elm_object_item_data_get
from general cimport strdup
from general cimport PY_EFL_ELM_LOG_DOMAIN
from efl.eina cimport EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, EINA_LOG_DOM_WARN, \
EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT
cimport enums
import traceback
@ -566,6 +569,9 @@ ELM_SEL_TYPE_SECONDARY = enums.ELM_SEL_TYPE_SECONDARY
ELM_SEL_TYPE_XDND = enums.ELM_SEL_TYPE_XDND
ELM_SEL_TYPE_CLIPBOARD = enums.ELM_SEL_TYPE_CLIPBOARD
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef char *_py_elm_genlist_item_text_get(void *data, Evas_Object *obj, const_char *part) with gil:
cdef:
@ -650,7 +656,6 @@ cdef void _py_elm_genlist_object_item_del(void *data, Evas_Object *obj) with gil
traceback.print_exc()
item._unset_obj()
Py_DECREF(item)
cdef void _py_elm_genlist_item_func(void *data, Evas_Object *obj, void *event_info) with gil:
cdef GenlistItem item = <object>data

View File

@ -69,9 +69,11 @@ cdef class GenlistItem(ObjectItem):
Py_INCREF(self)
return 1
cdef void _unset_obj(self):
cdef int _unset_obj(self) except 0:
assert self.item != NULL, "Object must wrap something"
self.item = NULL
Py_DECREF(self)
return 1
def __repr__(self):
return ("<%s(%#x, refcount=%d, Elm_Object_Item=%#x, "

View File

@ -1,6 +1,5 @@
from efl.evas cimport Eina_Bool, Eina_List, Evas_Object, Evas_Smart_Cb
from button cimport Button
from object_item cimport Elm_Object_Item, ObjectItem
from object_item cimport Elm_Object_Item
from enums cimport Elm_Icon_Type
from libc.string cimport const_char

View File

@ -72,14 +72,14 @@ Icon types
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String, Py_DECREF
from efl.eo cimport _object_mapping_register, object_from_instance
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object_item cimport _object_item_callback, _object_item_list_to_python
from object_item cimport ObjectItem, _object_item_callback, \
_object_item_list_to_python, _object_item_to_python, _object_item_callback2
from button cimport Button
cimport enums
@ -87,6 +87,10 @@ ELM_ICON_NONE = enums.ELM_ICON_NONE
ELM_ICON_FILE = enums.ELM_ICON_FILE
ELM_ICON_STANDARD = enums.ELM_ICON_STANDARD
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef class HoverselItem(ObjectItem):
"""
@ -99,7 +103,8 @@ cdef class HoverselItem(ObjectItem):
Elm_Icon_Type icon_type
def __init__(self, label = None, icon_file = None,
icon_type = ELM_ICON_NONE, callback = None, *args, **kargs):
icon_type = ELM_ICON_NONE, callback = None, cb_data = None,
*args, **kargs):
"""For more information on what ``icon_file`` and ``icon_type`` are,
see :py:class:`elementary.icon.Icon`.
@ -126,6 +131,7 @@ cdef class HoverselItem(ObjectItem):
raise TypeError("callback is not callable")
self.cb_func = callback
self.cb_data = cb_data
self.args = args
self.kwargs = kargs
@ -146,9 +152,9 @@ cdef class HoverselItem(ObjectItem):
"""
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_hoversel_item_add( hoversel.obj,
item = elm_hoversel_item_add(hoversel.obj,
<const_char *>self.label if self.label is not None else NULL,
<const_char *>self.icon_file if self.icon_file is not None else NULL,
self.icon_type,
@ -156,9 +162,11 @@ cdef class HoverselItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
property icon:
"""This sets the icon for the given hoversel item.
@ -328,8 +336,33 @@ cdef class Hoversel(Button):
def items_get(self):
return _object_item_list_to_python(elm_hoversel_items_get(self.obj))
def item_add(self, label = None, icon_file = None, icon_type = ELM_ICON_NONE, callback = None, *args, **kwargs):
return HoverselItem(label, icon_file, icon_type, callback, *args, **kwargs).add_to(self)
def item_add(self, label = None, icon_file = None,
icon_type = ELM_ICON_NONE, callback = None, *args, **kwargs):
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
HoverselItem ret = HoverselItem.__new__(HoverselItem)
if callback is not None and callable(callback):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
if isinstance(icon_file, unicode): icon_file = PyUnicode_AsUTF8String(icon_file)
item = elm_hoversel_item_add(self.obj,
<const_char *>label if label is not None else NULL,
<const_char *>icon_file if icon_file is not None else NULL,
icon_type,
cb, <void*>ret)
if item != NULL:
ret._set_obj(item)
ret.cb_func = callback
ret.args = args
ret.kwargs = kwargs
return ret
else:
return None
def callback_clicked_add(self, func, *args, **kwargs):
"""The user clicked the hoversel button and popped up the sel."""

View File

@ -94,8 +94,6 @@ Image manipulation types
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String
from efl.eo cimport _object_mapping_register, object_from_instance
@ -113,6 +111,9 @@ ELM_IMAGE_FLIP_VERTICAL = enums.ELM_IMAGE_FLIP_VERTICAL
ELM_IMAGE_FLIP_TRANSPOSE = enums.ELM_IMAGE_FLIP_TRANSPOSE
ELM_IMAGE_FLIP_TRANSVERSE = enums.ELM_IMAGE_FLIP_TRANSVERSE
def _cb_string_conv(long addr):
cdef const_char *s = <const_char *>addr
return _ctouni(s) if s is not NULL else None
class ImageProgressInfo(object):
"""

View File

@ -66,9 +66,6 @@ reported.
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String, Py_DECREF
from efl.eo cimport _object_mapping_register
@ -76,10 +73,13 @@ from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from layout_class cimport LayoutClass
from object_item cimport _object_item_callback, _object_item_to_python, \
elm_object_item_data_get
elm_object_item_data_get, _object_item_callback2
import traceback
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef int _index_compare_func(const_void *data1, const_void *data2) with gil:
"""Comparison by IndexItem objects"""
@ -154,7 +154,8 @@ cdef class IndexItem(ObjectItem):
bytes letter
object compare_func, data_compare_func
def __init__(self, letter, callback = None, *args, **kwargs):
def __init__(self, letter, callback = None, cb_data = None,
*args, **kwargs):
if callback is not None:
if not callable(callback):
raise TypeError("callback is not callable")
@ -163,6 +164,7 @@ cdef class IndexItem(ObjectItem):
self.letter = letter
self.cb_func = callback
self.cb_data = cb_data
self.args = args
self.kwargs = kwargs
@ -178,7 +180,7 @@ cdef class IndexItem(ObjectItem):
cdef Elm_Object_Item *item
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_index_item_append(index.obj,
<const_char *>self.letter if self.letter is not None else NULL,
@ -186,9 +188,11 @@ cdef class IndexItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
def prepend_to(self, Index index not None):
"""
@ -202,7 +206,7 @@ cdef class IndexItem(ObjectItem):
cdef Elm_Object_Item *item
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_index_item_prepend(index.obj,
<const_char *>self.letter if self.letter is not None else NULL,
@ -210,9 +214,11 @@ cdef class IndexItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
def insert_after(self, IndexItem after not None):
"""
@ -227,7 +233,7 @@ cdef class IndexItem(ObjectItem):
cdef Index index = after.widget
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_index_item_insert_after(index.obj, after.item,
<const_char *>self.letter if self.letter is not None else NULL,
@ -235,9 +241,11 @@ cdef class IndexItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
def insert_before(self, IndexItem before not None):
"""
@ -252,7 +260,7 @@ cdef class IndexItem(ObjectItem):
cdef Index index = before.widget
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_index_item_insert_before(index.obj, before.item,
<const_char *>self.letter if self.letter is not None else NULL,
@ -260,9 +268,11 @@ cdef class IndexItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
def insert_sorted(self, Index index not None, compare_func, data_compare_func = None):
"""
@ -288,7 +298,7 @@ cdef class IndexItem(ObjectItem):
cdef Elm_Object_Item *item
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
self.compare_func = compare_func
self.data_compare_func = data_compare_func
@ -299,9 +309,11 @@ cdef class IndexItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
property selected:
"""Set the selected state of an item.

View File

@ -158,18 +158,14 @@ Selection modes
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String, Py_DECREF
from efl.eo cimport _object_mapping_register, object_from_instance, PY_REFCOUNT
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object cimport Object
from object_item cimport _object_item_callback, \
_object_item_to_python, \
_object_item_list_to_python
from object_item cimport _object_item_callback, _object_item_callback2, \
_object_item_to_python, _object_item_list_to_python
from efl.utils.deprecated cimport DEPRECATED
from scroller cimport elm_scroller_policy_get, elm_scroller_policy_set, \
@ -192,6 +188,9 @@ ELM_SCROLLER_POLICY_AUTO = enums.ELM_SCROLLER_POLICY_AUTO
ELM_SCROLLER_POLICY_ON = enums.ELM_SCROLLER_POLICY_ON
ELM_SCROLLER_POLICY_OFF = enums.ELM_SCROLLER_POLICY_OFF
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef class ListItem(ObjectItem):
@ -201,19 +200,18 @@ cdef class ListItem(ObjectItem):
Evas_Object *icon_obj, *end_obj
def __init__(self, label = None, evasObject icon = None,
evasObject end = None, callback = None, *args, **kargs):
evasObject end = None, callback = None, cb_data = None, *args, **kargs):
"""Create a new ListItem
:param label: The label of the list item.
:type label: string
:param string label: The label of the list item.
:param icon: The icon object to use for the left side of the item. An
icon can be any Evas object, but usually it is an :py:class:`Icon`.
:type icon: :py:class:`evas.object.Object`
:param end: The icon object to use for the right side of the item. An
icon can be any Evas object.
:type end: :py:class:`evas.object.Object`
:param callback: The function to call when the item is clicked.
:type callback: function
:param callable callback: The function to call when the item is clicked.
:param cb_data: An object associated with the callback.
"""
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
@ -229,23 +227,24 @@ cdef class ListItem(ObjectItem):
raise TypeError("callback is not callable")
self.cb_func = callback
self.cb_data = cb_data
self.args = args
self.kwargs = kargs
def __str__(self):
return ("%s(label=%r, icon=%s, end=%s, "
"callback=%r, args=%r, kargs=%s)") % \
(self.__class__.__name__, self.text_get(), bool(self.part_content_get("icon")),
bool(self.part_content_get("end")), self.cb_func, self.args, self.kwargs)
def __repr__(self):
return ("%s(%#x, refcount=%d, Elm_Object_Item=%#x, "
return ("<%s at %#x (refcount=%d, item=%#x, "
"label=%r, icon=%s, end=%s, "
"callback=%r, args=%r, kargs=%s)") % \
(self.__class__.__name__, <unsigned long><void *>self,
PY_REFCOUNT(self), <unsigned long><void *>self.item,
self.text_get(), bool(self.part_content_get("icon")),
bool(self.part_content_get("end")), self.cb_func, self.args, self.kwargs)
"callback=%r, cb_data=%r, "
"args=%r, kargs=%r)>") % (
type(self).__name__,
<unsigned long><void *>self,
PY_REFCOUNT(self),
<unsigned long><void *>self.item,
self.text,
getattr(self.part_content_get("icon"), "file", None),
getattr(self.part_content_get("end"), "file", None),
self.cb_func, self.cb_data,
self.args, self.kwargs)
def append_to(self, List list):
"""append_to(List list)
@ -286,7 +285,7 @@ cdef class ListItem(ObjectItem):
cdef Elm_Object_Item *item
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_list_item_append(list.obj,
<const_char *>self.label if self.label is not None else NULL,
@ -295,9 +294,11 @@ cdef class ListItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
def prepend_to(self, List list):
"""prepend_to(List list)
@ -321,7 +322,7 @@ cdef class ListItem(ObjectItem):
cdef Elm_Object_Item *item
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_list_item_prepend( list.obj,
<const_char *>self.label if self.label is not None else NULL,
@ -330,9 +331,11 @@ cdef class ListItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
def insert_before(self, ListItem before):
"""insert_before(ListItem before)
@ -356,7 +359,7 @@ cdef class ListItem(ObjectItem):
cdef Elm_Object_Item *item
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
cdef List list = before.widget
item = elm_list_item_insert_before( list.obj,
@ -367,9 +370,11 @@ cdef class ListItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
def insert_after(self, ListItem after):
"""insert_after(ListItem after)
@ -393,7 +398,7 @@ cdef class ListItem(ObjectItem):
cdef Elm_Object_Item *item
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
cdef List list = after.widget
item = elm_list_item_insert_after( list.obj,
@ -404,50 +409,53 @@ cdef class ListItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
#def sorted_insert_to(self, List list, cmp_func=None):
"""Insert a new item into the sorted list object.
# TODO:
# def sorted_insert_to(self, List list, cmp_func=None):
# """Insert a new item into the sorted list object.
.. seealso::
:py:func:`append_to()`
:py:attr:`List.select_mode`
:py:func:`efl.elementary.object_item.ObjectItem.delete()`
:py:func:`List.clear()`
:py:class:`Icon <efl.elementary.icon.Icon>`
# .. seealso::
# :py:func:`append_to()`
# :py:attr:`List.select_mode`
# :py:func:`efl.elementary.object_item.ObjectItem.delete()`
# :py:func:`List.clear()`
# :py:class:`Icon <efl.elementary.icon.Icon>`
.. note:: This function inserts values into a list object assuming
it was sorted and the result will be sorted.
# .. note:: This function inserts values into a list object assuming
# it was sorted and the result will be sorted.
:param cmp_func: The comparing function to be used to sort list
items **by :py:class:`ListItem` handles**. This
function will receive two items and compare them,
returning a non-negative integer if the second item
should be place after the first, or negative value
if should be placed before.
:type cmp_func: function
# :param cmp_func: The comparing function to be used to sort list
# items **by :py:class:`ListItem` handles**. This
# function will receive two items and compare them,
# returning a non-negative integer if the second item
# should be place after the first, or negative value
# if should be placed before.
# :type cmp_func: function
:return: The created item or ``None`` upon failure.
:rtype: :py:class:`ListItem`
# :return: The created item or ``None`` upon failure.
# :rtype: :py:class:`ListItem`
"""
#cdef Elm_Object_Item *item
# """
# cdef Elm_Object_Item *item
#item = elm_list_item_sorted_insert(list.obj,
#<const_char *>self.label if self.label is not None else NULL,
#icon_obj,
#end_obj,
#cb,
#<void*>self,
#cmp_f)
# item = elm_list_item_sorted_insert(list.obj,
# <const_char *>self.label if self.label is not None else NULL,
# icon_obj,
# end_obj,
# cb,
# <void*>self,
# cmp_f)
#if item != NULL:
#self._set_obj(item)
#return self
#else:
#Py_DECREF(self)
# if item != NULL:
# self._set_obj(item)
# return self
# else:
# Py_DECREF(self)
property selected:
"""The selected state of an item.
@ -697,21 +705,129 @@ cdef class List(Object):
def select_mode_get(self):
return elm_list_select_mode_get(self.obj)
def item_append(self, label, evasObject icon = None,
evasObject end = None, callback = None, *args, **kargs):
return ListItem(label, icon, end, callback, *args, **kargs).append_to(self)
def item_append(self, label = None, evasObject icon = None,
evasObject end = None, callback = None, *args, **kargs):
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
ListItem ret = ListItem.__new__(ListItem)
def item_prepend(self, label, evasObject icon = None,
evasObject end = None, callback = None, *args, **kargs):
return ListItem(label, icon, end, callback, *args, **kargs).prepend_to(self)
if callback is not None:
if not callable(callback):
raise TypeError
ret.cb_func = callback
def item_insert_before(self, ListItem before, label, evasObject icon = None,
evasObject end = None, callback = None, *args, **kargs):
return ListItem(label, icon, end, callback, *args, **kargs).insert_before(before)
cb = _object_item_callback
def item_insert_after(self, ListItem after, label, evasObject icon = None,
evasObject end = None, callback = None, *args, **kargs):
return ListItem(label, icon, end, callback, *args, **kargs).insert_after(after)
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_list_item_append(self.obj,
<const_char *>label if label is not None else NULL,
icon.obj if icon is not None else NULL,
end.obj if end is not None else NULL,
cb, <void*>self)
if item != NULL:
ret._set_obj(item)
ret.args = args
ret.kwargs = kargs
return ret
else:
return None
def item_prepend(self, label = None, evasObject icon = None,
evasObject end = None, callback = None, *args, **kargs):
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
ListItem ret = ListItem.__new__(ListItem)
if callback is not None:
if not callable(callback):
raise TypeError
ret.cb_func = callback
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_list_item_prepend(self.obj,
<const_char *>label if label is not None else NULL,
icon.obj if icon is not None else NULL,
end.obj if end is not None else NULL,
cb, <void*>self)
if item != NULL:
ret._set_obj(item)
ret.args = args
ret.kwargs = kargs
return ret
else:
return None
def item_insert_before(self, ListItem before not None, label = None,
evasObject icon = None, evasObject end = None, callback = None,
*args, **kargs):
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
ListItem ret = ListItem.__new__(ListItem)
if callback is not None:
if not callable(callback):
raise TypeError
ret.cb_func = callback
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_list_item_insert_before(self.obj,
before.item,
<const_char *>label if label is not None else NULL,
icon.obj if icon is not None else NULL,
end.obj if end is not None else NULL,
cb, <void*>self)
if item != NULL:
ret._set_obj(item)
ret.args = args
ret.kwargs = kargs
return ret
else:
return None
def item_insert_after(self, ListItem after not None, label = None,
evasObject icon = None, evasObject end = None, callback = None,
*args, **kargs):
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
ListItem ret = ListItem.__new__(ListItem)
if callback is not None:
if not callable(callback):
raise TypeError
ret.cb_func = callback
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_list_item_insert_after(self.obj,
after.item,
<const_char *>label if label is not None else NULL,
icon.obj if icon is not None else NULL,
end.obj if end is not None else NULL,
cb, <void*>self)
if item != NULL:
ret._set_obj(item)
ret.args = args
ret.kwargs = kargs
return ret
else:
return None
def clear(self):
"""clear()

View File

@ -49,9 +49,8 @@ from cpython cimport PyUnicode_AsUTF8String, Py_DECREF
from efl.eo cimport _object_mapping_register, object_from_instance
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object_item cimport _object_item_callback, \
_object_item_list_to_python, \
_object_item_to_python
from object_item cimport _object_item_callback, _object_item_list_to_python, \
_object_item_to_python, _object_item_callback2
cdef class MenuItem(ObjectItem):
@ -62,7 +61,7 @@ cdef class MenuItem(ObjectItem):
bytes label, icon
def __init__(self, MenuItem parent = None, label = None, icon = None,
callback = None, *args, **kargs):
callback = None, cb_data = None, *args, **kargs):
if callback is not None:
if not callable(callback):
@ -74,6 +73,7 @@ cdef class MenuItem(ObjectItem):
self.label = label
self.icon = icon
self.cb_func = callback
self.cb_data = cb_data
self.args = args
self.kwargs = kargs
@ -82,7 +82,7 @@ cdef class MenuItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_menu_item_add(menu.obj,
self.parent.item if self.parent is not None else NULL,
@ -92,6 +92,7 @@ cdef class MenuItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -350,17 +351,17 @@ cdef class Menu(Object):
def items_get(self):
return _object_item_list_to_python(elm_menu_items_get(self.obj))
def item_add(self, parent = None, label = None, icon = None, callback = None, *args, **kwargs):
def item_add(self, MenuItem parent = None, label = None,
icon = None, callback = None, *args, **kwargs):
"""item_add(parent = None, label = None, icon = None, callback = None, *args, **kwargs) -> MenuItem
Add an item at the end of the given menu widget
:param parent: The parent menu item (optional)
:type parent: :py:class:`Object`
:param icon: An icon display on the item. The icon will be destroyed
:param string icon: An icon display on the item. The icon will be destroyed
by the menu.
:type icon: string
:param label: The label of the item.
:param string label: The label of the item.
:type label: string
:param callback: Function called when the user select the item.
:type callback: function
@ -369,7 +370,31 @@ cdef class Menu(Object):
:rtype: :py:class:`MenuItem`
"""
return MenuItem(parent, label, icon, callback, *args, **kwargs).add_to(self)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
MenuItem ret = MenuItem.__new__(MenuItem)
if callback is not None and callable(callback):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
if isinstance(icon, unicode): icon = PyUnicode_AsUTF8String(icon)
item = elm_menu_item_add(self.obj,
parent.item if parent is not None else NULL,
<const_char *>icon if icon is not None else NULL,
<const_char *>label if label is not None else NULL,
cb, <void*>ret)
if item != NULL:
ret._set_obj(item)
ret.cb_func = callback
ret.args = args
ret.kwargs = kwargs
return ret
else:
return None
def item_separator_add(self, parent = None):
"""item_separator_add(parent = None) -> MenuSeparatorItem

View File

@ -70,9 +70,8 @@ from libc.stdlib cimport free
from libc.string cimport strdup
from object cimport Object
import traceback
from object_item cimport _object_item_callback, \
_object_item_to_python, \
_object_item_list_to_python
from object_item cimport _object_item_callback, _object_item_callback2, \
_object_item_to_python, _object_item_list_to_python
cdef Eina_Bool _multibuttonentry_filter_callback(Evas_Object *obj, \
const_char *item_label, void *item_data, void *data) with gil:
@ -97,7 +96,8 @@ cdef class MultiButtonEntryItem(ObjectItem):
cdef:
bytes label
def __init__(self, label = None, callback = None, *args, **kargs):
def __init__(self, label = None, callback = None, cb_data = None,
*args, **kargs):
if callback:
if not callable(callback):
@ -106,6 +106,7 @@ cdef class MultiButtonEntryItem(ObjectItem):
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
self.label = label
self.cb_func = callback
self.cb_data = cb_data
self.args = args
self.kwargs = kargs
@ -114,7 +115,7 @@ cdef class MultiButtonEntryItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_multibuttonentry_item_append(mbe.obj,
<const_char *>self.label if self.label is not None else NULL,
@ -122,6 +123,7 @@ cdef class MultiButtonEntryItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -131,7 +133,7 @@ cdef class MultiButtonEntryItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_multibuttonentry_item_prepend(mbe.obj,
<const_char *>self.label if self.label is not None else NULL,
@ -139,6 +141,7 @@ cdef class MultiButtonEntryItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -149,7 +152,7 @@ cdef class MultiButtonEntryItem(ObjectItem):
cdef MultiButtonEntry mbe = before.widget
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_multibuttonentry_item_insert_before(mbe.obj,
before.item,
@ -158,6 +161,7 @@ cdef class MultiButtonEntryItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -168,7 +172,7 @@ cdef class MultiButtonEntryItem(ObjectItem):
cdef MultiButtonEntry mbe = after.widget
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_multibuttonentry_item_insert_after(mbe.obj,
after.item,
@ -177,6 +181,7 @@ cdef class MultiButtonEntryItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -260,16 +265,102 @@ cdef class MultiButtonEntry(Object):
return bool(elm_multibuttonentry_expanded_get(self.obj))
def item_prepend(self, label, func = None, *args, **kwargs):
return MultiButtonEntryItem(label, func, *args, **kwargs).prepend_to(self)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
MultiButtonEntryItem ret = MultiButtonEntryItem.__new__(MultiButtonEntryItem)
if func is not None and callable(func):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_multibuttonentry_item_prepend(self.obj,
<const_char *>label if label 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_append(self, label, func = None, *args, **kwargs):
return MultiButtonEntryItem(label, func, *args, **kwargs).append_to(self)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
MultiButtonEntryItem ret = MultiButtonEntryItem.__new__(MultiButtonEntryItem)
if func is not None and callable(func):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_multibuttonentry_item_append(self.obj,
<const_char *>label if label 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_before(self, MultiButtonEntryItem before, label, func = None, *args, **kwargs):
return MultiButtonEntryItem(label, func, *args, **kwargs).insert_before(before)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
MultiButtonEntryItem ret = MultiButtonEntryItem.__new__(MultiButtonEntryItem)
if func is not None and callable(func):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_multibuttonentry_item_insert_before(self.obj,
before.item if before is not None else NULL,
<const_char *>label if label 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, MultiButtonEntryItem after, label, func = None, *args, **kwargs):
return MultiButtonEntryItem(label, func, *args, **kwargs).insert_after(after)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
MultiButtonEntryItem ret = MultiButtonEntryItem.__new__(MultiButtonEntryItem)
if func is not None and callable(func):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_multibuttonentry_item_insert_after(self.obj,
after.item if after is not None else NULL,
<const_char *>label if label 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:
def __get__(self):

View File

@ -62,12 +62,16 @@ cdef Elm_Object_Item * _object_item_from_python(ObjectItem item) except NULL
cdef _object_item_list_to_python(const_Eina_List *lst)
cdef void _object_item_del_cb(void *data, Evas_Object *o, void *event_info) with gil
cdef void _object_item_callback(void *data, Evas_Object *obj, void *event_info) with gil
cdef void _object_item_callback2(void *data, Evas_Object *obj, void *event_info) with gil
cdef class ObjectItem(object):
cdef:
Elm_Object_Item *item
object cb_func
object cb_data
tuple args
dict kwargs
readonly dict data
int _set_obj(self, Elm_Object_Item *item) except 0
cdef int _set_properties_from_keyword_args(self, dict kwargs) except 0

View File

@ -22,6 +22,10 @@ from efl.utils.conversions cimport _ctouni
from efl.utils.deprecated cimport DEPRECATED
from efl.evas cimport Object as evasObject
from efl.eina cimport EINA_LOG_DOM_DBG, EINA_LOG_DOM_INFO, EINA_LOG_DOM_WARN, \
EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT
from efl.elementary.general cimport PY_EFL_ELM_LOG_DOMAIN
include "tooltips.pxi"
# cdef void _tooltip_item_data_del_cb(void *data, Evas_Object *o, void *event_info) with gil:
@ -48,11 +52,9 @@ cdef _object_item_to_python(Elm_Object_Item *it):
data = elm_object_item_data_get(it)
if data == NULL:
#
# Attempt to create a dummy object item.
#
# TODO: Warn here that the item is not complete.
#
# Create a dummy object item.
EINA_LOG_DOM_WARN(PY_EFL_ELM_LOG_DOMAIN,
"Creating an incomplete ObjectItem.", NULL)
item = ObjectItem.__new__(ObjectItem)
item._set_obj(it)
else:
@ -79,6 +81,7 @@ cdef void _object_item_del_cb(void *data, Evas_Object *o, void *event_info) with
Py_DECREF(d)
cdef void _object_item_callback(void *data, Evas_Object *obj, void *event_info) with gil:
# This should be used with old style items
cdef ObjectItem item = <object>data
try:
o = object_from_instance(obj)
@ -86,6 +89,15 @@ cdef void _object_item_callback(void *data, Evas_Object *obj, void *event_info)
except:
traceback.print_exc()
cdef void _object_item_callback2(void *data, Evas_Object *obj, void *event_info) with gil:
# This should be used with new style items
cdef ObjectItem item = <object>data
try:
o = object_from_instance(obj)
item.cb_func(o, item, item.cb_data)
except:
traceback.print_exc()
cdef class ObjectItem(object):
"""
@ -138,6 +150,13 @@ cdef class ObjectItem(object):
repr(object_from_instance(elm_object_item_widget_get(self.item)))
)
cdef int _set_properties_from_keyword_args(self, dict kwargs) except 0:
cdef list cls_list = dir(self)
for k, v in kwargs.items():
assert k in cls_list, "%s has no attribute with the name %s." % (self, k)
setattr(self, k, v)
return 1
@DEPRECATED("1.8", "Use the data attribute (dict) instead.")
def data_get(self):
return (self.args, self.kwargs)

View File

@ -177,8 +177,8 @@ from efl.eo cimport _object_mapping_register, PY_REFCOUNT
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object cimport Object
from object_item cimport _object_item_callback, \
_object_item_to_python
from object_item cimport _object_item_callback, _object_item_callback2, \
_object_item_to_python
cimport enums
@ -217,7 +217,8 @@ cdef class PopupItem(ObjectItem):
bytes label
evasObject icon
def __init__(self, evasObject popup, label = None, evasObject icon = None, func = None, *args, **kwargs):
def __init__(self, evasObject popup, label = None, evasObject icon = None,
func = None, cb_data = None, *args, **kwargs):
if func is not None:
if not callable(func):
raise TypeError("func is not None or callable")
@ -226,6 +227,7 @@ cdef class PopupItem(ObjectItem):
self.label = label
self.icon = icon
self.cb_func = func
self.cb_data = cb_data
self.args = args
self.kwargs = kwargs
@ -234,7 +236,7 @@ cdef class PopupItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_popup_item_append(popup.obj,
<const_char *>self.label if not None else NULL,
@ -243,9 +245,11 @@ cdef class PopupItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
# FIXME: raise RuntimeError?
return None
def __str__(self):
@ -296,7 +300,29 @@ cdef class Popup(Object):
content area.
"""
return PopupItem(self, label, icon, func, *args, **kwargs)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
PopupItem ret = PopupItem.__new__(PopupItem)
if func is not None and callable(func):
cb = _object_item_callback
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_popup_item_append(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 content_text_wrap_type:
"""Sets the wrapping type of content text packed in content

View File

@ -53,8 +53,6 @@ Default text parts of the segment control items that you can use for are:
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String
from efl.eo cimport _object_mapping_register, object_from_instance
@ -64,6 +62,10 @@ from layout_class cimport LayoutClass
from object_item cimport _object_item_to_python
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef class SegmentControlItem(ObjectItem):
"""An item for :py:class:`SegmentControl`."""

View File

@ -78,8 +78,6 @@ This widget emits the following signals, besides the ones sent from
"""
include "callback_conversions.pxi"
from cpython cimport PyUnicode_AsUTF8String, Py_INCREF, Py_DECREF
from efl.eo cimport _object_mapping_register, object_from_instance, PY_REFCOUNT
@ -92,6 +90,10 @@ from layout_class cimport LayoutClass
import traceback
from object_item cimport _object_item_to_python, _object_item_list_to_python
def _cb_object_item_conv(long addr):
cdef Elm_Object_Item *it = <Elm_Object_Item *>addr
return _object_item_to_python(it)
cdef Evas_Object *_py_elm_slideshow_item_get(void *data, Evas_Object *obj) with gil:
cdef SlideshowItem item = <object>data
cdef evasObject icon

View File

@ -170,7 +170,8 @@ from efl.eo cimport _object_mapping_register, object_from_instance
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object cimport Object
from object_item cimport _object_item_callback, _object_item_to_python
from object_item cimport _object_item_callback, _object_item_to_python, \
_object_item_callback2
from menu cimport Menu
from efl.utils.deprecated cimport DEPRECATED
@ -227,7 +228,10 @@ cdef class ToolbarItemState(object):
cdef Elm_Toolbar_Item_State *state
cdef object params
def __init__(self, ToolbarItem it, icon = None, label = None, callback = None, *args, **kwargs):
# FIXME
def __init__(self, ToolbarItem it, icon = None, label = None,
callback = None, *args, **kwargs):
cdef Evas_Smart_Cb cb = NULL
if callback:
@ -262,7 +266,8 @@ cdef class ToolbarItem(ObjectItem):
object icon
Evas_Smart_Cb cb
def __init__(self, icon = None, label = None, callback = None, *args, **kwargs):
def __init__(self, icon = None, label = None, callback = None,
cb_data = None, *args, **kwargs):
"""
If a function is passed as argument, it will be called every time
@ -292,6 +297,7 @@ cdef class ToolbarItem(ObjectItem):
self.icon = icon
self.label = label
self.cb_func = callback
self.cb_data = cb_data
self.args = args
self.kwargs = kwargs
@ -318,7 +324,7 @@ cdef class ToolbarItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_toolbar_item_append(toolbar.obj,
<const_char *>self.icon if self.icon is not None else NULL,
@ -327,6 +333,7 @@ cdef class ToolbarItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -350,7 +357,7 @@ cdef class ToolbarItem(ObjectItem):
cdef Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_toolbar_item_prepend(toolbar.obj,
<const_char *>self.icon if self.icon is not None else NULL,
@ -359,6 +366,7 @@ cdef class ToolbarItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -384,7 +392,7 @@ cdef class ToolbarItem(ObjectItem):
Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_toolbar_item_insert_after(toolbar,
after.item,
@ -394,6 +402,7 @@ cdef class ToolbarItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -419,7 +428,7 @@ cdef class ToolbarItem(ObjectItem):
Evas_Smart_Cb cb = NULL
if self.cb_func is not None:
cb = _object_item_callback
cb = _object_item_callback2
item = elm_toolbar_item_insert_before(toolbar,
before.item,
@ -429,6 +438,7 @@ cdef class ToolbarItem(ObjectItem):
if item != NULL:
self._set_obj(item)
self._set_properties_from_keyword_args(self.kwargs)
return self
else:
Py_DECREF(self)
@ -799,7 +809,30 @@ cdef class Toolbar(Object):
return elm_toolbar_icon_order_lookup_get(self.obj)
def item_append(self, icon, label, callback = None, *args, **kargs):
return ToolbarItem(icon, label, callback, *args, **kargs).append_to(self)
cdef:
Elm_Object_Item *item
Evas_Smart_Cb cb = NULL
ToolbarItem ret = ToolbarItem.__new__(ToolbarItem)
if callback is not None and callable(callback):
cb = _object_item_callback
if isinstance(icon, unicode): icon = PyUnicode_AsUTF8String(icon)
if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
item = elm_toolbar_item_append(self.obj,
<const_char *>icon if icon is not None else NULL,
<const_char *>label if label is not None else NULL,
cb, <void*>ret)
if item != NULL:
ret._set_obj(item)
ret.cb_func = callback
ret.args = args
ret.kwargs = kargs
return ret
else:
return None
#TODO: def item_prepend(self, icon, label, callback = None, *args, **kargs):
#return ToolbarItem(self, icon, label, callback, *args, **kargs)

View File

@ -77,7 +77,6 @@ from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object cimport Object
include "callback_conversions.pxi"
import traceback
cimport enums
@ -93,6 +92,10 @@ ELM_WEB_ZOOM_MODE_MANUAL = enums.ELM_WEB_ZOOM_MODE_MANUAL
ELM_WEB_ZOOM_MODE_AUTO_FIT = enums.ELM_WEB_ZOOM_MODE_AUTO_FIT
ELM_WEB_ZOOM_MODE_AUTO_FILL = enums.ELM_WEB_ZOOM_MODE_AUTO_FILL
def _cb_string_conv(long addr):
cdef const_char *s = <const_char *>addr
return _ctouni(s) if s is not NULL else None
def _web_double_conv(long addr):
cdef double *info = <double *>addr
if info == NULL: