summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2014-08-01 17:31:09 +0200
committerdavemds <dave@gurumeditation.it>2014-08-01 17:31:09 +0200
commitf5dd70b70fd9e1ae529b6f55c1c81bff3677da16 (patch)
tree02fd93d3ed9ce9ef3572fc35d0e055a3793797da
parentd8174aea3d6f185eca3a84934ef4bba67d713b91 (diff)
Gengrid: implemented search_by_text_item_get(), with a proper test
-rw-r--r--efl/elementary/gengrid.pxd4
-rw-r--r--efl/elementary/gengrid_widget.pxi40
-rw-r--r--examples/elementary/test_gengrid.py30
3 files changed, 72 insertions, 2 deletions
diff --git a/efl/elementary/gengrid.pxd b/efl/elementary/gengrid.pxd
index cc705c6..a8f5bb9 100644
--- a/efl/elementary/gengrid.pxd
+++ b/efl/elementary/gengrid.pxd
@@ -4,7 +4,7 @@ from efl.c_eo cimport Eo
4from object_item cimport Elm_Object_Item 4from object_item cimport Elm_Object_Item
5from general cimport Elm_Tooltip_Item_Content_Cb 5from general cimport Elm_Tooltip_Item_Content_Cb
6from enums cimport Elm_Genlist_Item_Scrollto_Type, Elm_Object_Select_Mode, \ 6from enums cimport Elm_Genlist_Item_Scrollto_Type, Elm_Object_Select_Mode, \
7 Elm_Object_Multi_Select_Mode 7 Elm_Object_Multi_Select_Mode, Elm_Glob_Match_Flags
8from efl.ecore.enums cimport Ecore_Pos_Map 8from efl.ecore.enums cimport Ecore_Pos_Map
9 9
10cdef extern from "Elementary.h": 10cdef extern from "Elementary.h":
@@ -101,3 +101,5 @@ cdef extern from "Elementary.h":
101 Eina_Bool elm_gengrid_item_cursor_engine_only_get(const Elm_Object_Item *item) 101 Eina_Bool elm_gengrid_item_cursor_engine_only_get(const Elm_Object_Item *item)
102 Elm_Object_Item * elm_gengrid_nth_item_get(const Evas_Object *obj, unsigned int nth) 102 Elm_Object_Item * elm_gengrid_nth_item_get(const Evas_Object *obj, unsigned int nth)
103 Elm_Object_Item * elm_gengrid_at_xy_item_get(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *xposret, int *yposret) 103 Elm_Object_Item * elm_gengrid_at_xy_item_get(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *xposret, int *yposret)
104 Elm_Object_Item * elm_gengrid_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)
105
diff --git a/efl/elementary/gengrid_widget.pxi b/efl/elementary/gengrid_widget.pxi
index b0a8900..4e6af66 100644
--- a/efl/elementary/gengrid_widget.pxi
+++ b/efl/elementary/gengrid_widget.pxi
@@ -558,6 +558,46 @@ cdef class Gengrid(Object):
558 return _object_item_to_python(ret), xposret, yposret 558 return _object_item_to_python(ret), xposret, yposret
559 559
560 560
561 def search_by_text_item_get(self, GengridItem item_to_search_from,
562 part_name, pattern, Elm_Glob_Match_Flags flags):
563 """Search gengrid item by given string.
564
565 This function uses globs (like "\*.jpg") for searching and takes
566 search flags as last parameter. That is a bitfield with values
567 to be ored together or 0 for no flags.
568
569 :param item_to_search_from: item to start search from, or None to
570 search from the first item.
571 :type item_to_search_from: :py:class:`GengridItem`
572 :param part_name: Name of the TEXT part of gengrid item to search
573 string in (usually "elm.text").
574 :type part_name: string
575 :param pattern: The search pattern.
576 :type pattern: string
577 :param flags: Search flags
578 :type flags: :ref:`Elm_Glob_Match_Flags`
579
580 :return: The first item found
581 :rtype: :py:class:`GengridItem`
582
583 .. versionadded:: 1.11
584
585 """
586 cdef Elm_Object_Item *from_item = NULL
587
588 if isinstance(part_name, unicode):
589 part_name = PyUnicode_AsUTF8String(part_name)
590 if isinstance(pattern, unicode):
591 pattern = PyUnicode_AsUTF8String(pattern)
592 if item_to_search_from is not None:
593 from_item = _object_item_from_python(item_to_search_from)
594
595 return _object_item_to_python(elm_gengrid_search_by_text_item_get(
596 self.obj, from_item,
597 <const char *>part_name if part_name is not None else NULL,
598 <const char *>pattern if pattern is not None else NULL,
599 flags))
600
561 # 601 #
562 # TODO: Drag and Drop 602 # TODO: Drag and Drop
563 # ============= 603 # =============
diff --git a/examples/elementary/test_gengrid.py b/examples/elementary/test_gengrid.py
index a18d1d6..5d0cb2c 100644
--- a/examples/elementary/test_gengrid.py
+++ b/examples/elementary/test_gengrid.py
@@ -10,7 +10,10 @@ from efl.elementary.window import StandardWindow
10from efl.elementary.background import Background 10from efl.elementary.background import Background
11from efl.elementary.button import Button 11from efl.elementary.button import Button
12from efl.elementary.check import Check 12from efl.elementary.check import Check
13from efl.elementary.entry import Entry
13from efl.elementary.image import Image 14from efl.elementary.image import Image
15from efl.elementary.label import Label
16from efl.elementary.general import ELM_GLOB_MATCH_NOCASE
14from efl.elementary.gengrid import Gengrid, GengridItemClass 17from efl.elementary.gengrid import Gengrid, GengridItemClass
15from efl.elementary.slider import Slider 18from efl.elementary.slider import Slider
16from efl.elementary.table import Table 19from efl.elementary.table import Table
@@ -67,7 +70,7 @@ def gengrid_clicked(obj):
67 global item_count 70 global item_count
68 item_count = 25 71 item_count = 25
69 72
70 win = StandardWindow("gengrid", "Gengrid", autodel=True, size=(480, 800)) 73 win = StandardWindow("gengrid", "Gengrid", autodel=True, size=(480, 600))
71 if obj is None: 74 if obj is None:
72 win.callback_delete_request_add(lambda o: elementary.exit()) 75 win.callback_delete_request_add(lambda o: elementary.exit())
73 76
@@ -332,6 +335,31 @@ def gengrid_clicked(obj):
332 tb.pack(bt, 4, 5, 1, 1) 335 tb.pack(bt, 4, 5, 1, 1)
333 bt.show() 336 bt.show()
334 337
338 # search_by_text_item_get
339 def search_cb(en, gg):
340 flags = ELM_GLOB_MATCH_NOCASE
341 from_item = gg.selected_item.next if gg.selected_item else None
342
343 item = gg.search_by_text_item_get(from_item, "elm.text", en.text, flags)
344 if item:
345 item.selected = True
346 en.focus = True
347 elif gg.selected_item:
348 gg.selected_item.selected = False
349
350 lb = Label(win, text="Search:")
351 tb.pack(lb, 2, 6, 1, 1)
352 lb.show()
353
354 en = Entry(win, single_line=True, scrollable=True,
355 size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
356 en.part_text_set("guide", "Type the search query")
357 en.callback_activated_add(search_cb, gg)
358 tb.pack(en, 3, 6, 3, 1)
359 en.show()
360 en.focus = True
361
362
335 print(gg) 363 print(gg)
336 364
337 win.show() 365 win.show()