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