New elm widget: Combobox

with docs and example
This commit is contained in:
Davide Andreoli 2016-01-23 12:19:20 +01:00
parent 078d440e05
commit 4f8dfc195f
8 changed files with 276 additions and 0 deletions

View File

@ -0,0 +1,44 @@
.. currentmodule:: efl.elementary
Combobox
########
.. image:: /images/combobox-preview.png
Widget description
==================
This is a the classic combobox widget, it is the composition of a
:class:`Button`, an :class:`Entry`, a :class:`Genlist` and an :class:`Hover`.
Thus you can use all the functionality of the base classes on the
:class:`Combobox` itself.
Available styles
================
- ``default`` a normal combobox.
Emitted signals
===============
- ``dismissed``: The combobox hover has been dismissed.
- ``expanded``: The combobox hover has been expanded.
- ``clicked``: The combobox button has been clicked.
- ``item,selected``: An item has been selected (highlighted).
- ``item,pressed``: An item has been pressed (clicked).
- ``filter,done``: Item filtering on genlist is completed.
Inheritance diagram
===================
.. inheritance-diagram:: Combobox
:parts: 2
.. autoclass:: _Combobox
.. autoclass:: Combobox

View File

@ -402,6 +402,7 @@ Inheritance diagram
efl.elementary.Check
efl.elementary.Clock
efl.elementary.Colorselector
efl.elementary.Combobox
efl.elementary.Configuration
efl.elementary.Conformant
efl.elementary.Ctxpopup

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -610,6 +610,7 @@ include "calendar.pxi"
include "check.pxi"
include "clock.pxi"
include "colorselector.pxi"
include "combobox.pxi"
include "configuration.pxi"
include "conformant.pxi"
include "ctxpopup.pxi"

116
efl/elementary/combobox.pxi Normal file
View File

@ -0,0 +1,116 @@
# Copyright (C) 2007-2015 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 3 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 this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
#
include "combobox_cdef.pxi"
cdef class _Combobox(Object):
def __init__(self, evasObject parent, *args, **kwargs):
self._set_obj(elm_combobox_add(parent.obj))
self._set_properties_from_keyword_args(kwargs)
property expanded:
""" Returns whether the combobox is expanded or not.
:type: bool (**readonly**)
"""
def __get__(self):
return bool(elm_combobox_expanded_get(self.obj))
def expanded_get(self):
return bool(elm_combobox_expanded_get(self.obj))
def hover_begin(self):
""" This triggers the combobox popup from code, the same as if the user
had clicked the button.
"""
elm_combobox_hover_begin(self.obj)
def hover_end(self):
""" This dismisses the combobox popup as if the user had clicked
outside the hover.
"""
elm_combobox_hover_end(self.obj)
def callback_dismissed_add(self, func, *args, **kwargs):
""" The combobox hover has been dismissed """
self._callback_add("dismissed", func, args, kwargs)
def callback_dismissed_del(self, func):
self._callback_del("dismissed", func)
def callback_expanded_add(self, func, *args, **kwargs):
""" The combobox hover has been expanded """
self._callback_add("expanded", func, args, kwargs)
def callback_expanded_del(self, func):
self._callback_del("expanded", func)
def callback_clicked_add(self, func, *args, **kwargs):
""" The combobox button has been clicked """
self._callback_add("clicked", func, args, kwargs)
def callback_clicked_del(self, func):
self._callback_del("clicked", func)
def callback_item_selected_add(self, func, *args, **kwargs):
""" An item has been selected """
self._callback_add_full("item,selected", _cb_object_item_conv,
func, args, kwargs)
def callback_item_selected_del(self, func):
self._callback_del_full("item,selected", _cb_object_item_conv, func)
def callback_item_pressed_add(self, func, *args, **kwargs):
""" An item has been pressed """
self._callback_add_full("item,pressed", _cb_object_item_conv,
func, args, kwargs)
def callback_item_pressed_del(self, func):
self._callback_del_full("item,pressed", _cb_object_item_conv, func)
def callback_filter_done_add(self, func, *args, **kwargs):
""" Item filtering is done """
self._callback_add("filter,done", func, args, kwargs)
def callback_filter_done_del(self, func):
self._callback_del("filter,done", func)
class Combobox(_Combobox, Button, Entry, Genlist, Hover):
"""
This is the class that actually implements the widget.
.. versionadded:: 1.17
"""
def __init__(self, evasObject parent, *args, **kwargs):
"""Combobox(...)
:param parent: The parent object
:type parent: :py:class:`efl.evas.Object`
:param \**kwargs: All the remaining keyword arguments are interpreted
as properties of the instance
"""
_Combobox.__init__(self, parent, *args, **kwargs)
_object_mapping_register("Elm_Combobox", Combobox)

View File

