Python bindings for ewe, built optionally

This commit is contained in:
Kai Huuhko 2014-06-02 20:16:12 +03:00
parent 4f1efb1ee1
commit dc664dd4c2
35 changed files with 2243 additions and 0 deletions

34
doc/ewe/ewe.rst Normal file
View File

@ -0,0 +1,34 @@
.. py:module:: efl.ewe
:mod:`efl.ewe` Package
=============================
.. automodule::
efl.ewe.__init__
Reference
---------
Modules
^^^^^^^
.. toctree::
:maxdepth: 4
module-combobox
module-entry
module-ruler
module-statusbar
module-tabs
Inheritance diagram
-------------------
.. inheritance-diagram::
efl.ewe.__init__
efl.ewe.combobox
efl.ewe.entry
efl.ewe.ruler
efl.ewe.statusbar
efl.ewe.tabs
:parts: 3

View File

@ -0,0 +1,8 @@
:mod:`combobox` Module
--------------------------
.. automodule:: efl.ewe.combobox
.. inheritance-diagram::
efl.ewe.combobox
:parts: 3

8
doc/ewe/module-entry.rst Normal file
View File

@ -0,0 +1,8 @@
:mod:`entry` Module
--------------------------
.. automodule:: efl.ewe.entry
.. inheritance-diagram::
efl.ewe.entry
:parts: 3

8
doc/ewe/module-ruler.rst Normal file
View File

@ -0,0 +1,8 @@
:mod:`ruler` Module
--------------------------
.. automodule:: efl.ewe.ruler
.. inheritance-diagram::
efl.ewe.ruler
:parts: 3

View File

@ -0,0 +1,8 @@
:mod:`statusbar` Module
--------------------------
.. automodule:: efl.ewe.statusbar
.. inheritance-diagram::
efl.ewe.statusbar
:parts: 3

8
doc/ewe/module-tabs.rst Normal file
View File

@ -0,0 +1,8 @@
:mod:`tabs` Module
--------------------------
.. automodule:: efl.ewe.tabs
.. inheritance-diagram::
efl.ewe.tabs
:parts: 3

View File

@ -79,6 +79,13 @@ Elementary
:maxdepth: 4
Ewe
----------
.. toctree:: ewe/ewe
:maxdepth: 4
DBus integration
----------------

View File

@ -5,6 +5,7 @@ from enums cimport Elm_Wrap_Type, Elm_Text_Format, Elm_Cnp_Mode, \
Elm_Input_Panel_Lang, Elm_Input_Panel_Return_Key_Type, \
Elm_Autocapital_Type, Elm_Icon_Type, Elm_Sel_Type, Elm_Sel_Format, \
Elm_Xdnd_Action
from efl.elementary.layout_class cimport LayoutClass
cdef extern from "Elementary.h":
ctypedef struct Elm_Entry_Anchor_Info:
@ -151,3 +152,6 @@ cdef extern from "Elementary.h":
void elm_entry_context_menu_item_icon_get(const Elm_Entry_Context_Menu_Item *item, const char **icon_file, const char **icon_group, Elm_Icon_Type *icon_type)
Eina_Bool elm_cnp_selection_get(const Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata)
cdef class Entry(LayoutClass):
pass

3
efl/ewe/__init__.pxd Normal file
View File

@ -0,0 +1,3 @@
cdef extern from "ewe.h":
int ewe_init(int argc, char **argv)
int ewe_shutdown()

0
efl/ewe/__init__.py Normal file
View File

45
efl/ewe/__init__.pyx Normal file
View File

@ -0,0 +1,45 @@
from libc.string cimport memcpy
from cpython cimport PyMem_Malloc, PyUnicode_AsUTF8String
import sys
def init():
"""Initialize Elementary Widget Extensions library
:return: The init counter value.
:rtype: int
This function initializes Ewe and increments a counter of
the number of calls to it. It returns the new counter's value.
"""
cdef:
int argc, i, arg_len
char **argv
char *arg
argc = len(sys.argv)
argv = <char **>PyMem_Malloc(argc * sizeof(char *))
for i in range(argc):
t = sys.argv[i]
if isinstance(t, unicode): t = PyUnicode_AsUTF8String(t)
arg = t
arg_len = len(arg)
argv[i] = <char *>PyMem_Malloc(arg_len + 1)
memcpy(argv[i], arg, arg_len + 1)
return ewe_init(argc, argv)
def shutdown():
"""Shut down Elementary Widget Extensions library
:return: The init counter value.
:rtype: int
This should be called at the end of your application, just
before it ceases to do any more processing. This will clean up
any permanent resources your application may have allocated via
Ewe that would otherwise persist.
"""
return ewe_shutdown()

21
efl/ewe/combobox.pxd Normal file
View File

