# Copyright (C) 2007-2013 various contributors (see AUTHORS)
#
# This file is part of Python-EFL.
#
# Python-EFL is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# Python-EFL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with python-elementary. If not, see .
#
"""
.. rubric:: Icon lookup modes
.. data:: ELM_ICON_LOOKUP_FDO_THEME
freedesktop, theme
.. data:: ELM_ICON_LOOKUP_THEME_FDO
theme, freedesktop
.. data:: ELM_ICON_LOOKUP_FDO
freedesktop
.. data:: ELM_ICON_LOOKUP_THEME
theme
.. rubric:: Selection modes
.. data:: ELM_OBJECT_SELECT_MODE_DEFAULT
Default select mode
.. data:: ELM_OBJECT_SELECT_MODE_ALWAYS
Always select mode
.. data:: ELM_OBJECT_SELECT_MODE_NONE
No select mode
.. data:: ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY
No select mode with no finger size rule
.. rubric:: Toolbar shrink modes
.. data:: ELM_TOOLBAR_SHRINK_NONE
Set toolbar minimum size to fit all the items
.. data:: ELM_TOOLBAR_SHRINK_HIDE
Hide exceeding items
.. data:: ELM_TOOLBAR_SHRINK_SCROLL
Allow accessing exceeding items through a scroller
.. data:: ELM_TOOLBAR_SHRINK_MENU
Inserts a button to pop up a menu with exceeding items
.. data:: ELM_TOOLBAR_SHRINK_EXPAND
Expand all items according the size of the toolbar.
"""
include "widget_header.pxi"
from object cimport Object
from object_item cimport _object_item_callback, \
_object_item_to_python
from menu cimport Menu
cimport enums
ELM_ICON_LOOKUP_FDO_THEME = enums.ELM_ICON_LOOKUP_FDO_THEME
ELM_ICON_LOOKUP_THEME_FDO = enums.ELM_ICON_LOOKUP_THEME_FDO
ELM_ICON_LOOKUP_FDO = enums.ELM_ICON_LOOKUP_FDO
ELM_ICON_LOOKUP_THEME = enums.ELM_ICON_LOOKUP_THEME
ELM_OBJECT_SELECT_MODE_DEFAULT = enums.ELM_OBJECT_SELECT_MODE_DEFAULT
ELM_OBJECT_SELECT_MODE_ALWAYS = enums.ELM_OBJECT_SELECT_MODE_ALWAYS
ELM_OBJECT_SELECT_MODE_NONE = enums.ELM_OBJECT_SELECT_MODE_NONE
ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY = enums.ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY
ELM_OBJECT_SELECT_MODE_MAX = enums.ELM_OBJECT_SELECT_MODE_MAX
ELM_TOOLBAR_SHRINK_NONE = enums.ELM_TOOLBAR_SHRINK_NONE
ELM_TOOLBAR_SHRINK_HIDE = enums.ELM_TOOLBAR_SHRINK_HIDE
ELM_TOOLBAR_SHRINK_SCROLL = enums.ELM_TOOLBAR_SHRINK_SCROLL
ELM_TOOLBAR_SHRINK_MENU = enums.ELM_TOOLBAR_SHRINK_MENU
ELM_TOOLBAR_SHRINK_EXPAND = enums.ELM_TOOLBAR_SHRINK_EXPAND
ELM_TOOLBAR_SHRINK_LAST = enums.ELM_TOOLBAR_SHRINK_LAST
cdef class ToolbarItemState(object):
"""A state for a :py:class:`ToolbarItem`."""
cdef Elm_Toolbar_Item_State *obj
cdef object params
def __init__(self, ToolbarItem it, icon = None, label = None, callback = None, *args, **kwargs):
cdef Evas_Smart_Cb cb = NULL
if callback:
if not callable(callback):
raise TypeError("callback is not callable")
cb = _object_item_callback
self.params = (callback, args, kwargs)
self.obj = elm_toolbar_item_state_add(it.item, _cfruni(icon), _cfruni(label), cb, self)
if self.obj == NULL:
Py_DECREF(self)
cdef class ToolbarItem(ObjectItem):
"""
An item for the toolbar.
"""
def __init__(self, evasObject toolbar not None, icon = None, label = None,
callback = None, *args, **kargs):
cdef Evas_Object *ic = NULL
cdef Evas_Smart_Cb cb = NULL
if callback is not None:
if not callable(callback):
raise TypeError("callback is not callable")
cb = _object_item_callback
self.params = (callback, args, kargs)
item = elm_toolbar_item_append(toolbar.obj, _cfruni(icon), _cfruni(label), cb, self)
if item != NULL:
self._set_obj(item)
else:
Py_DECREF(self)
property next:
"""Get the item after ``item`` in toolbar.
.. note:: If it is the last item, ``None`` will be returned.
.. seealso:: :py:func:`Toolbar.item_append()`
:type: :py:class:`ToolbarItem`
"""
def __get__(self):
return _object_item_to_python(elm_toolbar_item_next_get(self.item))
def next_get(self):
return _object_item_to_python(elm_toolbar_item_next_get(self.item))
property prev:
"""Get the item before ``item`` in toolbar.
.. note:: If it is the first item, ``None`` will be returned.
.. seealso:: :py:func:`Toolbar.item_prepend()`
:type: :py:class:`ToolbarItem`
"""
def __get__(self):
return _object_item_to_python(elm_toolbar_item_prev_get(self.item))
def prev_get(self):
return _object_item_to_python(elm_toolbar_item_prev_get(self.item))
property priority:
"""The priority of a toolbar item.
This is used only when the toolbar shrink mode is set to
ELM_TOOLBAR_SHRINK_MENU or ELM_TOOLBAR_SHRINK_HIDE. When space is
less than required, items with low priority will be removed from the
toolbar and added to a dynamically-created menu, while items with
higher priority will remain on the toolbar, with the same order they
were added.
:type: int
"""
def __get__(self):
return elm_toolbar_item_priority_get(self.item)
def __set__(self, priority):
elm_toolbar_item_priority_set(self.item, priority)
def priority_set(self, priority):
elm_toolbar_item_priority_set(self.item, priority)
def priority_get(self):
return elm_toolbar_item_priority_get(self.item)
property selected:
"""The selected state of an item.
This reflects the selected state of the given item. ``True`` for
selected, ``False`` for not selected.
If a new item is selected the previously selected will be unselected.
Previously selected item can be get with function
:py:attr:`Toolbar.selected_item`.
Selected items will be highlighted.
.. seealso:: :py:attr:`Toolbar.selected_item_get()`
:type: bool
"""
def __set__(self, selected):
elm_toolbar_item_selected_set(self.item, selected)
def __get__(self):
return elm_toolbar_item_selected_get(self.item)
def selected_get(self):
return elm_toolbar_item_selected_get(self.item)
def selected_set(self, selected):
elm_toolbar_item_selected_set(self.item, selected)
property icon:
"""The icon associated with the item.
Toolbar will load icon image from fdo or current theme. This
behavior can be set by :py:attr:`Toolbar.icon_order_lookup` function.
If an absolute path is provided it will load it direct from a file.
.. seealso:: :py:attr:`Toolbar.icon_order_lookup`
:type: string
"""
def __get__(self):
return _ctouni(elm_toolbar_item_icon_get(self.item))
def __set__(self, ic):
elm_toolbar_item_icon_set(self.item, _cfruni(ic))
def icon_set(self, ic):
elm_toolbar_item_icon_set(self.item, _cfruni(ic))
def icon_get(self):
return _ctouni(elm_toolbar_item_icon_get(self.item))
property object:
"""Get the object of item.
:type: :py:class:`Object`
"""
def __get__(self):
return object_from_instance(elm_toolbar_item_object_get(self.item))
def object_get(self):
return object_from_instance(elm_toolbar_item_object_get(self.item))
property icon_object:
"""Get the icon object of item.
.. seealso::
:py:attr:`icon`,
:py:attr:`icon_file`, or
:py:attr:`icon_memfile` for details.
:type: :py:class:`Icon`
"""
def __get__(self):
return object_from_instance(elm_toolbar_item_icon_object_get(self.item))
def icon_object_get(self):
return object_from_instance(elm_toolbar_item_icon_object_get(self.item))
def icon_memfile_set(self, img, size, format, key):
"""Set the icon associated with item to an image in a binary buffer.
.. note:: The icon image set by this function can be changed
by :py:attr:`icon`.
:param img: The binary data that will be used as an image
:param size: The size of binary data ``img``
:type size: int
:param format: Optional format of ``img`` to pass to the image loader
:type format: string
:param key: Optional key of ``img`` to pass to the image loader (eg.
if ``img`` is an edje file)
:type key: string
:return: (``True`` = success, ``False`` = error)
:rtype: bool
"""
return False
#TODO: return bool(elm_toolbar_item_icon_memfile_set(self.item, img, size, format, key))
property icon_file:
"""Set the icon associated with item to an image in a binary buffer.
.. note:: The icon image set by this function can be changed
by :py:attr:`icon`.
:type: string or tuple of strings
"""
def __set__(self, value):
if isinstance(value, tuple):
file, key = value
else:
file = value
key = None
if not bool(elm_toolbar_item_icon_file_set(self.item, _cfruni(file), _cfruni(key))):
raise RuntimeError("Could not set icon_file.")
def icon_file_set(self, file, key):
return bool(elm_toolbar_item_icon_file_set(self.item, _cfruni(file), _cfruni(key)))
property separator:
"""Whether item is a separator or not.
Items aren't set as separator by default.
If set as separator it will display separator theme, so won't display
icons or label.
:type: bool
"""
def __set__(self, separator):
elm_toolbar_item_separator_set(self.item, separator)
def __get__(self):
return elm_toolbar_item_separator_get(self.item)
def separator_set(self, separator):
elm_toolbar_item_separator_set(self.item, separator)
def separator_get(self):
return elm_toolbar_item_separator_get(self.item)
property menu:
"""This property has two diffent functionalities. The object you get
from it is the :py:class:`Menu` object used by this toolbar item,
and setting it to True or False controls whether this item is a menu
or not.
If item wasn't set as menu item, getting the value of this property
sets it to be that.
Once it is set to be a menu, it can be manipulated through
:py:attr:`Toolbar.menu_parent` and the :py:class:`Menu` functions
and properties.
So, items to be displayed in this item's menu should be added with
:py:func:`Menu.item_add()`.
The following code exemplifies the most basic usage::
tb = Toolbar(win)
item = tb.item_append("refresh", "Menu")
item.menu = True
tb.menu_parent = win
menu = item.menu
menu.item_add(None, "edit-cut", "Cut")
menu_item = menu.item_add(None, "edit-copy", "Copy")
:type: bool
"""
def __get__(self):
cdef Evas_Object *menu
menu = elm_toolbar_item_menu_get(self.item)
if menu == NULL:
return None
else:
return Menu(None,