@ -0,0 +1,9 @@
cdef extern from "Elementary.h":
ctypedef cEo Elm_Combobox
Evas_Object * elm_combobox_add(Evas_Object *parent)
Eina_Bool elm_combobox_expanded_get(const Elm_Combobox *obj)
void elm_combobox_hover_begin(Elm_Combobox *obj)
void elm_combobox_hover_end(Elm_Combobox *obj)

View File

@ -174,6 +174,7 @@ items = [
("Genlist 2", "test_genlist_2", "test_genlist_2"),
("Genlist Tree", "test_genlist_tree", "test_genlist_tree"),
("Genlist Group", "test_genlist_group", "test_genlist_group"),
("Genlist Filter", "test_genlist_filter", "test_genlist_filter"),
("Genlist Sorted", "test_genlist_sorted", "test_genlist_sorted"),
("Genlist Iteration", "test_genlist_iteration", "test_genlist_iteration"),
("Genlist Decorate Item Mode", "test_genlist_decorate", "test_genlist_decorate"),
@ -217,6 +218,7 @@ items = [
("Selectors", [
("Action Slider", "test_actionslider", "actionslider_clicked"),
("Color Selector", "test_colorselector", "colorselector_clicked"),
("Combobox", "test_combobox", "combobox_clicked"),
("Day Selector", "test_dayselector", "dayselector_clicked"),
("Disk Selector", "test_diskselector", "diskselector_clicked"),
("File Selector", "test_fileselector", "fileselector_clicked"),

View File

@ -0,0 +1,103 @@
#!/usr/bin/env python
# encoding: utf-8
from efl.evas import EVAS_HINT_EXPAND, EXPAND_BOTH, EXPAND_HORIZ, FILL_HORIZ, \
EVAS_ASPECT_CONTROL_VERTICAL
from efl import elementary as elm
from efl.elementary import StandardWindow, Box, Button, Icon, Separator, \
Combobox, GenlistItemClass
class ComboboxItemClass(GenlistItemClass):
def text_get(self, gl, part, item_data):
return item_data
def content_get(self, gl, part, item_data):
if part == 'elm.swallow.end':
return Icon(gl, standard='clock')
else:
return Icon(gl, standard='home')
def filter_get(self, gl, key, item_data):
if not key:
return True
if key.lower() in item_data.lower():
return True
return False
def btn_click_cb(btn, cbox):
if cbox.expanded:
cbox.hover_end()
else:
cbox.hover_begin()
def combobox_item_pressed_cb(cbox, item):
print("ITEM,PRESSED", item)
cbox.text = item.text
cbox.hover_end()
def combobox_changed_cb(cbox):
cbox.filter = cbox.text
def combobox_clicked(obj):
win = StandardWindow("combobox", "Combobox", autodel=True, size=(320, 500))
if obj is None:
win.callback_delete_request_add(lambda o: elm.exit())
bx = Box(win, size_hint_weight=EXPAND_BOTH)
win.resize_object_add(bx)
bx.show()
itc = ComboboxItemClass()
# combo 1 - a short list with callbacks
cbox1 = Combobox(win, size_hint_expand=EXPAND_HORIZ,
size_hint_fill=FILL_HORIZ)
cbox1.part_text_set("guide", "A short list (with callbacks attached)")
cbox1.callback_item_pressed_add(combobox_item_pressed_cb)
cbox1.callback_dismissed_add(lambda cbox: print("DISMISSED", cbox))
cbox1.callback_expanded_add(lambda cbox: print("EXPANDED", cbox))
cbox1.callback_clicked_add(lambda cbox: print("CLICKED", cbox))
cbox1.callback_item_selected_add(lambda cbox, item: print("ITEM,SELECTED", item))
for i in range(1, 7):
cbox1.item_append(itc, "Item # %d" % i)
bx.pack_end(cbox1)
cbox1.show()
# combo 2 - a long list with filtering
cbox2 = Combobox(win, size_hint_expand=EXPAND_HORIZ,
size_hint_fill=FILL_HORIZ)
cbox2.part_text_set("guide", "A long list (with item filtering)")
cbox2.callback_item_pressed_add(combobox_item_pressed_cb)
cbox2.callback_changed_add(combobox_changed_cb)
cbox2.callback_filter_done_add(lambda cbox: print("FILTER,DONE", cbox))
for i in range(1, 1001):
cbox2.item_append(itc, "Item # %d" % i)
bx.pack_end(cbox2)
cbox2.show()
# combo 3 - disabled
cbox3 = Combobox(win, text="Disabled Combobox", disabled=True,
size_hint_expand=EXPAND_HORIZ, size_hint_fill=FILL_HORIZ)
cbox3.part_text_set("guide", "A long list")
bx.pack_end(cbox3)
cbox3.show()
# expand-from-code button
bt = Button(win, text="Toggle first combo hover state")
bt.callback_clicked_add(btn_click_cb, cbox1)
bx.pack_start(bt)
bt.show()
#
win.show()
if __name__ == "__main__":
combobox_clicked(None)
elm.run()