summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2014-08-01 16:31:24 +0200
committerdavemds <dave@gurumeditation.it>2014-08-01 16:31:24 +0200
commitd8174aea3d6f185eca3a84934ef4bba67d713b91 (patch)
tree392ccbe8c783d99e118235fcdc6fd1394bbb00be
parent401145f4fa5eb54ba962b59de79390dc9cec19dc (diff)
Genlist: implemented search_by_text_item_get(), with a proper test
-rw-r--r--efl/elementary/enums.pxd6
-rw-r--r--efl/elementary/general.pyx42
-rw-r--r--efl/elementary/genlist.pxd3
-rw-r--r--efl/elementary/genlist_widget.pxi41
-rwxr-xr-xexamples/elementary/test.py1
-rw-r--r--examples/elementary/test_genlist.py86
6 files changed, 177 insertions, 2 deletions
diff --git a/efl/elementary/enums.pxd b/efl/elementary/enums.pxd
index 624f01d..87ea2e9 100644
--- a/efl/elementary/enums.pxd
+++ b/efl/elementary/enums.pxd
@@ -188,6 +188,12 @@ cdef extern from "Elementary.h":
188 ELM_GENLIST_ITEM_SCROLLTO_TOP 188 ELM_GENLIST_ITEM_SCROLLTO_TOP
189 ELM_GENLIST_ITEM_SCROLLTO_MIDDLE 189 ELM_GENLIST_ITEM_SCROLLTO_MIDDLE
190 190
191 ctypedef enum Elm_Glob_Match_Flags:
192 ELM_GLOB_MATCH_NO_ESCAPE
193 ELM_GLOB_MATCH_PATH
194 ELM_GLOB_MATCH_PERIOD
195 ELM_GLOB_MATCH_NOCASE
196
191 ctypedef enum Elm_Gesture_State: 197 ctypedef enum Elm_Gesture_State:
192 ELM_GESTURE_STATE_UNDEFINED 198 ELM_GESTURE_STATE_UNDEFINED
193 ELM_GESTURE_STATE_START 199 ELM_GESTURE_STATE_START
diff --git a/efl/elementary/general.pyx b/efl/elementary/general.pyx
index 13d50e4..be3a096 100644
--- a/efl/elementary/general.pyx
+++ b/efl/elementary/general.pyx
@@ -177,6 +177,43 @@ Urgency levels of a notification
177 .. versionadded:: 1.10 177 .. versionadded:: 1.10
178 178
179 179
180.. _Elm_Glob_Match_Flags:
181
182Glob matching
183-------------
184
185Glob matching bitfiled flags
186
187.. data:: ELM_GLOB_MATCH_NO_ESCAPE
188
189 Treat backslash as an ordinary character instead of escape.
190
191 .. versionadded:: 1.11
192
193.. data:: ELM_GLOB_MATCH_PATH
194
195 Match a slash in string only with a slash in pattern and not by an
196 asterisk (*) or a question mark (?) metacharacter, nor by a bracket
197 expression ([]) containing a slash.
198
199 .. versionadded:: 1.11
200
201.. data:: ELM_GLOB_MATCH_PERIOD
202
203 Leading period in string has to be matched exactly by a period in
204 pattern. A period is considered to be leading if it is the first
205 character in string, or if both ELM_GLOB_MATCH_PATH is set and the
206 period immediately follows a slash.
207
208 .. versionadded:: 1.11
209
210.. data:: ELM_GLOB_MATCH_NOCASE
211
212 The pattern is matched case-insensitively.
213
214 .. versionadded:: 1.11
215
216
180""" 217"""
181 218
182from cpython cimport PyUnicode_AsUTF8String, PyMem_Malloc, Py_DECREF, Py_INCREF 219from cpython cimport PyUnicode_AsUTF8String, PyMem_Malloc, Py_DECREF, Py_INCREF
@@ -228,6 +265,11 @@ ELM_SYS_NOTIFY_URGENCY_CRITICAL = enums.ELM_SYS_NOTIFY_URGENCY_CRITICAL
228ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED = enums.ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED 265ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED = enums.ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
229ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED = enums.ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED 266ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED = enums.ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
230 267
268ELM_GLOB_MATCH_NO_ESCAPE = enums.ELM_GLOB_MATCH_NO_ESCAPE
269ELM_GLOB_MATCH_PATH = enums.ELM_GLOB_MATCH_PATH
270ELM_GLOB_MATCH_PERIOD = enums.ELM_GLOB_MATCH_PERIOD
271ELM_GLOB_MATCH_NOCASE = enums.ELM_GLOB_MATCH_NOCASE
272
231import traceback 273import traceback
232 274
233cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id): 275cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
diff --git a/efl/elementary/genlist.pxd b/efl/elementary/genlist.pxd
index 7941c48..0d8d367 100644
--- a/efl/elementary/genlist.pxd
+++ b/efl/elementary/genlist.pxd
@@ -4,7 +4,7 @@ from object_item cimport Elm_Object_Item
4from general cimport Elm_Tooltip_Item_Content_Cb 4from general cimport Elm_Tooltip_Item_Content_Cb
5from enums cimport Elm_List_Mode, Elm_Object_Select_Mode, \ 5from enums cimport Elm_List_Mode, Elm_Object_Select_Mode, \
6 Elm_Genlist_Item_Type, Elm_Genlist_Item_Scrollto_Type, \ 6 Elm_Genlist_Item_Type, Elm_Genlist_Item_Scrollto_Type, \
7 Elm_Genlist_Item_Field_Type 7 Elm_Genlist_Item_Field_Type, Elm_Glob_Match_Flags
8 8
9cdef extern from "Elementary.h": 9cdef extern from "Elementary.h":
10 ctypedef char *(*GenlistItemLabelGetFunc) (void *data, Evas_Object *obj, const char *part) 10 ctypedef char *(*GenlistItemLabelGetFunc) (void *data, Evas_Object *obj, const char *part)
@@ -81,6 +81,7 @@ cdef extern from "Elementary.h":
81 void elm_genlist_longpress_timeout_set(Evas_Object *obj, double timeout) 81 void elm_genlist_longpress_timeout_set(Evas_Object *obj, double timeout)
82 double elm_genlist_longpress_timeout_get(const Evas_Object *obj) 82 double elm_genlist_longpress_timeout_get(const Evas_Object *obj)
83 Elm_Object_Item * elm_genlist_at_xy_item_get(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *posret) 83 Elm_Object_Item * elm_genlist_at_xy_item_get(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *posret)
84 Elm_Object_Item * elm_genlist_search_by_text_item_get(const Evas_Object *obj, Elm_Object_Item *item_to_search_from, const char *part_name, const char *pattern, Elm_Glob_Match_Flags flags)
84 85
85 Elm_Object_Item * elm_genlist_item_parent_get(const Elm_Object_Item *it) 86 Elm_Object_Item * elm_genlist_item_parent_get(const Elm_Object_Item *it)
86 void elm_genlist_item_subitems_clear(Elm_Object_Item *item) 87 void elm_genlist_item_subitems_clear(Elm_Object_Item *item)
diff --git a/efl/elementary/genlist_widget.pxi b/efl/elementary/genlist_widget.pxi
index 68cf2a8..dcc0c2d 100644
--- a/efl/elementary/genlist_widget.pxi
+++ b/efl/elementary/genlist_widget.pxi
@@ -634,6 +634,47 @@ cdef class Genlist(Object):
634 """ 634 """
635 return _object_item_to_python(elm_genlist_nth_item_get(self.obj, nth)) 635 return _object_item_to_python(elm_genlist_nth_item_get(self.obj, nth))
636 636
637 def search_by_text_item_get(self, GenlistItem item_to_search_from,
638 part_name, pattern, Elm_Glob_Match_Flags flags):
639 """Search genlist item by given string.
640
641 This function uses globs (like "\*.jpg") for searching and takes
642 search flags as last parameter. That is a bitfield with values
643 to be ored together or 0 for no flags.
644
645 :param item_to_search_from: item to start search from, or None to
646 search from the first item.
647 :type item_to_search_from: :py:class:`GenlistItem`
648 :param part_name: Name of the TEXT part of genlist item to search
649 string in (usually "elm.text").
650 :type part_name: string
651 :param pattern: The search pattern.
652 :type pattern: string
653 :param flags: Search flags
654 :type flags: :ref:`Elm_Glob_Match_Flags`
655
656 :return: The first item found
657 :rtype: :py:class:`GenlistItem`
658
659 .. versionadded:: 1.11
660
661 """
662 cdef Elm_Object_Item *from_item = NULL
663
664 if isinstance(part_name, unicode):
665 part_name = PyUnicode_AsUTF8String(part_name)
666 if isinstance(pattern, unicode):
667 pattern = PyUnicode_AsUTF8String(pattern)
668 if item_to_search_from is not None:
669 from_item = _object_item_from_python(item_to_search_from)
670
671 return _object_item_to_python(elm_genlist_search_by_text_item_get(
672 self.obj, from_item,
673 <const char *>part_name if part_name is not None else NULL,
674 <const char *>pattern if pattern is not None else NULL,
675 flags))
676
677
637 property focus_on_selection: 678 property focus_on_selection:
638 """ 679 """
639 680
diff --git a/examples/elementary/test.py b/examples/elementary/test.py
index b0014f6..0f7f0dd 100755
--- a/examples/elementary/test.py
+++ b/examples/elementary/test.py
@@ -181,6 +181,7 @@ items = [
181 ("Genlist Iteration", "test_genlist", "genlist5_clicked"), 181 ("Genlist Iteration", "test_genlist", "genlist5_clicked"),
182 ("Genlist Decorate Item Mode", "test_genlist", "genlist10_clicked"), 182 ("Genlist Decorate Item Mode", "test_genlist", "genlist10_clicked"),
183 ("Genlist Decorate All Mode", "test_genlist", "genlist15_clicked"), 183 ("Genlist Decorate All Mode", "test_genlist", "genlist15_clicked"),
184 ("Genlist Search By Text", "test_genlist", "genlist20_clicked"),
184 ("List", "test_list", "list_clicked"), 185 ("List", "test_list", "list_clicked"),
185 ("List 2", "test_list", "list2_clicked"), 186 ("List 2", "test_list", "list2_clicked"),
186 ("List 3", "test_list", "list3_clicked"), 187 ("List 3", "test_list", "list3_clicked"),
diff --git a/examples/elementary/test_genlist.py b/examples/elementary/test_genlist.py
index 611cb86..6bdea80 100644
--- a/examples/elementary/test_genlist.py
+++ b/examples/elementary/test_genlist.py
@@ -23,9 +23,10 @@ from efl.elementary.genlist import Genlist, GenlistItem, GenlistItemClass, \
23 ELM_GENLIST_ITEM_NONE, ELM_OBJECT_SELECT_MODE_ALWAYS, \ 23 ELM_GENLIST_ITEM_NONE, ELM_OBJECT_SELECT_MODE_ALWAYS, \
24 ELM_OBJECT_SELECT_MODE_DEFAULT, ELM_GENLIST_ITEM_GROUP, \ 24 ELM_OBJECT_SELECT_MODE_DEFAULT, ELM_GENLIST_ITEM_GROUP, \
25 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY 25 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY
26from efl.elementary.general import cache_all_flush 26from efl.elementary.general import cache_all_flush, ELM_GLOB_MATCH_NOCASE
27from efl.elementary.radio import Radio 27from efl.elementary.radio import Radio
28from efl.elementary.check import Check 28from efl.elementary.check import Check
29from efl.elementary.entry import Entry
29 30
30EXPAND_BOTH = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND 31EXPAND_BOTH = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
31EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0 32EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0
@@ -647,6 +648,88 @@ def genlist15_clicked(obj, item=None):
647 648
648 win.show() 649 win.show()
649 650
651### Genlist search by text
652cities = ("Albany","Annapolis","Atlanta","Augusta","Austin","Baton Rouge",
653"Bismarck","Boise","Boston","Carson City","Charleston","Cheyenne","Columbia",
654"Columbus","Concord","Denver","Des Moines","Dover","Frankfort","Harrisburg",
655"Hartford","Helena","Honolulu","Indianapolis","Jackson","Jefferson City",
656"Juneau","Lansing","Lincoln","Little Rock","Madison","Montgomery","Montpelier",
657"Nashville","Oklahoma City","Olympia","Phoenix","Pierre","Providence",
658"Raleigh","Richmond","Sacramento","Saint Paul","Salem","Salt Lake City",
659"Santa Fe","Springfield","Tallahassee","Topeka","Trenton"
660)
661
662class ItemClass20(GenlistItemClass):
663 def text_get(self, obj, part, data):
664 if part == "elm.text":
665 return data
666
667 def content_get(self, obj, part, data):
668 if part == "elm.swallow.icon":
669 return Icon(obj, file=os.path.join(img_path, "logo_small.png"))
670
671def genlist20_search_cb(en, gl, tg):
672 flags = ELM_GLOB_MATCH_NOCASE if tg.state == False else 0
673 from_item = gl.selected_item.next if gl.selected_item else None
674
675 item = gl.search_by_text_item_get(from_item, "elm.text", en.text, flags)
676 if item:
677 item.selected = True
678 en.focus = True
679 elif gl.selected_item:
680 gl.selected_item.selected = False
681
682
683def genlist20_clicked(obj, item=None):
684 win = StandardWindow("genlist-search-by-text",
685 "Genlist Search By Text", autodel=True, size=(300, 520))
686
687 gl = Genlist(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
688
689 bx = Box(win, size_hint_weight=EXPAND_BOTH)
690 win.resize_object_add(bx)
691 bx.show()
692
693 lb = Label(win)
694 lb.text = \
695 "<align=left>This example show the usage of search_by_text_item_get().<br>" \
696 "Enter a search string and press Enter to show the next result.<br>" \
697 "Search will start from the selected item (not included).<br>" \
698 "You can search using glob patterns.</align>"
699 fr = Frame(win, text="Information", content=lb,
700 size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
701 bx.pack_end(fr)
702 fr.show()
703
704 tg = Check(win, style="toggle", text="Case Sensitive Search");
705 bx.pack_end(tg)
706 tg.show()
707
708 bx_entry = Box(win, horizontal=True,
709 size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
710 bx.pack_end(bx_entry)
711 bx_entry.show()
712
713 lb = Label(win, text="Search:")
714 bx_entry.pack_end(lb)
715 lb.show()
716
717 en = Entry(win, single_line=True, scrollable=True,
718 size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
719 en.part_text_set("guide", "Type the search query")
720 en.callback_activated_add(genlist20_search_cb, gl, tg)
721 bx_entry.pack_end(en)
722 en.show()
723 en.focus = True
724
725 bx.pack_end(gl)
726 gl.show()
727
728 itc20 = ItemClass20()
729 for name in cities:
730 gl.item_append(itc20, name)
731
732 win.show()
650 733
651if __name__ == "__main__": 734if __name__ == "__main__":
652 elementary.init() 735 elementary.init()
@@ -676,6 +759,7 @@ if __name__ == "__main__":
676 ("Genlist Iteration", genlist5_clicked), 759 ("Genlist Iteration", genlist5_clicked),
677 ("Genlist Decorate Item Mode", genlist10_clicked), 760 ("Genlist Decorate Item Mode", genlist10_clicked),
678 ("Genlist Decorate All Mode", genlist15_clicked), 761 ("Genlist Decorate All Mode", genlist15_clicked),
762 ("Genlist Search By Text", genlist20_clicked),
679 ] 763 ]
680 764
681 li = List(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) 765 li = List(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)