@ -0,0 +1,21 @@
from efl.eina cimport Eina_Bool, Eina_Stringshare, Eina_List
from efl.evas cimport Evas_Object
cdef extern from "ewe.h":
ctypedef struct Ewe_Combobox_Item:
Evas_Object *owner
Evas_Object *content
Eina_Stringshare *title
unsigned int index
Evas_Object * ewe_combobox_add(Evas_Object *parent)
Eina_Bool ewe_combobox_expanded_get(Evas_Object *obj)
Ewe_Combobox_Item * ewe_combobox_item_add(Evas_Object *obj, Eina_Stringshare *title)
Eina_Bool ewe_combobox_item_del(Evas_Object *obj, Ewe_Combobox_Item *item)
Eina_Bool ewe_combobox_items_list_free(Evas_Object *obj, Eina_Bool empty)
const Eina_List * ewe_combobox_items_list_get(const Evas_Object *obj)
Eina_Bool ewe_combobox_item_title_set(Evas_Object *obj, int index, Eina_Stringshare *title)
Eina_Bool ewe_combobox_text_set(Evas_Object *obj, Eina_Stringshare *title)
Eina_Stringshare * ewe_combobox_item_title_get(Evas_Object *obj, const int index)
Ewe_Combobox_Item * ewe_combobox_select_item_get(Evas_Object *obj)
Eina_Bool ewe_combobox_select_item_set(Evas_Object *obj, const int index)

166
efl/ewe/combobox.pyx Normal file
View File

@ -0,0 +1,166 @@
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)

15
efl/ewe/entry.pxd Normal file
View File

@ -0,0 +1,15 @@
from efl.eina cimport Eina_Bool
from efl.evas cimport Evas_Object
cdef extern from "ewe.h":
Evas_Object *ewe_entry_add(Evas_Object *parent)
Eina_Bool ewe_entry_regex_set(Evas_Object *obj, const char *regex_str, int flags)
Eina_Bool ewe_entry_regex_unset(Evas_Object *obj)
Eina_Bool ewe_entry_regex_check(Evas_Object *obj)
Eina_Bool ewe_entry_regex_glow_set(Evas_Object *obj, Eina_Bool glow)
Eina_Bool ewe_entry_regex_glow_get(const Evas_Object *obj)
int ewe_entry_regex_error_get(const Evas_Object *obj)
const char * ewe_entry_regex_error_text_get(const Evas_Object *obj)
Eina_Bool ewe_entry_regex_autocheck_set(Evas_Object *obj, Eina_Bool autocheck)
Eina_Bool ewe_entry_regex_autocheck_get(const Evas_Object *obj)
void ewe_entry_entry_set(Evas_Object *obj, const char *text)

221
efl/ewe/entry.pyx Normal file
View File

@ -0,0 +1,221 @@
"""
Enumerations
============
.. _Ewe_Entry_Regex_Toggles:
Regex Flags
-------------
.. data:: EWE_REG_EXTENDED
Regex check option: Use Extended Regular Expressions.
.. data:: EWE_REG_ICASE
Regex check option: Ignore case in match.
.. _Ewe_Entry_Regex_Status:
Regex Status
------------
.. data:: EWE_REG_NOERROR
Regex Success: Regex maches to the Entrys text
.. data:: EWE_REG_NOMATCH
Regex Error: regexec() failed to match.
.. data:: EWE_REG_BADPAT
Regex Error: Invalid regular expression.
.. data:: EWE_REG_ECOLLATE
Regex Error: Invalid collating element referenced.
.. data:: EWE_REG_ECTYPE
Regex Error: Invalid character class type referenced.
.. data:: EWE_REG_EESCAPE
Regex Error: Trailing \ in pattern.
.. data:: EWE_REG_ESUBREG
Regex Error: Wrong back reference.
.. data:: EWE_REG_EBRACK
Regex Error: [ ] imbalance.
.. data:: EWE_REG_EPAREN
Regex Error: \( \) or ( ) imbalance.
.. data:: EWE_REG_EBRACE
Regex Error: \{ \} imbalance.
.. data:: EWE_REG_BADBR
Regex Error: Content of \{ \} invalid: not a number, number too large, more than two numbers, first larger than second.
.. data:: EWE_REG_ERANGE
Regex Error: Invalid endpoint in range expression.
.. data:: EWE_REG_ESPACE
Regex Error: Out of memory.
.. data:: EWE_REG_BADRPT
Regex Error: ?, * or + not preceded by valid regular expression.
"""
from efl.elementary.entry cimport Entry as elmEntry
from cpython cimport PyUnicode_AsUTF8String
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
cimport enums
EWE_REG_EXTENDED = enums.EWE_REG_EXTENDED
EWE_REG_ICASE = enums.EWE_REG_ICASE
EWE_REG_NOERROR = enums.EWE_REG_NOERROR
EWE_REG_NOMATCH = enums.EWE_REG_NOMATCH
EWE_REG_BADPAT = enums.EWE_REG_BADPAT
EWE_REG_ECOLLATE = enums.EWE_REG_ECOLLATE
EWE_REG_ECTYPE = enums.EWE_REG_ECTYPE
EWE_REG_EESCAPE = enums.EWE_REG_EESCAPE
EWE_REG_ESUBREG = enums.EWE_REG_ESUBREG
EWE_REG_EBRACK = enums.EWE_REG_EBRACK
EWE_REG_EPAREN = enums.EWE_REG_EPAREN
EWE_REG_EBRACE = enums.EWE_REG_EBRACE
EWE_REG_BADBR = enums.EWE_REG_BADBR
EWE_REG_ERANGE = enums.EWE_REG_ERANGE
EWE_REG_ESPACE = enums.EWE_REG_ESPACE
EWE_REG_BADRPT = enums.EWE_REG_BADRPT
cdef class Entry(elmEntry):
def __init__(self, evasObject parent not None, **kwargs):
"""This adds an entry to @p parent object.
By default, entries are:
- not scrolled
- multi-line
- word wrapped
- autosave is enabled
:param parent: The parent object
"""
self._set_obj(ewe_entry_add(parent.obj))
self._set_properties_from_keyword_args(kwargs)
def regex_set(self, regex_str not None, int flags):
"""Set regular expresion to be compiled and used.
:param regex_str: The text of regular expresion
:param flags: Compile flags for regex
:type flags: int value from or'ed :ref:`Ewe_Entry_Regex_Toggles`
:return: True on success, otherwise returns False.
"""
if isinstance(regex_str, unicode):
regex_str = PyUnicode_AsUTF8String(regex_str)
return bool(ewe_entry_regex_set(
self.obj,
<const char *>regex_str,
flags
))
def regex_unset(self):
"""Unset previoustly set regular expresion.
:return: True on success, otherwise returns False.
"""
return bool(ewe_entry_regex_unset(self.obj))
def regex_check(self):
"""Check current text of Entry with previoustly set regular expresion.
:return: True on success, otherwise returns False.
"""
return bool(ewe_entry_regex_check(self.obj))
property regex_glow:
"""Set if regex error signals for EDJE should be emitted.
:type: bool
"""
def __set__(self, bint glow):
if not ewe_entry_regex_glow_set(self.obj, glow):
raise RuntimeError("glow could not be set")
def __get__(self):
return bool(ewe_entry_regex_glow_get(self.obj))
def regex_error_get(self):
"""Returns last regex error
:return: The last regex error.
"""
return ewe_entry_regex_error_get(self.obj)
def regex_error_text_get(self):
"""Returns the string that contains last regex error.
This message updates on each regex setting and checking.
The string is deleted on Entry object deleteon.
:return: The last regex error. If regex is not set yet None would be returned.
"""
return _ctouni(ewe_entry_regex_error_text_get(self.obj))
property regex_autocheck:
"""Automatic regex check on "entry,changed".
Signals will be processed only for focused entry.
:type: bool
"""
def __set__(self, bint autocheck):
if not ewe_entry_regex_autocheck_set(self.obj, autocheck):
raise RuntimeError("could not enable autocheck")
def __get__(self):
return bool(ewe_entry_regex_autocheck_get(self.obj))
property entry:
"""This sets the text displayed within the entry to @p entry.
:param entry: The text to be displayed
.. note:: Using this function bypasses text filters
"""
def __get__(self):
return elmEntry.entry.__get__(self)
def __set__(self, text):
if isinstance(text, unicode): text = PyUnicode_AsUTF8String(text)
ewe_entry_entry_set(
self.obj,
<const char *>text if text is not None else NULL
)

