Genlist: implemented search_by_text_item_get(), with a proper test
This commit is contained in:
parent
401145f4fa
commit
d8174aea3d
|
@ -188,6 +188,12 @@ cdef extern from "Elementary.h":
|
|||
ELM_GENLIST_ITEM_SCROLLTO_TOP
|
||||
ELM_GENLIST_ITEM_SCROLLTO_MIDDLE
|
||||
|
||||
ctypedef enum Elm_Glob_Match_Flags:
|
||||
ELM_GLOB_MATCH_NO_ESCAPE
|
||||
ELM_GLOB_MATCH_PATH
|
||||
ELM_GLOB_MATCH_PERIOD
|
||||
ELM_GLOB_MATCH_NOCASE
|
||||
|
||||
ctypedef enum Elm_Gesture_State:
|
||||
ELM_GESTURE_STATE_UNDEFINED
|
||||
ELM_GESTURE_STATE_START
|
||||
|
|
|
@ -177,6 +177,43 @@ Urgency levels of a notification
|
|||
.. versionadded:: 1.10
|
||||
|
||||
|
||||
.. _Elm_Glob_Match_Flags:
|
||||
|
||||
Glob matching
|
||||
-------------
|
||||
|
||||
Glob matching bitfiled flags
|
||||
|
||||
.. data:: ELM_GLOB_MATCH_NO_ESCAPE
|
||||
|
||||
Treat backslash as an ordinary character instead of escape.
|
||||
|
||||
.. versionadded:: 1.11
|
||||
|
||||
.. data:: ELM_GLOB_MATCH_PATH
|
||||
|
||||
Match a slash in string only with a slash in pattern and not by an
|
||||
asterisk (*) or a question mark (?) metacharacter, nor by a bracket
|
||||
expression ([]) containing a slash.
|
||||
|
||||
.. versionadded:: 1.11
|
||||
|
||||
.. data:: ELM_GLOB_MATCH_PERIOD
|
||||
|
||||
Leading period in string has to be matched exactly by a period in
|
||||
pattern. A period is considered to be leading if it is the first
|
||||
character in string, or if both ELM_GLOB_MATCH_PATH is set and the
|
||||
period immediately follows a slash.
|
||||
|
||||
.. versionadded:: 1.11
|
||||
|
||||
.. data:: ELM_GLOB_MATCH_NOCASE
|
||||
|
||||
The pattern is matched case-insensitively.
|
||||
|
||||
.. versionadded:: 1.11
|
||||
|
||||
|
||||
"""
|
||||
|
||||
from 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
|
|||
ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED = enums.ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED
|
||||
ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED = enums.ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED
|
||||
|
||||
ELM_GLOB_MATCH_NO_ESCAPE = enums.ELM_GLOB_MATCH_NO_ESCAPE
|
||||
ELM_GLOB_MATCH_PATH = enums.ELM_GLOB_MATCH_PATH
|
||||
ELM_GLOB_MATCH_PERIOD = enums.ELM_GLOB_MATCH_PERIOD
|
||||
ELM_GLOB_MATCH_NOCASE = enums.ELM_GLOB_MATCH_NOCASE
|
||||
|
||||
import traceback
|
||||
|
||||
cdef void py_elm_sys_notify_send_cb(void *data, unsigned int id):
|
||||
|
|
|
@ -4,7 +4,7 @@ from object_item cimport Elm_Object_Item
|
|||
from general cimport Elm_Tooltip_Item_Content_Cb
|
||||
from enums cimport Elm_List_Mode, Elm_Object_Select_Mode, \
|
||||
Elm_Genlist_Item_Type, Elm_Genlist_Item_Scrollto_Type, \
|
||||
Elm_Genlist_Item_Field_Type
|
||||
Elm_Genlist_Item_Field_Type, Elm_Glob_Match_Flags
|
||||
|
||||
cdef extern from "Elementary.h":
|
||||
ctypedef char *(*GenlistItemLabelGetFunc) (void *data, Evas_Object *obj, const char *part)
|
||||
|
@ -81,6 +81,7 @@ cdef extern from "Elementary.h":
|
|||
void elm_genlist_longpress_timeout_set(Evas_Object *obj, double timeout)
|
||||
double elm_genlist_longpress_timeout_get(const Evas_Object *obj)
|
||||
Elm_Object_Item * elm_genlist_at_xy_item_get(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *posret)
|
||||
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)
|
||||
|
||||
Elm_Object_Item * elm_genlist_item_parent_get(const Elm_Object_Item *it)
|
||||
void elm_genlist_item_subitems_clear(Elm_Object_Item *item)
|
||||
|
|
|
@ -634,6 +634,47 @@ cdef class Genlist(Object):
|
|||
"""
|
||||
return _object_item_to_python(elm_genlist_nth_item_get(self.obj, nth))
|
||||
|
||||
def search_by_text_item_get(self, GenlistItem item_to_search_from,
|
||||
part_name, pattern, Elm_Glob_Match_Flags flags):
|
||||
"""Search genlist item by given string.
|
||||
|
||||
This function uses globs (like "\*.jpg") for searching and takes
|
||||
search flags as last parameter. That is a bitfield with values
|
||||
to be ored together or 0 for no flags.
|
||||
|
||||
:param item_to_search_from: item to start search from, or None to
|
||||
search from the first item.
|
||||
:type item_to_search_from: :py:class:`GenlistItem`
|
||||
:param part_name: Name of the TEXT part of genlist item to search
|
||||
string in (usually "elm.text").
|
||||
:type part_name: string
|
||||
:param pattern: The search pattern.
|
||||
:type pattern: string
|
||||
:param flags: Search flags
|
||||
:type flags: :ref:`Elm_Glob_Match_Flags`
|
||||
|
||||
:return: The first item found
|
||||
:rtype: :py:class:`GenlistItem`
|
||||
|
||||
.. versionadded:: 1.11
|
||||
|
||||
"""
|
||||
cdef Elm_Object_Item *from_item = NULL
|
||||
|
||||
if isinstance(part_name, unicode):
|
||||
part_name = PyUnicode_AsUTF8String(part_name)
|
||||
if isinstance(pattern, unicode):
|
||||
pattern = PyUnicode_AsUTF8String(pattern)
|
||||
if item_to_search_from is not None:
|
||||
from_item = _object_item_from_python(item_to_search_from)
|
||||
|
||||
return _object_item_to_python(elm_genlist_search_by_text_item_get(
|
||||
self.obj, from_item,
|
||||
<const char *>part_name if part_name is not None else NULL,
|
||||
<const char *>pattern if pattern is not None else NULL,
|
||||
flags))
|
||||
|
||||
|
||||
property focus_on_selection:
|
||||
"""
|
||||
|
||||
|
|
|
@ -181,6 +181,7 @@ items = [
|
|||
("Genlist Iteration", "test_genlist", "genlist5_clicked"),
|
||||
("Genlist Decorate Item Mode", "test_genlist", "genlist10_clicked"),
|
||||
("Genlist Decorate All Mode", "test_genlist", "genlist15_clicked"),
|
||||
("Genlist Search By Text", "test_genlist", "genlist20_clicked"),
|
||||
("List", "test_list", "list_clicked"),
|
||||
("List 2", "test_list", "list2_clicked"),
|
||||
("List 3", "test_list", "list3_clicked"),
|
||||
|
|
|
@ -23,9 +23,10 @@ from efl.elementary.genlist import Genlist, GenlistItem, GenlistItemClass, \
|
|||
ELM_GENLIST_ITEM_NONE, ELM_OBJECT_SELECT_MODE_ALWAYS, \
|
||||
ELM_OBJECT_SELECT_MODE_DEFAULT, ELM_GENLIST_ITEM_GROUP, \
|
||||
ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY
|
||||
from efl.elementary.general import cache_all_flush
|
||||
from efl.elementary.general import cache_all_flush, ELM_GLOB_MATCH_NOCASE
|
||||
from efl.elementary.radio import Radio
|
||||
from efl.elementary.check import Check
|
||||
from efl.elementary.entry import Entry
|
||||
|
||||
EXPAND_BOTH = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
|
||||
EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0
|
||||
|
@ -647,6 +648,88 @@ def genlist15_clicked(obj, item=None):
|
|||
|
||||
win.show()
|
||||
|
||||
### Genlist search by text
|
||||
cities = ("Albany","Annapolis","Atlanta","Augusta","Austin","Baton Rouge",
|
||||
"Bismarck","Boise","Boston","Carson City","Charleston","Cheyenne","Columbia",
|
||||
"Columbus","Concord","Denver","Des Moines","Dover","Frankfort","Harrisburg",
|
||||
"Hartford","Helena","Honolulu","Indianapolis","Jackson","Jefferson City",
|
||||
"Juneau","Lansing","Lincoln","Little Rock","Madison","Montgomery","Montpelier",
|
||||
"Nashville","Oklahoma City","Olympia","Phoenix","Pierre","Providence",
|
||||
"Raleigh","Richmond","Sacramento","Saint Paul","Salem","Salt Lake City",
|
||||
"Santa Fe","Springfield","Tallahassee","Topeka","Trenton"
|
||||
)
|
||||
|
||||
class ItemClass20(GenlistItemClass):
|
||||
def text_get(self, obj, part, data):
|
||||
if part == "elm.text":
|
||||
return data
|
||||
|
||||
def content_get(self, obj, part, data):
|
||||
if part == "elm.swallow.icon":
|
||||
return Icon(obj, file=os.path.join(img_path, "logo_small.png"))
|
||||
|
||||
def genlist20_search_cb(en, gl, tg):
|
||||
flags = ELM_GLOB_MATCH_NOCASE if tg.state == False else 0
|
||||
from_item = gl.selected_item.next if gl.selected_item else None
|
||||
|
||||
item = gl.search_by_text_item_get(from_item, "elm.text", en.text, flags)
|
||||
if item:
|
||||
item.selected = True
|
||||
en.focus = True
|
||||
elif gl.selected_item:
|
||||
gl.selected_item.selected = False
|
||||
|
||||
|
||||
def genlist20_clicked(obj, item=None):
|
||||
win = StandardWindow("genlist-search-by-text",
|
||||
"Genlist Search By Text", autodel=True, size=(300, 520))
|
||||
|
||||
gl = Genlist(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
|
||||
|
||||
bx = Box(win, size_hint_weight=EXPAND_BOTH)
|
||||
win.resize_object_add(bx)
|
||||
bx.show()
|
||||
|
||||
lb = Label(win)
|
||||
lb.text = \
|
||||
"<align=left>This example show the usage of search_by_text_item_get().<br>" \
|
||||
"Enter a search string and press Enter to show the next result.<br>" \
|
||||
"Search will start from the selected item (not included).<br>" \
|
||||
"You can search using glob patterns.</align>"
|
||||
fr = Frame(win, text="Information", content=lb,
|
||||
size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
|
||||
bx.pack_end(fr)
|
||||
fr.show()
|
||||
|
||||
tg = Check(win, style="toggle", text="Case Sensitive Search");
|
||||
bx.pack_end(tg)
|
||||
tg.show()
|
||||
|
||||
bx_entry = Box(win, horizontal=True,
|
||||
size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
|
||||
bx.pack_end(bx_entry)
|
||||
bx_entry.show()
|
||||
|
||||
lb = Label(win, text="Search:")
|
||||
bx_entry.pack_end(lb)
|
||||
lb.show()
|
||||
|
||||
en = Entry(win, single_line=True, scrollable=True,
|
||||
size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
|
||||
en.part_text_set("guide", "Type the search query")
|
||||
en.callback_activated_add(genlist20_search_cb, gl, tg)
|
||||
bx_entry.pack_end(en)
|
||||
en.show()
|
||||
en.focus = True
|
||||
|
||||
bx.pack_end(gl)
|
||||
gl.show()
|
||||
|
||||
itc20 = ItemClass20()
|
||||
for name in cities:
|
||||
gl.item_append(itc20, name)
|
||||
|
||||
win.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
elementary.init()
|
||||
|
@ -676,6 +759,7 @@ if __name__ == "__main__":
|
|||
("Genlist Iteration", genlist5_clicked),
|
||||
("Genlist Decorate Item Mode", genlist10_clicked),
|
||||
("Genlist Decorate All Mode", genlist15_clicked),
|
||||
("Genlist Search By Text", genlist20_clicked),
|
||||
]
|
||||
|
||||
li = List(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
|
||||
|
|
Loading…
Reference in New Issue