167 lines
5.0 KiB
Cython
167 lines
5.0 KiB
Cython
from libc.stdint cimport uintptr_t
|
|
from cpython cimport PyUnicode_AsUTF8String
|
|
|
|
from efl.utils.conversions cimport _ctouni
|
|
from efl.evas cimport Object as evasObject
|
|
from efl.elementary.object cimport Object
|
|
|
|
def _cb_combobox_item_conv(uintptr_t addr):
|
|
cdef ComboboxItem it = ComboboxItem.__new__(ComboboxItem)
|
|
it.item = <Ewe_Combobox_Item *>addr
|
|
return it
|
|
|
|
cdef class ComboboxItem(object):
|
|
|
|
cdef Ewe_Combobox_Item *item
|
|
|
|
def __init__(self, evasObject parent not None, title):
|
|
"""This adds an item to combobox object.
|
|
|
|
:param parent: The combobox object
|
|
:param title: The combobox title
|
|
|
|
"""
|
|
if isinstance(title, unicode): title = PyUnicode_AsUTF8String(title)
|
|
self.item = ewe_combobox_item_add(parent.obj, title)
|
|
|
|
def delete(self):
|
|
"""Delete combobox item.
|
|
|
|
:param item: The combobox item
|
|
:return: EINA_TRUE on success, EINA_FALSE otherwise
|
|
|
|
"""
|
|
return bool(ewe_combobox_item_del(self.item.owner, self.item))
|
|
|
|
cdef list eina_list_items_to_python_list(const Eina_List *lst):
|
|
cdef:
|
|
Ewe_Combobox_Item *item
|
|
list ret = []
|
|
Eina_List *itr = <Eina_List *>lst
|
|
ComboboxItem it
|
|
while itr:
|
|
it = ComboboxItem.__new__(ComboboxItem)
|
|
it.item = <Ewe_Combobox_Item *>itr.data
|
|
ret.append(it)
|
|
itr = itr.next
|
|
return ret
|
|
|
|
cdef class Combobox(Object):
|
|
|
|
def __init__(self, evasObject parent not None, **kwargs):
|
|
"""Add a new combobox to the parent
|
|
|
|
:param parent: The parent object
|
|
|
|
"""
|
|
self._set_obj(ewe_combobox_add(parent.obj))
|
|
self._set_properties_from_keyword_args(kwargs)
|
|
|
|
property expanded:
|
|
"""Returns whether the combobox is expanded.
|
|
|
|
:type: bool
|
|
|
|
"""
|
|
def __get__(self):
|
|
return bool(ewe_combobox_expanded_get(self.obj))
|
|
|
|
def items_list_free(self, bint empty):
|
|
"""Combobox items list free.
|
|
|
|
:param item: The combobox item
|
|
:return: True on success, False otherwise
|
|
|
|
"""
|
|
return ewe_combobox_items_list_free(self.obj, empty)
|
|
|
|
def items_list_get(self):
|
|
"""Get internal items list.
|
|
|
|
:return: list of items on success, None otherwise
|
|
|
|
"""
|
|
return eina_list_items_to_python_list(
|
|
ewe_combobox_items_list_get(self.obj)
|
|
)
|
|
|
|
property text:
|
|
"""This sets title for the combobox.
|
|
|
|
:param title: Text to be set as title of the combobox
|
|
:raise RuntimeError: True on success, False otherwise
|
|
|
|
"""
|
|
def __set__(self, title):
|
|
if isinstance(title, unicode):
|
|
title = PyUnicode_AsUTF8String(title)
|
|
if not ewe_combobox_text_set(self.obj, title):
|
|
raise RuntimeError("Setting title text failed")
|
|
|
|
def selected_item_get(self):
|
|
"""Gets the selected item from a combobox object.
|
|
|
|
:return: The selected combobox item object or None if it cannot be created
|
|
|
|
"""
|
|
cdef ComboboxItem it = ComboboxItem.__new__(ComboboxItem)
|
|
it.item = ewe_combobox_select_item_get(self.obj)
|
|
return it
|
|
|
|
def selected_item_set(self, int index):
|
|
"""Sets select combobox item.
|
|
|
|
:param index: The combobox index
|
|
:return: True on success, False otherwise
|
|
|
|
"""
|
|
return bool(ewe_combobox_select_item_set(self.obj, index))
|
|
|
|
def item_title_set(self, int index, title):
|
|
"""This sets title of the combobox item.
|
|
|
|
:param index: The combobox item index
|
|
:param title: Text to be setted as title of the combobox item
|
|
:rtype: bool
|
|
|
|
"""
|
|
if isinstance(title, unicode): title = PyUnicode_AsUTF8String(title)
|
|
return ewe_combobox_item_title_set(
|
|
self.obj,
|
|
index,
|
|
<Eina_Stringshare *>title if title is not None else NULL
|
|
)
|
|
def item_title_get(self, int index):
|
|
"""This sets title of the combobox item.
|
|
|
|
:param index: The combobox item index
|
|
:rtype: string
|
|
|
|
"""
|
|
return _ctouni(ewe_combobox_item_title_get(
|
|
self.obj,
|
|
index
|
|
))
|
|
|
|
def callback_collapsed_add(self, func, *args, **kwargs):
|
|
"""Called when the menu is collapsed."""
|
|
self._callback_add("collapsed", func, *args, **kwargs)
|
|
|
|
def callback_collapsed_del(self, func):
|
|
self._callback_del("collapsed", func)
|
|
|
|
def callback_expanded_add(self, func, *args, **kwargs):
|
|
"""Called when the menu is expanded."""
|
|
self._callback_add("expanded", func, *args, **kwargs)
|
|
|
|
def callback_expanded_del(self, func):
|
|
self._callback_del("expanded", func)
|
|
|
|
def callback_selected_add(self, func, *args, **kwargs):
|
|
"""Called when user selects an item."""
|
|
self._callback_add_full("selected", _cb_combobox_item_conv, func,
|
|
*args, **kwargs)
|
|
|
|
def callback_selected_del(self, func):
|
|
self._callback_del_full("selected", _cb_combobox_item_conv, func)
|