35
efl/ewe/enums.pxd Normal file
View File

@ -0,0 +1,35 @@
cdef extern from "ewe.h":
enum:
EWE_REG_EXTENDED
EWE_REG_ICASE
enum:
EWE_REG_NOERROR
EWE_REG_NOMATCH
EWE_REG_BADPAT
EWE_REG_ECOLLATE
EWE_REG_ECTYPE
EWE_REG_EESCAPE
EWE_REG_ESUBREG
EWE_REG_EBRACK
EWE_REG_EPAREN
EWE_REG_EBRACE
EWE_REG_BADBR
EWE_REG_ERANGE
EWE_REG_ESPACE
EWE_REG_BADRPT
ctypedef enum Ewe_Ruler_Orient:
EWE_RULER_ORIENT_WRONG # returned from get func if some error occured
EWE_RULER_ORIENT_HORIZONTAL # Ruler (dis)appears in horizontal mode
EWE_RULER_ORIENT_VERTICAL # Ruler (dis)appears in vertical mode
ctypedef enum Ewe_Statusbar_Items_Align:
EWE_STATUSBAR_ITEMS_ALIGN_RIGHT
EWE_STATUSBAR_ITEMS_ALIGN_CENTER
EWE_STATUSBAR_ITEMS_ALIGN_LEFT
EWE_STATUSBAR_ITEMS_ALIGN_LAST
ctypedef enum Ewe_Statusbar_Items_Type:
EWE_STATUSBAR_ITEM_TYPE_OBJECT # item with content
EWE_STATUSBAR_ITEM_TYPE_SEPARATOR # separate item

2
efl/ewe/object_item.pxd Normal file
View File

@ -0,0 +1,2 @@
cdef class _ObjectItem(object):
cdef int _set_properties_from_keyword_args(self, dict kwargs) except 0

9
efl/ewe/object_item.pyx Normal file
View File

@ -0,0 +1,9 @@
cdef class _ObjectItem(object):
cdef int _set_properties_from_keyword_args(self, dict kwargs) except 0:
if not kwargs:
return 1
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

13
efl/ewe/ruler.pxd Normal file
View File

