summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--elementary/elementary.c_elementary_genlist.pxi95
-rw-r--r--elementary/elementary.c_elementary_object.pxi11
-rw-r--r--elementary/elementary.c_elementary_slideshow.pxi12
3 files changed, 112 insertions, 6 deletions
diff --git a/elementary/elementary.c_elementary_genlist.pxi b/elementary/elementary.c_elementary_genlist.pxi
index 8080ca3..7def5a0 100644
--- a/elementary/elementary.c_elementary_genlist.pxi
+++ b/elementary/elementary.c_elementary_genlist.pxi
@@ -110,6 +110,29 @@ cdef void _py_elm_genlist_item_func(void *data, Evas_Object *obj, void *event_in
110 except Exception as e: 110 except Exception as e:
111 traceback.print_exc() 111 traceback.print_exc()
112 112
113cdef int _py_elm_genlist_compare_func(const_void *data1, const_void *data2) with gil:
114 cdef Elm_Object_Item *citem1 = <Elm_Object_Item *>data1
115 cdef Elm_Object_Item *citem2 = <Elm_Object_Item *>data2
116 cdef object func
117
118 item1 = <GenlistItem>elm_object_item_data_get(citem1)
119 item2 = <GenlistItem>elm_object_item_data_get(citem2)
120
121 func = item1.comparison_func
122
123 if func is None:
124 return 0
125
126 ret = func(item1, item2)
127 if ret is not None:
128 try:
129 return ret
130 except Exception as e:
131 traceback.print_exc()
132 return 0
133 else:
134 return 0
135
113cdef class GenlistItemClass: 136cdef class GenlistItemClass:
114 """Defines the behavior of each list item. 137 """Defines the behavior of each list item.
115 138
@@ -813,6 +836,78 @@ cdef public class Genlist(Object) [object PyElementaryGenlist, type PyElementary
813 Py_DECREF(ret) 836 Py_DECREF(ret)
814 return None 837 return None
815 838
839 def item_sorted_insert( self,
840 GenlistItemClass item_class not None,
841 item_data,
842 GenlistItem parent_item=None,
843 int flags=ELM_GENLIST_ITEM_NONE,
844 comparison_func = None,
845 func=None):
846 """Insert a new item into the sorted genlist object
847
848 @param item_class: a valid instance that defines the
849 behavior of this row. See L{GenlistItemClass}.
850 @param item_data: some data that defines the model of this
851 row. This value will be given to methods of
852 C{item_class} such as
853 L{GenlistItemClass.text_get()}. It will also be
854 provided to C{func} as its last parameter.
855 @param parent_item: if this is a tree child, then the
856 parent item must be given here, otherwise it may be
857 None. The parent must have the flag
858 C{ELM_GENLIST_ITEM_SUBITEMS} set.
859 @param flags: defines special behavior of this item:
860 - ELM_GENLIST_ITEM_NONE = 0
861 - ELM_GENLIST_ITEM_SUBITEMS = 1
862 - ELM_GENLIST_ITEM_GROUP = 2
863 @param comparison_func: The comparison function used to sort
864 the list. The cb function gets passed two Genlist items
865 and you should return -1 if item1 is less than item2,
866 0 if they are equal, 1 if item1 is greater than item2.
867 @param func: if not None, this must be a callable to be
868 called back when the item is selected. The function
869 signature is:
870 C{func(item, obj, item_data)}
871 Where C{item} is the handle, C{obj} is the Evas object
872 that represents this item, and C{item_data} is the
873 value given as parameter to this function.
874 """
875 cdef GenlistItem ret = GenlistItem()
876 cdef Elm_Object_Item *item, *parent
877 cdef Evas_Smart_Cb cb
878
879 parent = _object_item_from_python(parent_item) if parent_item is not None else NULL
880
881 if func is None:
882 cb = NULL
883 elif callable(func):
884 cb = _py_elm_genlist_item_func
885 else:
886 raise TypeError("func is not None or callable")
887
888 if comparison_func is not None:
889 if not callable(comparison_func):
890 raise TypeError("func is not None or callable")
891 ret.comparison_func = comparison_func
892
893 ret.params = (item_class, item_data, func)
894 item = elm_genlist_item_sorted_insert( self.obj,
895 &item_class.obj,
896 <void*>ret,
897 parent,
898 <Elm_Genlist_Item_Type>flags,
899 _py_elm_genlist_compare_func,
900 cb,
901 <void*>ret)
902
903 if item != NULL:
904 ret._set_obj(item)
905 return ret
906 else:
907 Py_DECREF(ret)
908 return None
909
910
816 #Elm_Object_Item *elm_genlist_item_sorted_insert(self.obj, Elm_Genlist_Item_Class *itc, void *data, Elm_Object_Item *parent, Elm_Genlist_Item_Type flags, Eina_Compare_Cb comp, Evas_Smart_Cb func, void *func_data) 911 #Elm_Object_Item *elm_genlist_item_sorted_insert(self.obj, Elm_Genlist_Item_Class *itc, void *data, Elm_Object_Item *parent, Elm_Genlist_Item_Type flags, Eina_Compare_Cb comp, Evas_Smart_Cb func, void *func_data)
817 912
818 def selected_item_get(self): 913 def selected_item_get(self):
diff --git a/elementary/elementary.c_elementary_object.pxi b/elementary/elementary.c_elementary_object.pxi
index 019a9b8..a39fa48 100644
--- a/elementary/elementary.c_elementary_object.pxi
+++ b/elementary/elementary.c_elementary_object.pxi
@@ -17,12 +17,13 @@
17# 17#
18 18
19from evas.c_evas cimport Object as evasObject 19from evas.c_evas cimport Object as evasObject
20from evas.c_evas cimport EventKeyDown, EventKeyUp 20from evas.c_evas cimport EventKeyDown, EventKeyUp, EventMouseWheel
21from evas.c_evas cimport evas_object_data_get 21from evas.c_evas cimport evas_object_data_get
22from evas.c_evas cimport evas_object_smart_callback_add 22from evas.c_evas cimport evas_object_smart_callback_add
23from evas.c_evas cimport evas_object_smart_callback_del 23from evas.c_evas cimport evas_object_smart_callback_del
24from evas.c_evas cimport EVAS_CALLBACK_KEY_DOWN 24from evas.c_evas cimport EVAS_CALLBACK_KEY_DOWN
25from evas.c_evas cimport EVAS_CALLBACK_KEY_UP 25from evas.c_evas cimport EVAS_CALLBACK_KEY_UP
26from evas.c_evas cimport EVAS_CALLBACK_MOUSE_WHEEL
26from evas.c_evas cimport eina_list_append 27from evas.c_evas cimport eina_list_append
27 28
28from evas.c_evas import _extended_object_mapping_register 29from evas.c_evas import _extended_object_mapping_register
@@ -72,13 +73,13 @@ cdef Eina_Bool _event_dispatcher(o, src, Evas_Callback_Type t, event_info):
72 return True 73 return True
73 return False 74 return False
74 75
75#TODO: More event types
76cdef Eina_Bool _event_callback(void *data, Evas_Object *o, Evas_Object *src, Evas_Callback_Type t, void *event_info) with gil: 76cdef Eina_Bool _event_callback(void *data, Evas_Object *o, Evas_Object *src, Evas_Callback_Type t, void *event_info) with gil:
77 cdef Object obj = <Object>Object_from_instance(o) 77 cdef Object obj = <Object>Object_from_instance(o)
78 cdef Object src_obj = <Object>Object_from_instance(src) 78 cdef Object src_obj = <Object>Object_from_instance(src)
79 cdef Eina_Bool ret = False 79 cdef Eina_Bool ret = False
80 cdef EventKeyDown down_event 80 cdef EventKeyDown down_event
81 cdef EventKeyUp up_event 81 cdef EventKeyUp up_event
82
82 if t == EVAS_CALLBACK_KEY_DOWN: 83 if t == EVAS_CALLBACK_KEY_DOWN:
83 down_event = EventKeyDown() 84 down_event = EventKeyDown()
84 down_event._set_obj(event_info) 85 down_event._set_obj(event_info)
@@ -89,7 +90,13 @@ cdef Eina_Bool _event_callback(void *data, Evas_Object *o, Evas_Object *src, Eva
89 up_event._set_obj(event_info) 90 up_event._set_obj(event_info)
90 ret = _event_dispatcher(obj, src_obj, t, up_event) 91 ret = _event_dispatcher(obj, src_obj, t, up_event)
91 up_event._unset_obj() 92 up_event._unset_obj()
93 elif t == EVAS_CALLBACK_MOUSE_WHEEL:
94 wheel_event = EventMouseWheel()
95 wheel_event._set_obj(event_info)
96 ret = _event_dispatcher(obj, src_obj, t, wheel_event)
97 wheel_event._unset_obj()
92 98
99 return bool(ret)
93 100
94cdef void _event_data_del_cb(void *data, Evas_Object *o, void *event_info) with gil: 101cdef void _event_data_del_cb(void *data, Evas_Object *o, void *event_info) with gil:
95 Py_DECREF(<object>data) 102 Py_DECREF(<object>data)
diff --git a/elementary/elementary.c_elementary_slideshow.pxi b/elementary/elementary.c_elementary_slideshow.pxi
index 3097041..d493f2a 100644
--- a/elementary/elementary.c_elementary_slideshow.pxi
+++ b/elementary/elementary.c_elementary_slideshow.pxi
@@ -62,10 +62,14 @@ cdef void _py_elm_slideshow_item_del(void *data, Evas_Object *obj) with gil:
62 Py_DECREF(item) 62 Py_DECREF(item)
63 63
64cdef int _py_elm_slideshow_compare_func(const_void *data1, const_void *data2) with gil: 64cdef int _py_elm_slideshow_compare_func(const_void *data1, const_void *data2) with gil:
65 cdef SlideshowItem item1 = <object>data1 65 cdef Elm_Object_Item *citem1 = <Elm_Object_Item *>data1
66 cdef SlideshowItem item2 = <object>data2 66 cdef Elm_Object_Item *citem2 = <Elm_Object_Item *>data2
67 cdef object params = item1.params 67 cdef object func
68 cdef object func = params[2] 68
69 item1 = <SlideshowItem>elm_object_item_data_get(citem1)
70 item2 = <SlideshowItem>elm_object_item_data_get(citem2)
71
72 func = item1.comparison_func
69 73
70 if func is None: 74 if func is None:
71 return 0 75 return 0