summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2015-05-04 02:20:55 +0200
committerDave Andreoli <dave@gurumeditation.it>2015-05-04 02:21:07 +0200
commit9b258cb28e86fb963415ad448a70ae07e0b429e6 (patch)
tree0edc7e60daa7e7bad41b2844cb55c9765525379b
parenta70d9c7cd46b03cb3b5bd2610b67ec26a0906ea6 (diff)
Changed slideshow to use new-style item data.
Item data is now a single value instead of args/kargs, to reflect the usage in Genlist/Gengrid Also updated the test
-rw-r--r--efl/elementary/slideshow.pyx92
-rw-r--r--examples/elementary/test_slideshow.py45
2 files changed, 80 insertions, 57 deletions
diff --git a/efl/elementary/slideshow.pyx b/efl/elementary/slideshow.pyx
index 19249a7..e1f9597 100644
--- a/efl/elementary/slideshow.pyx
+++ b/efl/elementary/slideshow.pyx
@@ -110,9 +110,10 @@ cdef object _cb_object_item_conv(void *addr):
110 110
111 111
112cdef Evas_Object *_py_elm_slideshow_item_get(void *data, Evas_Object *obj) with gil: 112cdef Evas_Object *_py_elm_slideshow_item_get(void *data, Evas_Object *obj) with gil:
113 cdef SlideshowItem item = <object>data 113 cdef:
114 cdef evasObject icon 114 SlideshowItem item = <SlideshowItem>data
115 cdef SlideshowItemClass itc = item.cls 115 SlideshowItemClass itc = item.item_class
116 evasObject icon
116 117
117 func = itc._get_func 118 func = itc._get_func
118 if func is None: 119 if func is None:
@@ -120,37 +121,39 @@ cdef Evas_Object *_py_elm_slideshow_item_get(void *data, Evas_Object *obj) with
120 121
121 try: 122 try:
122 o = object_from_instance(obj) 123 o = object_from_instance(obj)
123 ret = func(o, *item.args, **item.kwargs) 124 icon = func(o, item.item_data)
124 except Exception: 125 except Exception:
125 traceback.print_exc() 126 traceback.print_exc()
126 return NULL 127 return NULL
127 128
128 if ret is None: 129 if icon is not None:
130 return icon.obj
131 else:
129 return NULL 132 return NULL
130 133
131 icon = ret
132 return icon.obj
133 134
134cdef void _py_elm_slideshow_item_del(void *data, Evas_Object *obj) with gil: 135cdef void _py_elm_slideshow_item_del(void *data, Evas_Object *obj) with gil:
135 cdef SlideshowItem item = <object>data 136 cdef:
136 cdef SlideshowItemClass itc = item.cls 137 SlideshowItem item = <SlideshowItem>data
138 SlideshowItemClass itc = item.item_class
137 139
138 func = itc._del_func 140 func = itc._del_func
139 if func is not None: 141 if func is not None:
140 try: 142 try:
141 o = object_from_instance(obj) 143 o = object_from_instance(obj)
142 func(o, *item.args, **item.kwargs) 144 func(o, item.item_data)
143 except Exception: 145 except Exception:
144 traceback.print_exc() 146 traceback.print_exc()
145 147
146 # XXX: SlideShow item handling is weird 148 # XXX: SlideShow item handling is weird
147 #item._unset_obj() 149 # item._unset_obj()
148 #Py_DECREF(item) 150 #Py_DECREF(item)
149 151
150cdef int _py_elm_slideshow_compare_func(const void *data1, const void *data2) with gil: 152cdef int _py_elm_slideshow_compare_func(const void *data1, const void *data2) with gil:
151 cdef SlideshowItem item1 = <object>data1 153 cdef:
152 cdef SlideshowItem item2 = <object>data2 154 SlideshowItem item1 = <SlideshowItem>data1
153 cdef object func = item1.compare_func 155 SlideshowItem item2 = <SlideshowItem>data2
156 object func = item1.compare_func
154 157
155 if func is None: 158 if func is None:
156 return 0 159 return 0
@@ -192,17 +195,17 @@ cdef class SlideshowItemClass (object):
192 ``func(obj, item_data)`` 195 ``func(obj, item_data)``
193 196
194 .. note:: In all these signatures, 'obj' means Slideshow and 197 .. note:: In all these signatures, 'obj' means Slideshow and
195 'item_data' is the value given to Slideshow item append/prepend 198 'item_data' is the value given to Slideshow item add/sorted_insert
196 methods, it should represent your item model as you want. 199 methods, it should represent your item model as you want.
197 200
198 """ 201 """
199 cdef Elm_Slideshow_Item_Class obj 202 cdef Elm_Slideshow_Item_Class cls
200 cdef readonly object _get_func 203 cdef readonly object _get_func
201 cdef readonly object _del_func 204 cdef readonly object _del_func
202 205
203 def __cinit__(self, *a, **ka): 206 def __cinit__(self):
204 self.obj.func.get = _py_elm_slideshow_item_get 207 self.cls.func.get = _py_elm_slideshow_item_get
205 self.obj.func.del_ = _py_elm_slideshow_item_del 208 self.cls.func.del_ = _py_elm_slideshow_item_del
206 209
207 def __init__(self, get_func=None, del_func=None): 210 def __init__(self, get_func=None, del_func=None):
208 if get_func and not callable(get_func): 211 if get_func and not callable(get_func):
@@ -228,7 +231,7 @@ cdef class SlideshowItemClass (object):
228 (type(self).__name__, 231 (type(self).__name__,
229 <uintptr_t><void *>self, 232 <uintptr_t><void *>self,
230 PY_REFCOUNT(self), 233 PY_REFCOUNT(self),
231 <uintptr_t>&self.obj, 234 <uintptr_t>&self.cls,
232 self._get_func, 235 self._get_func,
233 self._del_func) 236 self._del_func)
234 237
@@ -236,7 +239,7 @@ cdef class SlideshowItemClass (object):
236 """To be called by Slideshow for each item to get its icon. 239 """To be called by Slideshow for each item to get its icon.
237 240
238 :param obj: the Slideshow instance 241 :param obj: the Slideshow instance
239 :param item_data: the value given to slideshow append/prepend. 242 :param item_data: the value given to slideshow item_add func.
240 243
241 :return: icon object to be used and swallowed. 244 :return: icon object to be used and swallowed.
242 :rtype: evas Object or None 245 :rtype: evas Object or None
@@ -251,8 +254,8 @@ cdef class SlideshowItem(ObjectItem):
251 """ 254 """
252 255
253 cdef: 256 cdef:
254 SlideshowItemClass cls 257 readonly SlideshowItemClass item_class
255 object compare_func 258 object item_data, compare_func
256 259
257 cdef int _set_obj(self, Elm_Object_Item *item) except 0: 260 cdef int _set_obj(self, Elm_Object_Item *item) except 0:
258 assert self.item == NULL, "Object must be clean" 261 assert self.item == NULL, "Object must be clean"
@@ -264,8 +267,10 @@ cdef class SlideshowItem(ObjectItem):
264 assert self.item != NULL, "Object must wrap something" 267 assert self.item != NULL, "Object must wrap something"
265 self.item = NULL 268 self.item = NULL
266 269
267 def __init__(self, SlideshowItemClass item_class not None, *args, **kwargs): 270 def __init__(self, SlideshowItemClass item_class not None,
268 self.cls = item_class 271 item_data=None, *args, **kwargs):
272 self.item_class = item_class
273 self.item_data = item_data
269 self.args = args 274 self.args = args
270 self.kwargs = kwargs 275 self.kwargs = kwargs
271 276
@@ -275,9 +280,9 @@ cdef class SlideshowItem(ObjectItem):
275 (type(self).__name__, 280 (type(self).__name__,
276 <uintptr_t><void*>self, 281 <uintptr_t><void*>self,
277 PY_REFCOUNT(self), 282 PY_REFCOUNT(self),
278 <uintptr_t>self.obj, 283 <uintptr_t>self.item,
279 type(self.cls).__name__, 284 type(self.item_class).__name__,
280 self.args) 285 self.item_data)
281 286
282 def add_to(self, Slideshow slideshow not None): 287 def add_to(self, Slideshow slideshow not None):
283 """Add (append) a new item in a given slideshow widget. 288 """Add (append) a new item in a given slideshow widget.
@@ -303,7 +308,8 @@ cdef class SlideshowItem(ObjectItem):
303 """ 308 """
304 cdef Elm_Object_Item *item 309 cdef Elm_Object_Item *item
305 310
306 item = elm_slideshow_item_add(slideshow.obj, &self.cls.obj, <void*>self) 311 item = elm_slideshow_item_add(slideshow.obj, &self.item_class.cls,
312 <void*>self)
307 313
308 if item == NULL: 314 if item == NULL:
309 raise RuntimeError("The item could not be added to the widget.") 315 raise RuntimeError("The item could not be added to the widget.")
@@ -347,8 +353,8 @@ cdef class SlideshowItem(ObjectItem):
347 self.compare_func = func 353 self.compare_func = func
348 compare = _py_elm_slideshow_compare_func 354 compare = _py_elm_slideshow_compare_func
349 355
350 item = elm_slideshow_item_sorted_insert(slideshow.obj, &self.cls.obj, \ 356 item = elm_slideshow_item_sorted_insert(slideshow.obj,
351 <void*>self, compare) 357 &self.item_class.cls, <void*>self, compare)
352 358
353 if item == NULL: 359 if item == NULL:
354 raise RuntimeError("The item could not be added to the widget.") 360 raise RuntimeError("The item could not be added to the widget.")
@@ -407,7 +413,7 @@ cdef class Slideshow(LayoutClass):
407 self._set_obj(elm_slideshow_add(parent.obj)) 413 self._set_obj(elm_slideshow_add(parent.obj))
408 self._set_properties_from_keyword_args(kwargs) 414 self._set_properties_from_keyword_args(kwargs)
409 415
410 def item_add(self, SlideshowItemClass item_class not None, *args, **kwargs): 416 def item_add(self, SlideshowItemClass item_class not None, item_data):
411 """Add (append) a new item in a given slideshow widget. 417 """Add (append) a new item in a given slideshow widget.
412 418
413 Add a new item to ``obj's`` internal list of items, appending it. 419 Add a new item to ``obj's`` internal list of items, appending it.
@@ -425,14 +431,19 @@ cdef class Slideshow(LayoutClass):
425 :param item_class: The item class for the item 431 :param item_class: The item class for the item
426 :type item_class: :py:class:`SlideshowItemClass` 432 :type item_class: :py:class:`SlideshowItemClass`
427 433
434 :param item_data: The data (model) associated with this item
435
428 :return: A handle to the item added or ``None``, on errors 436 :return: A handle to the item added or ``None``, on errors
429 :rtype: :py:class:`SlideshowItem` 437 :rtype: :py:class:`SlideshowItem`
430 438
439 .. versionchanged:: 1.14
440 use item_data param instead or args/kargs
441
431 """ 442 """
432 return SlideshowItem(item_class, *args, **kwargs).add_to(self) 443 return SlideshowItem(item_class, item_data).add_to(self)
433 444
434 def item_sorted_insert(self, SlideshowItemClass item_class not None, 445 def item_sorted_insert(self, SlideshowItemClass item_class not None,
435 func not None, *args, **kwargs): 446 func not None, item_data):
436 """Insert a new item into the given slideshow widget, using the ``func`` 447 """Insert a new item into the given slideshow widget, using the ``func``
437 function to sort items (by item handles). 448 function to sort items (by item handles).
438 449
@@ -454,11 +465,18 @@ cdef class Slideshow(LayoutClass):
454 :param itc: The item class for the item 465 :param itc: The item class for the item
455 :param func: The comparing function to be used to sort slideshow 466 :param func: The comparing function to be used to sort slideshow
456 items **by SlideshowItemClass item handles** 467 items **by SlideshowItemClass item handles**
457 :return: Returns The slideshow item handle, on success, or 468
458 ``None``, on errors 469 :param item_data: The data (model) associated with this item
470
471 :return: A handle to the item added or ``None``, on errors
472 :rtype: :py:class:`SlideshowItem`
473
474 .. versionchanged:: 1.14
475 use item_data param instead or args/kargs
476
459 477
460 """ 478 """
461 return SlideshowItem(item_class, *args, **kwargs).sorted_insert(self, func) 479 return SlideshowItem(item_class, item_data).sorted_insert(self, func)
462 480
463 def next(self): 481 def next(self):
464 """Slide to the **next** item, in a given slideshow widget 482 """Slide to the **next** item, in a given slideshow widget
diff --git a/examples/elementary/test_slideshow.py b/examples/elementary/test_slideshow.py
index a3c6a44..effac2e 100644
--- a/examples/elementary/test_slideshow.py
+++ b/examples/elementary/test_slideshow.py
@@ -74,40 +74,45 @@ def spin(sp, ss):
74 if (ss.timeout > 0): 74 if (ss.timeout > 0):
75 ss.timeout = sp.value 75 ss.timeout = sp.value
76 76
77def slide_transition(ss, slide_it, slide_last_it): 77
78 if (slide_last_it == slide_it): 78def ss_changed_cb(ss, item):
79 print("CHANGED", item)
80
81def ss_transition_end_cb(ss, item, last_item):
82 print("TRANSITION END", item)
83 if item == last_item:
79 print("Reaches to End of slides\n") 84 print("Reaches to End of slides\n")
80 85
81class ssClass(SlideshowItemClass): 86class ssClass(SlideshowItemClass):
82 def get(self, obj, *args, **kwargs): 87 def get(self, obj, item_data):
83 photo = Photo(obj, file=args[0], fill_inside=True, style="shadow") 88 print("Class get", item_data)
89 photo = Photo(obj, file=item_data, fill_inside=True, style="shadow")
84 return photo 90 return photo
85 91
92 def delete(self, obj, item_data):
93 print("Class delete", item_data)
94
86def slideshow_clicked(obj): 95def slideshow_clicked(obj):
87 win = StandardWindow("slideshow", "Slideshow", autodel=True, 96 win = StandardWindow("slideshow", "Slideshow",
88 size=(500, 400)) 97 autodel=True, size=(500, 400))
89 98
90 ss = Slideshow(win, loop=True, size_hint_weight=EXPAND_BOTH) 99 ss = Slideshow(win, loop=True, size_hint_weight=EXPAND_BOTH)
91 win.resize_object_add(ss) 100 win.resize_object_add(ss)
92 ss.show() 101 ss.show()
93 102
94 ssc = ssClass() 103 ssc = ssClass()
95 ss.item_add(ssc, os.path.join(img_path, images[0])) 104 for i in range(len(images)):
96 ss.item_add(ssc, os.path.join(img_path, images[1])) 105 print("ADD", images[i])
97 ss.item_add(ssc, os.path.join(img_path, images[2])) 106 slide_last_it = ss.item_add(ssc, os.path.join(img_path, images[i]))
98 ss.item_add(ssc, os.path.join(img_path, images[3])) 107
99 ss.item_add(ssc, os.path.join(img_path, images[8])) 108 ss.callback_changed_add(ss_changed_cb)
100 ss.item_add(ssc, os.path.join(img_path, images[4])) 109 ss.callback_transition_end_add(ss_transition_end_cb, slide_last_it)
101 ss.item_add(ssc, os.path.join(img_path, images[5]))
102 ss.item_add(ssc, os.path.join(img_path, images[6]))
103 slide_last_it = ss.item_add(ssc, os.path.join(img_path, images[7]))
104 ss.callback_transition_end_add(slide_transition, slide_last_it)
105 110
106 bx = Box(win, horizontal=True) 111 bx = Box(win, horizontal=True)
107 bx.show() 112 bx.show()
108 113
109 no = Notify(win, align=(0.5, 1.0), 114 no = Notify(win, align=(0.5, 1.0), timeout=3.0, content=bx,
110 size_hint_weight=EXPAND_BOTH, timeout=3.0, content=bx) 115 size_hint_weight=EXPAND_BOTH)
111 win.resize_object_add(no) 116 win.resize_object_add(no)
112 117
113 bx.event_callback_add(EVAS_CALLBACK_MOUSE_IN, mouse_in, no) 118 bx.event_callback_add(EVAS_CALLBACK_MOUSE_IN, mouse_in, no)
@@ -136,8 +141,8 @@ def slideshow_clicked(obj):
136 hv.item_add(layout, None, 0, layout_select, ss, layout) 141 hv.item_add(layout, None, 0, layout_select, ss, layout)
137 hv.show() 142 hv.show()
138 143
139 sp = Spinner(win, label_format="%2.0f secs.", step=1, min_max=(1, 30), 144 sp = Spinner(win, label_format="%2.0f secs.",
140 value=3) 145 step=1, min_max=(1, 30), value=3)
141 sp.callback_changed_add(spin, ss) 146 sp.callback_changed_add(spin, ss)
142 bx.pack_end(sp) 147 bx.pack_end(sp)
143 sp.show() 148 sp.show()