@ -0,0 +1,13 @@
from efl.c_eo cimport Eo
from efl.eina cimport Eina_Bool
from efl.evas cimport Evas_Object
from enums cimport Ewe_Ruler_Orient
cdef extern from "ewe.h":
Evas_Object * ewe_ruler_add(Evas_Object *parent)
Eina_Bool ewe_ruler_orient_set(Evas_Object *obj, Ewe_Ruler_Orient orient)
Ewe_Ruler_Orient ewe_ruler_orient_get(const Eo *obj)
Eina_Bool ewe_ruler_step_set(Evas_Object *obj, unsigned int step)
unsigned int ewe_ruler_step_get(const Eo *obj)
Eina_Bool ewe_ruler_zero_offset_set(Evas_Object *obj, int pos)
int ewe_ruler_zero_offset_get(const Eo *obj)

84
efl/ewe/ruler.pyx Normal file
View File

@ -0,0 +1,84 @@
"""
Enumerations
============
.. _Ewe_Ruler_Orient:
Orientation
-----------
.. data:: EWE_RULER_ORIENT_WRONG
returned from get func if some error occured
.. data:: EWE_RULER_ORIENT_HORIZONTAL
Ruler (dis)appears in horizontal mode
.. data:: EWE_RULER_ORIENT_VERTICAL
Ruler (dis)appears in vertical mode
"""
from cpython cimport PyUnicode_AsUTF8String
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from efl.elementary.object cimport Object
cimport enums
EWE_RULER_ORIENT_WRONG = enums.EWE_RULER_ORIENT_WRONG
EWE_RULER_ORIENT_HORIZONTAL = enums.EWE_RULER_ORIENT_HORIZONTAL
EWE_RULER_ORIENT_VERTICAL = enums.EWE_RULER_ORIENT_VERTICAL
cdef class Ruler(Object):
def __init__(self, evasObject parent not None, **kwargs):
"""Add new ruler to the given parent object
:param parent: The parent object.
"""
self._set_obj(ewe_ruler_add(parent.obj))
self._set_properties_from_keyword_args(kwargs)
property orient:
"""Ruler orientation
:type: :ref:`Ewe_Ruler_Orient`
"""
def __set__(self, Ewe_Ruler_Orient orient):
if not ewe_ruler_orient_set(self.obj, orient):
raise RuntimeError("Could not set ruler orientation")
def __get__(self):
return ewe_ruler_orient_get(self.obj)
property step:
"""Step between marks of the ruler. If step is setting to 0, it would be
setting to 1.
:type: int
"""
def __set__(self, unsigned int step):
if not ewe_ruler_step_set(self.obj, step):
raise RuntimeError("Could not set ruler step")
def __get__(self):
return ewe_ruler_step_get(self.obj)
property zero_offset:
"""Change the ruler's "zero pointer" mark position in pixels relative to
start parent's layout
:type: int
"""
def __set__(self, int pos):
if not ewe_ruler_zero_offset_set(self.obj, pos):
raise RuntimeError("Could not set ruler offset")
def __get__(self):
return ewe_ruler_zero_offset_get(self.obj)

47
efl/ewe/statusbar.pxd Normal file
View File

@ -0,0 +1,47 @@
from efl.eina cimport Eina_Bool, Eina_List
from efl.evas cimport Evas_Object, Evas_Smart_Cb
from enums cimport Ewe_Statusbar_Items_Type, Ewe_Statusbar_Items_Align
cdef extern from "ewe.h":
ctypedef struct Ewe_Statusbar_Item:
Evas_Object *parent # the pointer to parent statusbar object
Evas_Object *content # the object, which added into item
Evas_Object *markup # the object which load markup from edj file
Ewe_Statusbar_Items_Type type # item type: separator or item witch content
Evas_Smart_Cb func # callback function, which call when item clicked
void *cb_data # data, which will be sended into item callback
Eina_Bool disabled # the item disabled status: EINA_TRUE - enabled
int id # the item identificator
int width # the item width, if less that 0, then ulimited width will set
int ewe_statusbar_item_id_get(Ewe_Statusbar_Item *item)
int ewe_statusbar_item_width_get(Ewe_Statusbar_Item *item)
Eina_Bool ewe_statusbar_item_width_set(Ewe_Statusbar_Item *item, int width)
char * ewe_statusbar_item_label_get(Ewe_Statusbar_Item *item)
Eina_Bool ewe_statusbar_item_label_set(Ewe_Statusbar_Item *item, const char *label)
Evas_Object * ewe_statusbar_item_content_get(Ewe_Statusbar_Item *item)
Eina_Bool ewe_statusbar_item_content_set(Ewe_Statusbar_Item *item, Evas_Object *content)
Evas_Object * ewe_statusbar_item_content_unset(Ewe_Statusbar_Item *item)
Evas_Object * ewe_statusbar_item_statusbar_get(Ewe_Statusbar_Item *item)
Evas_Object * ewe_statusbar_add(Evas_Object *parent)
Eina_Bool ewe_statusbar_clear(Evas_Object *obj)
Ewe_Statusbar_Item * ewe_statusbar_item_append(Evas_Object *obj, Evas_Object *content, Ewe_Statusbar_Items_Type type, Evas_Smart_Cb func, void *func_data)
Ewe_Statusbar_Item * ewe_statusbar_item_prepend(Evas_Object *obj, Evas_Object *content, Ewe_Statusbar_Items_Type type, Evas_Smart_Cb func, void *func_data)
Eina_Bool ewe_statusbar_item_insert_before(Evas_Object *obj, Ewe_Statusbar_Item *item, Ewe_Statusbar_Item *before)
Eina_Bool ewe_statusbar_item_insert_after(Evas_Object *obj, Ewe_Statusbar_Item *item, Ewe_Statusbar_Item *after)
Eina_Bool ewe_statusbar_items_swap(Evas_Object *obj, Ewe_Statusbar_Item *item_first, Ewe_Statusbar_Item *item_second)
const Eina_List * ewe_statusbar_items_list_get(Evas_Object *obj)
void ewe_statusbar_items_padding_set(Evas_Object *obj, int padding)
int ewe_statusbar_items_padding_get(const Evas_Object *obj)
void ewe_statusbar_items_align_set(Evas_Object *obj, Ewe_Statusbar_Items_Align align)
Ewe_Statusbar_Items_Align ewe_statusbar_items_align_get(const Evas_Object *obj)
Eina_Bool ewe_statusbar_item_remove(Evas_Object *obj, Ewe_Statusbar_Item *item)

