summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2016-01-23 12:19:20 +0100
committerDave Andreoli <dave@gurumeditation.it>2016-01-23 12:19:20 +0100
commit4f8dfc195f98bd1a12efe4f1c5d2259e75d2b4c1 (patch)
treec4d4d9d448e30a238fb7029a955782141faf0eaf
parent078d440e05c370daeada4c1ad3f3526a74844995 (diff)
New elm widget: Combobox
with docs and example
-rw-r--r--doc/elementary/combobox.rst44
-rw-r--r--doc/elementary/elementary.rst1
-rw-r--r--doc/images/combobox-preview.pngbin0 -> 30083 bytes
-rw-r--r--efl/elementary/__init__.pyx1
-rw-r--r--efl/elementary/combobox.pxi116
-rw-r--r--efl/elementary/combobox_cdef.pxi9
-rwxr-xr-xexamples/elementary/test.py2
-rw-r--r--examples/elementary/test_combobox.py103
8 files changed, 276 insertions, 0 deletions
diff --git a/doc/elementary/combobox.rst b/doc/elementary/combobox.rst
new file mode 100644
index 0000000..713416a
--- /dev/null
+++ b/doc/elementary/combobox.rst
@@ -0,0 +1,44 @@
1.. currentmodule:: efl.elementary
2
3Combobox
4########
5
6.. image:: /images/combobox-preview.png
7
8
9Widget description
10==================
11
12This is a the classic combobox widget, it is the composition of a
13:class:`Button`, an :class:`Entry`, a :class:`Genlist` and an :class:`Hover`.
14Thus you can use all the functionality of the base classes on the
15:class:`Combobox` itself.
16
17
18Available styles
19================
20
21- ``default`` a normal combobox.
22
23
24Emitted signals
25===============
26
27- ``dismissed``: The combobox hover has been dismissed.
28- ``expanded``: The combobox hover has been expanded.
29- ``clicked``: The combobox button has been clicked.
30- ``item,selected``: An item has been selected (highlighted).
31- ``item,pressed``: An item has been pressed (clicked).
32- ``filter,done``: Item filtering on genlist is completed.
33
34
35Inheritance diagram
36===================
37
38.. inheritance-diagram:: Combobox
39 :parts: 2
40
41
42.. autoclass:: _Combobox
43.. autoclass:: Combobox
44
diff --git a/doc/elementary/elementary.rst b/doc/elementary/elementary.rst
index 6349fa0..f1a81a3 100644
--- a/doc/elementary/elementary.rst
+++ b/doc/elementary/elementary.rst
@@ -402,6 +402,7 @@ Inheritance diagram
402 efl.elementary.Check 402 efl.elementary.Check
403 efl.elementary.Clock 403 efl.elementary.Clock
404 efl.elementary.Colorselector 404 efl.elementary.Colorselector
405 efl.elementary.Combobox
405 efl.elementary.Configuration 406 efl.elementary.Configuration
406 efl.elementary.Conformant 407 efl.elementary.Conformant
407 efl.elementary.Ctxpopup 408 efl.elementary.Ctxpopup
diff --git a/doc/images/combobox-preview.png b/doc/images/combobox-preview.png
new file mode 100644
index 0000000..73250f4
--- /dev/null
+++ b/doc/images/combobox-preview.png
Binary files differ
diff --git a/efl/elementary/__init__.pyx b/efl/elementary/__init__.pyx
index 2c0ca00..b3f7382 100644
--- a/efl/elementary/__init__.pyx
+++ b/efl/elementary/__init__.pyx
@@ -610,6 +610,7 @@ include "calendar.pxi"
610include "check.pxi" 610include "check.pxi"
611include "clock.pxi" 611include "clock.pxi"
612include "colorselector.pxi" 612include "colorselector.pxi"
613include "combobox.pxi"
613include "configuration.pxi" 614include "configuration.pxi"
614include "conformant.pxi" 615include "conformant.pxi"
615include "ctxpopup.pxi" 616include "ctxpopup.pxi"
diff --git a/efl/elementary/combobox.pxi b/efl/elementary/combobox.pxi
new file mode 100644
index 0000000..5253468
--- /dev/null
+++ b/efl/elementary/combobox.pxi
@@ -0,0 +1,116 @@
1# Copyright (C) 2007-2015 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 3 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17#
18
19include "combobox_cdef.pxi"
20
21cdef class _Combobox(Object):
22 def __init__(self, evasObject parent, *args, **kwargs):
23 self._set_obj(elm_combobox_add(parent.obj))
24 self._set_properties_from_keyword_args(kwargs)
25
26 property expanded:
27 """ Returns whether the combobox is expanded or not.
28
29 :type: bool (**readonly**)
30
31 """
32 def __get__(self):
33 return bool(elm_combobox_expanded_get(self.obj))
34
35 def expanded_get(self):
36 return bool(elm_combobox_expanded_get(self.obj))
37
38 def hover_begin(self):
39 """ This triggers the combobox popup from code, the same as if the user
40 had clicked the button.
41 """
42 elm_combobox_hover_begin(self.obj)
43
44 def hover_end(self):
45 """ This dismisses the combobox popup as if the user had clicked
46 outside the hover.
47 """
48 elm_combobox_hover_end(self.obj)
49
50 def callback_dismissed_add(self, func, *args, **kwargs):
51 """ The combobox hover has been dismissed """
52 self._callback_add("dismissed", func, args, kwargs)
53
54 def callback_dismissed_del(self, func):
55 self._callback_del("dismissed", func)
56
57 def callback_expanded_add(self, func, *args, **kwargs):
58 """ The combobox hover has been expanded """
59 self._callback_add("expanded", func, args, kwargs)
60
61 def callback_expanded_del(self, func):
62 self._callback_del("expanded", func)
63
64 def callback_clicked_add(self, func, *args, **kwargs):
65 """ The combobox button has been clicked """
66 self._callback_add("clicked", func, args, kwargs)
67
68 def callback_clicked_del(self, func):
69 self._callback_del("clicked", func)
70
71 def callback_item_selected_add(self, func, *args, **kwargs):
72 """ An item has been selected """
73 self._callback_add_full("item,selected", _cb_object_item_conv,
74 func, args, kwargs)
75
76 def callback_item_selected_del(self, func):
77 self._callback_del_full("item,selected", _cb_object_item_conv, func)
78
79 def callback_item_pressed_add(self, func, *args, **kwargs):
80 """ An item has been pressed """
81 self._callback_add_full("item,pressed", _cb_object_item_conv,
82 func, args, kwargs)
83
84 def callback_item_pressed_del(self, func):
85 self._callback_del_full("item,pressed", _cb_object_item_conv, func)
86
87 def callback_filter_done_add(self, func, *args, **kwargs):
88 """ Item filtering is done """
89 self._callback_add("filter,done", func, args, kwargs)
90
91 def callback_filter_done_del(self, func):
92 self._callback_del("filter,done", func)
93
94
95class Combobox(_Combobox, Button, Entry, Genlist, Hover):
96 """
97
98 This is the class that actually implements the widget.
99
100 .. versionadded:: 1.17
101
102 """
103 def __init__(self, evasObject parent, *args, **kwargs):
104 """Combobox(...)
105
106 :param parent: The parent object
107 :type parent: :py:class:`efl.evas.Object`
108 :param \**kwargs: All the remaining keyword arguments are interpreted
109 as properties of the instance
110
111 """
112 _Combobox.__init__(self, parent, *args, **kwargs)
113
114
115
116_object_mapping_register("Elm_Combobox", Combobox)
diff --git a/efl/elementary/combobox_cdef.pxi b/efl/elementary/combobox_cdef.pxi
new file mode 100644
index 0000000..8df1cdc
--- /dev/null
+++ b/efl/elementary/combobox_cdef.pxi
@@ -0,0 +1,9 @@
1cdef extern from "Elementary.h":
2
3 ctypedef cEo Elm_Combobox
4
5 Evas_Object * elm_combobox_add(Evas_Object *parent)
6 Eina_Bool elm_combobox_expanded_get(const Elm_Combobox *obj)
7 void elm_combobox_hover_begin(Elm_Combobox *obj)
8 void elm_combobox_hover_end(Elm_Combobox *obj)
9
diff --git a/examples/elementary/test.py b/examples/elementary/test.py
index 486a5fb..f2e984d 100755
--- a/examples/elementary/test.py
+++ b/examples/elementary/test.py
@@ -174,6 +174,7 @@ items = [
174 ("Genlist 2", "test_genlist_2", "test_genlist_2"), 174 ("Genlist 2", "test_genlist_2", "test_genlist_2"),
175 ("Genlist Tree", "test_genlist_tree", "test_genlist_tree"), 175 ("Genlist Tree", "test_genlist_tree", "test_genlist_tree"),
176 ("Genlist Group", "test_genlist_group", "test_genlist_group"), 176 ("Genlist Group", "test_genlist_group", "test_genlist_group"),
177 ("Genlist Filter", "test_genlist_filter", "test_genlist_filter"),
177 ("Genlist Sorted", "test_genlist_sorted", "test_genlist_sorted"), 178 ("Genlist Sorted", "test_genlist_sorted", "test_genlist_sorted"),
178 ("Genlist Iteration", "test_genlist_iteration", "test_genlist_iteration"), 179 ("Genlist Iteration", "test_genlist_iteration", "test_genlist_iteration"),
179 ("Genlist Decorate Item Mode", "test_genlist_decorate", "test_genlist_decorate"), 180 ("Genlist Decorate Item Mode", "test_genlist_decorate", "test_genlist_decorate"),
@@ -217,6 +218,7 @@ items = [
217 ("Selectors", [ 218 ("Selectors", [
218 ("Action Slider", "test_actionslider", "actionslider_clicked"), 219 ("Action Slider", "test_actionslider", "actionslider_clicked"),
219 ("Color Selector", "test_colorselector", "colorselector_clicked"), 220 ("Color Selector", "test_colorselector", "colorselector_clicked"),
221 ("Combobox", "test_combobox", "combobox_clicked"),
220 ("Day Selector", "test_dayselector", "dayselector_clicked"), 222 ("Day Selector", "test_dayselector", "dayselector_clicked"),
221 ("Disk Selector", "test_diskselector", "diskselector_clicked"), 223 ("Disk Selector", "test_diskselector", "diskselector_clicked"),
222 ("File Selector", "test_fileselector", "fileselector_clicked"), 224 ("File Selector", "test_fileselector", "fileselector_clicked"),
diff --git a/examples/elementary/test_combobox.py b/examples/elementary/test_combobox.py
new file mode 100644
index 0000000..632e92e
--- /dev/null
+++ b/examples/elementary/test_combobox.py
@@ -0,0 +1,103 @@
1#!/usr/bin/env python
2# encoding: utf-8
3
4from efl.evas import EVAS_HINT_EXPAND, EXPAND_BOTH, EXPAND_HORIZ, FILL_HORIZ, \
5 EVAS_ASPECT_CONTROL_VERTICAL
6from efl import elementary as elm
7from efl.elementary import StandardWindow, Box, Button, Icon, Separator, \
8 Combobox, GenlistItemClass
9
10
11class ComboboxItemClass(GenlistItemClass):
12 def text_get(self, gl, part, item_data):
13 return item_data
14
15 def content_get(self, gl, part, item_data):
16 if part == 'elm.swallow.end':
17 return Icon(gl, standard='clock')
18 else:
19 return Icon(gl, standard='home')
20
21 def filter_get(self, gl, key, item_data):
22 if not key:
23 return True
24 if key.lower() in item_data.lower():
25 return True
26 return False
27
28
29def btn_click_cb(btn, cbox):
30 if cbox.expanded:
31 cbox.hover_end()
32 else:
33 cbox.hover_begin()
34
35def combobox_item_pressed_cb(cbox, item):
36 print("ITEM,PRESSED", item)
37 cbox.text = item.text
38 cbox.hover_end()
39
40def combobox_changed_cb(cbox):
41 cbox.filter = cbox.text
42
43
44def combobox_clicked(obj):
45 win = StandardWindow("combobox", "Combobox", autodel=True, size=(320, 500))
46 if obj is None:
47 win.callback_delete_request_add(lambda o: elm.exit())
48
49 bx = Box(win, size_hint_weight=EXPAND_BOTH)
50 win.resize_object_add(bx)
51 bx.show()
52
53 itc = ComboboxItemClass()
54
55 # combo 1 - a short list with callbacks
56 cbox1 = Combobox(win, size_hint_expand=EXPAND_HORIZ,
57 size_hint_fill=FILL_HORIZ)
58 cbox1.part_text_set("guide", "A short list (with callbacks attached)")
59 cbox1.callback_item_pressed_add(combobox_item_pressed_cb)
60 cbox1.callback_dismissed_add(lambda cbox: print("DISMISSED", cbox))
61 cbox1.callback_expanded_add(lambda cbox: print("EXPANDED", cbox))
62 cbox1.callback_clicked_add(lambda cbox: print("CLICKED", cbox))
63 cbox1.callback_item_selected_add(lambda cbox, item: print("ITEM,SELECTED", item))
64
65 for i in range(1, 7):
66 cbox1.item_append(itc, "Item # %d" % i)
67 bx.pack_end(cbox1)
68 cbox1.show()
69
70 # combo 2 - a long list with filtering
71 cbox2 = Combobox(win, size_hint_expand=EXPAND_HORIZ,
72 size_hint_fill=FILL_HORIZ)
73 cbox2.part_text_set("guide", "A long list (with item filtering)")
74 cbox2.callback_item_pressed_add(combobox_item_pressed_cb)
75 cbox2.callback_changed_add(combobox_changed_cb)
76 cbox2.callback_filter_done_add(lambda cbox: print("FILTER,DONE", cbox))
77
78 for i in range(1, 1001):
79 cbox2.item_append(itc, "Item # %d" % i)
80 bx.pack_end(cbox2)
81 cbox2.show()
82
83 # combo 3 - disabled
84 cbox3 = Combobox(win, text="Disabled Combobox", disabled=True,
85 size_hint_expand=EXPAND_HORIZ, size_hint_fill=FILL_HORIZ)
86 cbox3.part_text_set("guide", "A long list")
87 bx.pack_end(cbox3)
88 cbox3.show()
89
90 # expand-from-code button
91 bt = Button(win, text="Toggle first combo hover state")
92 bt.callback_clicked_add(btn_click_cb, cbox1)
93 bx.pack_start(bt)
94 bt.show()
95
96 #
97 win.show()
98
99
100if __name__ == "__main__":
101 combobox_clicked(None)
102 elm.run()
103