python-efl/efl/ewe/statusbar.pyx

395 lines
11 KiB
Cython

"""
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)