394
efl/ewe/statusbar.pyx Normal file
View File

@ -0,0 +1,394 @@
"""
Enumerations
============
.. _Ewe_Statusbar_Items_Align:
Item alignment
--------------
Defines items align into statusbar
.. data:: EWE_STATUSBAR_ITEMS_ALIGN_RIGHT
.. data:: EWE_STATUSBAR_ITEMS_ALIGN_CENTER
.. data:: EWE_STATUSBAR_ITEMS_ALIGN_LEFT
.. _Ewe_Statusbar_Items_Type:
Item types
----------
Defines statusbar item types.
.. data:: EWE_STATUSBAR_ITEM_TYPE_OBJECT
item with content
.. data:: EWE_STATUSBAR_ITEM_TYPE_SEPARATOR
separator item
"""
from cpython cimport PyUnicode_AsUTF8String, Py_INCREF, Py_DECREF
from efl.eo cimport object_from_instance
from efl.utils.conversions cimport _touni
from efl.evas cimport Object as evasObject
from efl.elementary.object cimport Object
from efl.ewe.object_item cimport _ObjectItem
cimport enums
import traceback
EWE_STATUSBAR_ITEMS_ALIGN_RIGHT = enums.EWE_STATUSBAR_ITEMS_ALIGN_RIGHT
EWE_STATUSBAR_ITEMS_ALIGN_CENTER = enums.EWE_STATUSBAR_ITEMS_ALIGN_CENTER
EWE_STATUSBAR_ITEMS_ALIGN_LEFT = enums.EWE_STATUSBAR_ITEMS_ALIGN_LEFT
EWE_STATUSBAR_ITEMS_ALIGN_LAST = enums.EWE_STATUSBAR_ITEMS_ALIGN_LAST
EWE_STATUSBAR_ITEM_TYPE_OBJECT = enums.EWE_STATUSBAR_ITEM_TYPE_OBJECT
EWE_STATUSBAR_ITEM_TYPE_SEPARATOR = enums.EWE_STATUSBAR_ITEM_TYPE_SEPARATOR
cdef void _py_ewe_statusbar_item_cb(void *data, Evas_Object *obj, void *event_info) with gil:
cdef StatusbarItem item = <object>data
try:
o = object_from_instance(obj)
item.cb(o, item, item.cb_data)
except Exception:
traceback.print_exc()
cdef _statusbar_item_to_python(Ewe_Statusbar_Item *it):
cdef:
void *data
StatusbarItem item
if it == NULL:
return None
data = it.cb_data
if data == NULL:
# Create a dummy statusbar item.
item = StatusbarItem.__new__(StatusbarItem)
item._set_obj(it)
else:
item = <object>data
return item
cdef _statusbar_item_list_to_python(const Eina_List *lst):
cdef Ewe_Statusbar_Item *it
ret = []
while lst:
it = <Ewe_Statusbar_Item *>lst.data
lst = lst.next
o = _statusbar_item_to_python(it)
if o is not None:
ret.append(o)
return ret
cdef class StatusbarItem(_ObjectItem):
cdef:
object cb
object cb_data
Ewe_Statusbar_Item *item
cdef int _set_obj(self, Ewe_Statusbar_Item *item) except 0:
assert self.item == NULL, "Object must be clean"
self.item = item
Py_INCREF(self)
return 1
cdef int _unset_obj(self) except 0:
assert self.item != NULL, "Object already deleted"
self.item = NULL
Py_DECREF(self)
return 1
def __init__(self, *args, **kwargs):
self.append(*args, **kwargs)
@classmethod
def append(cls,
Statusbar statusbar not None, evasObject content=None,
Ewe_Statusbar_Items_Type type=enums.EWE_STATUSBAR_ITEM_TYPE_OBJECT,
cb=None, cb_data=None, **kwargs):
"""Append a new item in a given statusbar widget.
:param content: The object, which will be set into statusbar item as
content. Can be None, if planned set content with
:py:attr:`StatusbarItem.content`.
:param type: Item type.
:param func: Convenience function called when the item is clicked.
:param func_data: Data passed to func above.
:return: A handle to the item added or NULL if not possible
This adds the new item to the end of the list childrens in statusbar widget.
"""
cdef:
void *func_data
StatusbarItem self
self = cls.__new__(cls)
if cb:
if not callable(cb):
raise TypeError("cb must be callable")
else:
self.cb = cb
self.cb_data = cb_data
self._set_obj(ewe_statusbar_item_append(
statusbar.obj, content.obj, type,
<Evas_Smart_Cb>_py_ewe_statusbar_item_cb if cb is not None else NULL,
<void *>self
))
self._set_properties_from_keyword_args(kwargs)
return self
@classmethod
def prepend(cls,
Statusbar statusbar not None, evasObject content=None,
Ewe_Statusbar_Items_Type type=enums.EWE_STATUSBAR_ITEM_TYPE_OBJECT,
cb=None, cb_data=None, **kwargs):
"""Prepend a new item in a given statusbar widget.
:param content: The object, which will be set into statusbar item as
content. Can be None, if planned set content with
:py:attr:`StatusbarItem.content`.
:param type: Item type.
:param func: Convenience function called when the item is clicked.
:param func_data: Data passed to func above.
:return: A handle to the item added or None if not possible
This adds the new item to the beginnig of the list childrens in statusbar widget.
"""
cdef:
void *func_data
StatusbarItem self
self = cls.__new__(cls)
if cb:
if not callable(cb):
raise TypeError("cb must be callable")
else:
self.cb = cb
self.cb_data = cb_data
self._set_properties_from_keyword_args(kwargs)
self._set_obj(ewe_statusbar_item_prepend(
statusbar.obj, content.obj, type,
<Evas_Smart_Cb>_py_ewe_statusbar_item_cb if cb is not None else NULL,
<void *>self
))
return self
def insert_before(self, StatusbarItem before not None):
"""Insert this item before another in a given statusbar widget.
:param before: The item to place this one before.
:return: True if item inserted sucessful, or Flase in otherwise.
"""
return bool(ewe_statusbar_item_insert_before(
ewe_statusbar_item_statusbar_get(self.item),
before.item,
self.item
))
def insert_after(self, StatusbarItem after not None):
"""Insert a existent item after another in a given statusbar widget.
:param after: The item to place this one before.
:return: True if item inserted sucessful, or False in otherwise.
"""
return bool(ewe_statusbar_item_insert_after(
ewe_statusbar_item_statusbar_get(self.item),
after.item,
self.item
))
def items_swap(self, StatusbarItem item_second not None):
"""Swap statusbar items positions into statusbar widgets.
:param item_first: The item, which will be swapped.
:param item_second: The item, which will be swapped.
:return: True if swap is sucessful, or False in otherwise.
"""
return bool(ewe_statusbar_items_swap(
ewe_statusbar_item_statusbar_get(self.item),
self.item,
item_second.item
))
property index:
"""Get the index of the statusbar item.
:type: int
"""
def __get__(self):
return ewe_statusbar_item_id_get(self.item)
property width:
"""The width of the statusbar item.
A width, which will be set as fixed for statusbar item. If
param equal -1, then width of statusbar item will be unlimited.
:type: int
"""
def __get__(self):
return ewe_statusbar_item_width_get(self.item)
def __set__(self, int width):
if not ewe_statusbar_item_width_set(self.item, width):
raise RuntimeError("Width could not be set")
property label:
"""Item label.
:type: string
"""
def __get__(self):
return _touni(ewe_statusbar_item_label_get(self.item))
def __set__(self, label):
if isinstance(label, unicode):
label = PyUnicode_AsUTF8String(label)
if not ewe_statusbar_item_label_set(
self.item,
<const char *>label if label is not None else NULL
):
raise RuntimeError("Could not set item label")
property content:
"""Get the object, which stored into statusbar item.
:type: :py:class:`efl.evas.Object`
"""
def __get__(self):
return object_from_instance(
ewe_statusbar_item_content_get(self.item)
)
def __set__(self, evasObject content):
if not ewe_statusbar_item_content_set(self.item, content.obj):
raise RuntimeError("Content could not be set")
def __del__(self):
ewe_statusbar_item_content_unset(self.item)
property statusbar:
"""Get the statusbar object from statusbar item.
:type: :py:class:`Statusbar`
"""
def __get__(self):
return object_from_instance(
ewe_statusbar_item_statusbar_get(self.item)
)
def delete(self):
"""Remove item from statusbar widget.
:return: True if item removed sucessful, or False in otherwise.
"""
cdef bint ret
ret = ewe_statusbar_item_remove(
ewe_statusbar_item_statusbar_get(self.item),
self.item
)
self._unset_obj()
return ret
cdef class Statusbar(Object):
def __init__(self, evasObject parent not None, **kwargs):
"""Add a new statusbar widget to the given parent object.
:param parent: The parent object
"""
self._set_obj(ewe_statusbar_add(parent.obj))
self._set_properties_from_keyword_args(kwargs)
def clear(self):
"""Remove all items from a given statusbar widget.
:return: True if items clear sucessful, or False in otherwise.
This removes (and deletes) all items in given statusbar, leaving it
empty.
"""
return bool(ewe_statusbar_clear(self.obj))
property items:
"""Retrieve a list of the items, which exist into the statusbar.
:return: a new Eina_List with a pointer to Ewe_Statusbar_Item in its
nodes, or None on errors.
"""
def __get__(self):
return _statusbar_item_list_to_python(
ewe_statusbar_items_list_get(self.obj)
)
property padding:
"""Set the padding between the statusbar items.
:type: int
Extra space in pixels that will be added between a statusbar items.
This padding is set for all items in the statusbar widget.
"""
def __set__(self, int padding):
ewe_statusbar_items_padding_set(self.obj, padding)
def __get__(self):
return ewe_statusbar_items_padding_get(self.obj)
property align:
"""Alignment of the whole bounding statusbar of items.
:type: :ref:`Ewe_Statusbar_Items_Align`
How the bounding box containing all the items of the statusbar, after
their sizes and position has been calculated, will be aligned within
the space given for the whole statusbar widget.
"""
def __set__(self, Ewe_Statusbar_Items_Align align):
ewe_statusbar_items_align_set(self.obj, align)
def __get__(self):
return ewe_statusbar_items_align_get(self.obj)

