summaryrefslogtreecommitdiff
path: root/efl
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2016-01-20 22:55:43 +0100
committerDave Andreoli <dave@gurumeditation.it>2016-01-20 22:55:43 +0100
commit005dd26f73f0a634d16286362b80ce98e2e277a8 (patch)
tree35878d110c4e4baae022bd2016c4156cc0272bef /efl
parent90595ffdcada4bc3f6084165e13c87a5b3fbf8e2 (diff)
Implemented Genlist filter ability
It is somehow not perfectly working, see TODO for more info
Diffstat (limited to 'efl')
-rw-r--r--efl/elementary/genlist.pxi18
-rw-r--r--efl/elementary/genlist_cdef.pxi3
-rw-r--r--efl/elementary/genlist_item_class.pxi27
-rw-r--r--efl/elementary/genlist_widget.pxi38
4 files changed, 83 insertions, 3 deletions
diff --git a/efl/elementary/genlist.pxi b/efl/elementary/genlist.pxi
index 71935a0..d395297 100644
--- a/efl/elementary/genlist.pxi
+++ b/efl/elementary/genlist.pxi
@@ -80,6 +80,24 @@ cdef Eina_Bool _py_elm_genlist_item_state_get(void *data, Evas_Object *obj, cons
80 80
81 return ret if ret is not None else 0 81 return ret if ret is not None else 0
82 82
83cdef Eina_Bool _py_elm_genlist_item_filter_get(void *data, Evas_Object *obj, void *key) with gil:
84 cdef:
85 GenlistItem item = <GenlistItem>data
86 object pykey = <object>key
87
88 func = item.item_class._filter_get_func
89 if func is None:
90 return 1
91
92 try:
93 o = object_from_instance(obj)
94 ret = func(o, pykey, item.item_data)
95 except Exception:
96 traceback.print_exc()
97 return 0
98
99 return 1 if ret else 0
100
83cdef void _py_elm_genlist_object_item_del(void *data, Evas_Object *obj) with gil: 101cdef void _py_elm_genlist_object_item_del(void *data, Evas_Object *obj) with gil:
84 cdef GenlistItem item = <GenlistItem>data 102 cdef GenlistItem item = <GenlistItem>data
85 103
diff --git a/efl/elementary/genlist_cdef.pxi b/efl/elementary/genlist_cdef.pxi
index c990620..89779d3 100644
--- a/efl/elementary/genlist_cdef.pxi
+++ b/efl/elementary/genlist_cdef.pxi
@@ -64,12 +64,14 @@ cdef extern from "Elementary.h":
64 ctypedef char *(*GenlistItemLabelGetFunc) (void *data, Evas_Object *obj, const char *part) 64 ctypedef char *(*GenlistItemLabelGetFunc) (void *data, Evas_Object *obj, const char *part)
65 ctypedef Evas_Object *(*GenlistItemIconGetFunc) (void *data, Evas_Object *obj, const char *part) 65 ctypedef Evas_Object *(*GenlistItemIconGetFunc) (void *data, Evas_Object *obj, const char *part)
66 ctypedef Eina_Bool (*GenlistItemStateGetFunc) (void *data, Evas_Object *obj, const char *part) 66 ctypedef Eina_Bool (*GenlistItemStateGetFunc) (void *data, Evas_Object *obj, const char *part)
67 ctypedef Eina_Bool (*GenlistItemFilterGetFunc) (void *data, Evas_Object *obj, void *key)
67 ctypedef void (*GenlistItemDelFunc) (void *data, Evas_Object *obj) 68 ctypedef void (*GenlistItemDelFunc) (void *data, Evas_Object *obj)
68 69
69 ctypedef struct Elm_Genlist_Item_Class_Func: 70 ctypedef struct Elm_Genlist_Item_Class_Func:
70 GenlistItemLabelGetFunc text_get 71 GenlistItemLabelGetFunc text_get
71 GenlistItemIconGetFunc content_get 72 GenlistItemIconGetFunc content_get
72 GenlistItemStateGetFunc state_get 73 GenlistItemStateGetFunc state_get
74 GenlistItemFilterGetFunc filter_get
73 GenlistItemDelFunc del_ "del" 75 GenlistItemDelFunc del_ "del"
74 76
75 ctypedef struct Elm_Genlist_Item_Class: 77 ctypedef struct Elm_Genlist_Item_Class:
@@ -155,3 +157,4 @@ cdef extern from "Elementary.h":
155 Elm_Object_Item * elm_genlist_nth_item_get(const Evas_Object *obj, unsigned int nth) 157 Elm_Object_Item * elm_genlist_nth_item_get(const Evas_Object *obj, unsigned int nth)
156 void elm_genlist_focus_on_selection_set(Evas_Object *obj, Eina_Bool enabled) 158 void elm_genlist_focus_on_selection_set(Evas_Object *obj, Eina_Bool enabled)
157 Eina_Bool elm_genlist_focus_on_selection_get(const Evas_Object *obj) 159 Eina_Bool elm_genlist_focus_on_selection_get(const Evas_Object *obj)
160 void elm_genlist_filter_set(Evas_Object *obj, void *key)
diff --git a/efl/elementary/genlist_item_class.pxi b/efl/elementary/genlist_item_class.pxi
index 06546ba..68875d3 100644
--- a/efl/elementary/genlist_item_class.pxi
+++ b/efl/elementary/genlist_item_class.pxi
@@ -19,6 +19,7 @@ cdef class GenlistItemClass(object):
19 object _text_get_func 19 object _text_get_func
20 object _content_get_func 20 object _content_get_func
21 object _state_get_func 21 object _state_get_func
22 object _filter_get_func
22 object _del_func 23 object _del_func
23 object _item_style 24 object _item_style
24 object _decorate_item_style 25 object _decorate_item_style
@@ -29,6 +30,7 @@ cdef class GenlistItemClass(object):
29 self.cls.func.text_get = _py_elm_genlist_item_text_get 30 self.cls.func.text_get = _py_elm_genlist_item_text_get
30 self.cls.func.content_get = _py_elm_genlist_item_content_get 31 self.cls.func.content_get = _py_elm_genlist_item_content_get
31 self.cls.func.state_get = _py_elm_genlist_item_state_get 32 self.cls.func.state_get = _py_elm_genlist_item_state_get
33 self.cls.func.filter_get = _py_elm_genlist_item_filter_get
32 # In C the struct member is del but we rename it to del_ in pxd 34 # In C the struct member is del but we rename it to del_ in pxd
33 self.cls.func.del_ = _py_elm_genlist_object_item_del 35 self.cls.func.del_ = _py_elm_genlist_object_item_del
34 36
@@ -39,7 +41,7 @@ cdef class GenlistItemClass(object):
39 def __init__(self, item_style=None, text_get_func=None, 41 def __init__(self, item_style=None, text_get_func=None,
40 content_get_func=None, state_get_func=None, del_func=None, 42 content_get_func=None, state_get_func=None, del_func=None,
41 decorate_item_style=None, decorate_all_item_style=None, 43 decorate_item_style=None, decorate_all_item_style=None,
42 *args, **kwargs): 44 filter_get_func=None, *args, **kwargs):
43 45
44 """GenlistItemClass constructor. 46 """GenlistItemClass constructor.
45 47
@@ -106,6 +108,14 @@ cdef class GenlistItemClass(object):
106 else: 108 else:
107 self._state_get_func = self.state_get 109 self._state_get_func = self.state_get
108 110
111 if filter_get_func is not None:
112 if callable(filter_get_func):
113 self._filter_get_func = filter_get_func
114 else:
115 raise TypeError("filter_get_func is not callable!")
116 else:
117 self._filter_get_func = self.filter_get
118
109 if del_func is not None: 119 if del_func is not None:
110 if callable(del_func): 120 if callable(del_func):
111 self._del_func = del_func 121 self._del_func = del_func
@@ -136,7 +146,7 @@ cdef class GenlistItemClass(object):
136 def __repr__(self): 146 def __repr__(self):
137 return ("<%s(%#x, refcount=%d, Elm_Genlist_Item_Class=%#x, " 147 return ("<%s(%#x, refcount=%d, Elm_Genlist_Item_Class=%#x, "
138 "item_style=%r, text_get_func=%s, content_get_func=%s, " 148 "item_style=%r, text_get_func=%s, content_get_func=%s, "
139 "state_get_func=%s, del_func=%s)>") % \ 149 "state_get_func=%s, filter_get_func=%s, del_func=%s)>") % \
140 (type(self).__name__, 150 (type(self).__name__,
141 <uintptr_t><void *>self, 151 <uintptr_t><void *>self,
142 PY_REFCOUNT(self), 152 PY_REFCOUNT(self),
@@ -145,6 +155,7 @@ cdef class GenlistItemClass(object):
145 self._text_get_func, 155 self._text_get_func,
146 self._content_get_func, 156 self._content_get_func,
147 self._state_get_func, 157 self._state_get_func,
158 self._filter_get_func,
148 self._del_func) 159 self._del_func)
149 160
150 def ref(self): 161 def ref(self):
@@ -237,3 +248,15 @@ cdef class GenlistItemClass(object):
237 """ 248 """
238 return False 249 return False
239 250
251 def filter_get(self, evasObject obj, key, item_data):
252 """To be called by Genlist for each row when filter is enabled.
253
254 :param obj: the Genlist instance
255 :param key: the filter key given in the filter_set function
256 :param item_data: the value given to genlist append/prepend.
257
258 :return: Wheter the item should be visible or not
259 :rtype: bool
260 """
261 return True
262
diff --git a/efl/elementary/genlist_widget.pxi b/efl/elementary/genlist_widget.pxi
index 6961255..416678b 100644
--- a/efl/elementary/genlist_widget.pxi
+++ b/efl/elementary/genlist_widget.pxi
@@ -685,7 +685,6 @@ cdef class Genlist(Object):
685 <const char *>pattern if pattern is not None else NULL, 685 <const char *>pattern if pattern is not None else NULL,
686 flags)) 686 flags))
687 687
688
689 property focus_on_selection: 688 property focus_on_selection:
690 """ 689 """
691 690
@@ -709,6 +708,33 @@ cdef class Genlist(Object):
709 def __get__(self): 708 def __get__(self):
710 return bool(elm_genlist_focus_on_selection_get(self.obj)) 709 return bool(elm_genlist_focus_on_selection_get(self.obj))
711 710
711 property filter:
712 """ Set filter mode with key.
713
714 This initiates the filter mode of genlist with user/application
715 provided key. If key is None, the filter mode is turned off.
716
717 The given key will be passed back in the filter_get function of
718 the GenlistItemClass
719
720 :type: any python object
721
722 .. versionadded:: 1.17
723
724 """
725 def __set__(self, object key):
726 self.data['__filterkeyref'] = key # keep a reference for key
727 elm_genlist_filter_set(self.obj, <void *>key if key is not None else NULL)
728
729 def __get__(self):
730 return self.data['__filterkeyref']
731
732 def filter_set(self, key):
733 self.data['__filterkeyref'] = key
734 elm_genlist_filter_set(self.obj, <void*>key if key is not None else NULL)
735 def filter_get(self):
736 return self.data['__filterkeyref']
737
712 # 738 #
713 # Drag and Drop 739 # Drag and Drop
714 # ============= 740 # =============
@@ -1070,6 +1096,16 @@ cdef class Genlist(Object):
1070 def callback_changed_del(self, func): 1096 def callback_changed_del(self, func):
1071 self._callback_del("changed", func) 1097 self._callback_del("changed", func)
1072 1098
1099 def callback_filter_done_add(self, func, *args, **kwargs):
1100 """Genlist filter operation is completed.
1101
1102 .. versionadded:: 1.17
1103 """
1104 self._callback_add("filter,done", func, args, kwargs)
1105
1106 def callback_filter_done_del(self, func):
1107 self._callback_del("filter,done", func)
1108
1073 property scroller_policy: 1109 property scroller_policy:
1074 """ 1110 """
1075 1111