32
efl/ewe/tabs.pxd Normal file
View File

@ -0,0 +1,32 @@
from efl.eina cimport Eina_Bool, Eina_List, Eina_Stringshare
from efl.evas cimport Evas_Object, Evas_Smart_Cb
from enums cimport Ewe_Statusbar_Items_Type, Ewe_Statusbar_Items_Align
cdef extern from "ewe.h":
ctypedef struct Ewe_Tabs_Item:
Evas_Object *owner
Evas_Object *head
Evas_Object *content
Eina_Stringshare *title
Eina_Stringshare *style
Eina_Bool disabled
Evas_Object * ewe_tabs_add(Evas_Object *parent)
Ewe_Tabs_Item * ewe_tabs_item_append(Evas_Object *obj, Ewe_Tabs_Item *item, Eina_Stringshare *title, Eina_Stringshare *style)
Ewe_Tabs_Item * ewe_tabs_item_prepend(Evas_Object *obj, Ewe_Tabs_Item *item, Eina_Stringshare *title, Eina_Stringshare *style)
Eina_Bool ewe_tabs_item_del(Evas_Object *obj, Ewe_Tabs_Item *item)
const Eina_List * ewe_tabs_items_list_get(const Evas_Object *obj)
Eina_Bool ewe_tabs_item_content_set(Evas_Object *obj, Ewe_Tabs_Item *item, Evas_Object *content)
Evas_Object * ewe_tabs_item_content_unset(Evas_Object *obj, Ewe_Tabs_Item *item)
const Evas_Object * ewe_tabs_item_content_get(Evas_Object *obj, Ewe_Tabs_Item *item)
Eina_Bool ewe_tabs_item_icon_set(Evas_Object *obj, Ewe_Tabs_Item *item, Evas_Object *icon)
Evas_Object * ewe_tabs_item_icon_unset(Evas_Object *obj, Ewe_Tabs_Item *item)
Eina_Bool ewe_tabs_item_button_set(Evas_Object *obj, Ewe_Tabs_Item *item, Evas_Object *button)
Evas_Object * ewe_tabs_item_button_unset(Evas_Object *obj, Ewe_Tabs_Item *item)
Eina_Bool ewe_tabs_active_item_set(Evas_Object *obj, Ewe_Tabs_Item *item)
Ewe_Tabs_Item * ewe_tabs_active_item_get(const Evas_Object *obj)
Eina_Bool ewe_tabs_item_title_set(Evas_Object *obj, Ewe_Tabs_Item *item, Eina_Stringshare *title)
Eina_Stringshare * ewe_tabs_item_title_get(const Evas_Object *obj, Ewe_Tabs_Item *item)
Eina_Bool ewe_tabs_item_disabled_set(Evas_Object *obj, Ewe_Tabs_Item *item, Eina_Bool disabled)
Eina_Bool ewe_tabs_item_disabled_get(const Evas_Object *obj, Ewe_Tabs_Item *item)

278
efl/ewe/tabs.pyx Normal file
View File

@ -0,0 +1,278 @@
from libc.stdint cimport uintptr_t
from cpython cimport PyUnicode_AsUTF8String, Py_INCREF, Py_DECREF
from efl.eo cimport object_from_instance
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from efl.elementary.object cimport Object
from efl.ewe.object_item cimport _ObjectItem
cimport enums
import traceback
def _cb_tabs_item_conv(uintptr_t addr):
cdef TabsItem it = TabsItem.__new__(TabsItem)
it.item = <Ewe_Tabs_Item *>addr
return it
cdef _tabs_item_to_python(Ewe_Tabs_Item *it):
cdef:
TabsItem item
if it == NULL:
return None
# Create a dummy tabs item.
item = TabsItem.__new__(TabsItem)
item._set_obj(it)
return item
cdef _tabs_item_list_to_python(const Eina_List *lst):
cdef Ewe_Tabs_Item *it
ret = []
while lst:
it = <Ewe_Tabs_Item *>lst.data
lst = lst.next
o = _tabs_item_to_python(it)
if o is not None:
ret.append(o)
return ret
cdef class TabsItem(_ObjectItem):
cdef:
Ewe_Tabs_Item *item
cdef int _set_obj(self, Ewe_Tabs_Item *item) except 0:
assert self.item == NULL, "Object must be clean"
self.item = item
Py_INCREF(self)
return 1
def __richcmp__(TabsItem self, TabsItem y, op):
if op == 2:
return self.item == y.item
elif op == 3:
return self.item != y.item
else:
return NotImplemented
def __init__(self, *args, **kwargs):
self.append(*args, **kwargs)
@classmethod
def append(cls,
Tabs tabs not None, TabsItem after=None,
title=None, style=None, **kwargs
):
"""This adds an item after specified item.
If no item specified adds as last.
:param item: The tabs item
:param title: The tabs title
:param style: The tabs style
:return: The new tabs item object or NULL if it cannot be created
"""
cdef:
void *func_data
TabsItem self
self = cls.__new__(cls)
if isinstance(title, unicode): title = PyUnicode_AsUTF8String(title)
if isinstance(style, unicode): style = PyUnicode_AsUTF8String(style)
self._set_obj(ewe_tabs_item_append(
tabs.obj,
<Ewe_Tabs_Item *>after.item if after is not None else NULL,
<Eina_Stringshare *>title if title is not None else NULL,
<Eina_Stringshare *>style if style is not None else NULL
))
self._set_properties_from_keyword_args(kwargs)
return self
@classmethod
def prepend(cls,
Tabs tabs not None, TabsItem before=None,
title=None, style=None, **kwargs
):
"""This adds an item before specified item.
If no item specified adds as first.
:param item: The tabs item
:param title: The tabs title
:param style: The tabs style
:return: The new tabs item object or NULL if it cannot be created
"""
cdef:
void *func_data
TabsItem self
self = cls.__new__(cls)
if isinstance(title, unicode): title = PyUnicode_AsUTF8String(title)
if isinstance(style, unicode): style = PyUnicode_AsUTF8String(style)
self._set_obj(ewe_tabs_item_prepend(
tabs.obj,
<Ewe_Tabs_Item *>before.item if before is not None else NULL,
<Eina_Stringshare *>title if title is not None else NULL,
<Eina_Stringshare *>style if style is not None else NULL
))
self._set_properties_from_keyword_args(kwargs)
return self
def delete(self):
"""Delete tabs item.
:param item: The tabs item
:return: EINA_TRUE on success, EINA_FALSE otherwise
"""
return bool(ewe_tabs_item_del(self.item.owner, self.item))
property content:
"""Content of tabs item
:type: :py:class:`efl.evas.Object`
"""
def __set__(self, evasObject content):
if not ewe_tabs_item_content_set(
self.item.owner, self.item, content.obj
):
raise RuntimeError
def __del__(self):
ewe_tabs_item_content_unset(self.item.owner, self.item)
def __get__(self):
return object_from_instance(ewe_tabs_item_content_get(
self.item.owner, self.item
))
property icon:
"""Icon of tabs item
:type: :py:class:`efl.evas.Object`
"""
def __set__(self, evasObject icon not None):
if not ewe_tabs_item_icon_set(self.item.owner, self.item, icon.obj):
raise RuntimeError
def __del__(self):
ewe_tabs_item_icon_unset(self.item.owner, self.item)
property button:
"""Button of tabs item.
:type: :py:class:`efl.evas.Object`
"""
def __set__(self, evasObject button not None):
if not ewe_tabs_item_button_set(self.item.owner, self.item, button.obj):
raise RuntimeError
def __del__(self):
ewe_tabs_item_button_unset(self.item.owner, self.item)
def activate(self):
"""This activates tabs item.
:param item: The tabs item
:return: EINA_TRUE on success, EINA_FALSE otherwise
"""
return bool(ewe_tabs_active_item_set(self.item.owner, self.item))
property title:
"""Title of the tabs item.
:type: string
"""
def __set__(self, title):
if isinstance(title, unicode):
title = PyUnicode_AsUTF8String(title)
if not ewe_tabs_item_title_set(
self.item.owner, self.item, title
):
raise RuntimeError
def __get__(self):
return _ctouni(ewe_tabs_item_title_get(self.item.owner, self.item))
property disabled:
"""This enables or disables tabs item.
Notes: user cannot switch to disabled tabs item.
If it is active allready or is activated from code
items content will be also rendered disabled.
:param item: The tabs item
:param disabled: EINA_TRUE to disable, EINA_FALSE to enable tabs item
:return: EINA_TRUE on success, EINA_FALSE otherwise
"""
def __set__(self, bint disabled):
if not ewe_tabs_item_disabled_set(self.item.owner, self.item, disabled):
raise RuntimeError
def __get__(self):
return bool(ewe_tabs_item_disabled_get(self.item.owner, self.item))
cdef class Tabs(Object):
def __init__(self, evasObject parent not None, **kwargs):
"""This adds tabs to @p parent object.
:param parent: The parent object
:return: The new object or NULL if it cannot be created
"""
self._set_obj(ewe_tabs_add(parent.obj))
self._set_properties_from_keyword_args(kwargs)
property items:
"""Get internal items list.
:param obj: The tabs object
:return: list of items on success, NULL otherwise
"""
def __get__(self):
return _tabs_item_list_to_python(ewe_tabs_items_list_get(self.obj))
property active_item:
"""Get active item item.
:return: Ewe_Tabs_Item* on success, NULL otherwise
"""
def __get__(self):
return _tabs_item_to_python(ewe_tabs_active_item_get(self.obj))
def callback_item_activated_add(self, func, *args, **kwargs):
self._callback_add_full("ewe,tabs,item,activated", _cb_tabs_item_conv,
func, *args, **kwargs)
def callback_item_activated_del(self, func):