summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2014-07-31 22:18:41 +0200
committerdavemds <dave@gurumeditation.it>2014-07-31 22:18:41 +0200
commita97e61dd4ffceb30e62cc0973e879e60a8d43169 (patch)
treeeddca5af9d991456fb8bc532237c26c88969789e
parent5aa12930a1ac3971d36c3b713fa010d96cd1c607 (diff)
Ctxpopup: new getters for items and the item_prepend method, with tests
-rw-r--r--efl/elementary/ctxpopup.pxd8
-rw-r--r--efl/elementary/ctxpopup.pyx142
-rw-r--r--examples/elementary/test_ctxpopup.py23
3 files changed, 169 insertions, 4 deletions
diff --git a/efl/elementary/ctxpopup.pxd b/efl/elementary/ctxpopup.pxd
index a976554..31ab98f 100644
--- a/efl/elementary/ctxpopup.pxd
+++ b/efl/elementary/ctxpopup.pxd
@@ -1,4 +1,4 @@
1from efl.evas cimport Eina_Bool, Evas_Object, Evas_Smart_Cb 1from efl.evas cimport Eina_Bool, Eina_List, Evas_Object, Evas_Smart_Cb
2from object_item cimport Elm_Object_Item 2from object_item cimport Elm_Object_Item
3from enums cimport Elm_Ctxpopup_Direction 3from enums cimport Elm_Ctxpopup_Direction
4 4
@@ -10,10 +10,16 @@ cdef extern from "Elementary.h":
10 void elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal) 10 void elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
11 Eina_Bool elm_ctxpopup_horizontal_get(const Evas_Object *obj) 11 Eina_Bool elm_ctxpopup_horizontal_get(const Evas_Object *obj)
12 Elm_Object_Item *elm_ctxpopup_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, void *data) 12 Elm_Object_Item *elm_ctxpopup_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, void *data)
13 Elm_Object_Item *elm_ctxpopup_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, void *data)
13 void elm_ctxpopup_direction_priority_set(Evas_Object *obj, Elm_Ctxpopup_Direction first, Elm_Ctxpopup_Direction second, Elm_Ctxpopup_Direction third, Elm_Ctxpopup_Direction fourth) 14 void elm_ctxpopup_direction_priority_set(Evas_Object *obj, Elm_Ctxpopup_Direction first, Elm_Ctxpopup_Direction second, Elm_Ctxpopup_Direction third, Elm_Ctxpopup_Direction fourth)
14 void elm_ctxpopup_direction_priority_get(const Evas_Object *obj, Elm_Ctxpopup_Direction *first, Elm_Ctxpopup_Direction *second, Elm_Ctxpopup_Direction *third, Elm_Ctxpopup_Direction *fourth) 15 void elm_ctxpopup_direction_priority_get(const Evas_Object *obj, Elm_Ctxpopup_Direction *first, Elm_Ctxpopup_Direction *second, Elm_Ctxpopup_Direction *third, Elm_Ctxpopup_Direction *fourth)
15 Elm_Ctxpopup_Direction elm_ctxpopup_direction_get(const Evas_Object *obj) 16 Elm_Ctxpopup_Direction elm_ctxpopup_direction_get(const Evas_Object *obj)
16 void elm_ctxpopup_dismiss(Evas_Object *obj) 17 void elm_ctxpopup_dismiss(Evas_Object *obj)
17 void elm_ctxpopup_auto_hide_disabled_set(Evas_Object *obj, Eina_Bool disabled) 18 void elm_ctxpopup_auto_hide_disabled_set(Evas_Object *obj, Eina_Bool disabled)
18 Eina_Bool elm_ctxpopup_auto_hide_disabled_get(const Evas_Object *obj) 19 Eina_Bool elm_ctxpopup_auto_hide_disabled_get(const Evas_Object *obj)
20 Eina_List *elm_ctxpopup_items_get(const Evas_Object *obj)
21 Elm_Object_Item *elm_ctxpopup_first_item_get(const Evas_Object *obj)
22 Elm_Object_Item *elm_ctxpopup_last_item_get(const Evas_Object *obj)
23 Elm_Object_Item *elm_ctxpopup_item_prev_get(const Elm_Object_Item *it)
24 Elm_Object_Item *elm_ctxpopup_item_next_get(const Elm_Object_Item *it)
19 25
diff --git a/efl/elementary/ctxpopup.pyx b/efl/elementary/ctxpopup.pyx
index 28e08d5..feba3a7 100644
--- a/efl/elementary/ctxpopup.pyx
+++ b/efl/elementary/ctxpopup.pyx
@@ -95,7 +95,7 @@ from efl.eo cimport _object_mapping_register, object_from_instance
95from efl.evas cimport Object as evasObject 95from efl.evas cimport Object as evasObject
96from layout_class cimport LayoutClass 96from layout_class cimport LayoutClass
97from object_item cimport ObjectItem, _object_item_callback, \ 97from object_item cimport ObjectItem, _object_item_callback, \
98 _object_item_callback2 98 _object_item_callback2, _object_item_to_python, _object_item_list_to_python
99 99
100cimport enums 100cimport enums
101 101
@@ -175,6 +175,63 @@ cdef class CtxpopupItem(ObjectItem):
175 self._set_properties_from_keyword_args(self.kwargs) 175 self._set_properties_from_keyword_args(self.kwargs)
176 return self 176 return self
177 177
178 def prepend_to(self, evasObject ctxpopup):
179 """Prepend a new item to a ctxpopup object.
180
181 .. warning:: Ctxpopup can't hold both an item list and a content at the
182 same time. When an item is added, any previous content will be
183 removed.
184
185 .. seealso:: :py:attr:`~efl.elementary.object.Object.content`
186
187 :param ctxpopup: The Ctxpopup widget this item is to be prepended on
188 :type ctxpopup: :py:class:`Ctxpopup`
189 :return: The item added or ``None``, on errors
190 :rtype: :py:class:`CtxpopupItem`
191
192 ..versionadded:: 1.11
193
194 """
195 cdef Elm_Object_Item *item
196 cdef Evas_Smart_Cb cb = NULL
197
198 if self.cb_func is not None:
199 cb = _object_item_callback2
200
201 item = elm_ctxpopup_item_prepend(ctxpopup.obj,
202 <const char *>self.label if self.label is not None else NULL,
203 self.icon.obj if self.icon is not None else NULL,
204 cb, <void*>self)
205
206 if item == NULL:
207 raise RuntimeError("The item could not be added to the widget.")
208
209 self._set_obj(item)
210 self._set_properties_from_keyword_args(self.kwargs)
211 return self
212
213 property prev:
214 """ The previous item.
215
216 :type: :py:class:`CtxpopupItem`
217
218 ..versionadded:: 1.11
219
220 """
221 def __get__(self):
222 return _object_item_to_python(elm_ctxpopup_item_prev_get(self.item))
223
224 property next:
225 """ The next item.
226
227 :type: :py:class:`CtxpopupItem`
228
229 ..versionadded:: 1.11
230
231 """
232 def __get__(self):
233 return _object_item_to_python(elm_ctxpopup_item_next_get(self.item))
234
178cdef class Ctxpopup(LayoutClass): 235cdef class Ctxpopup(LayoutClass):
179 236
180 """This is the class that actually implements the widget. 237 """This is the class that actually implements the widget.
@@ -226,8 +283,8 @@ cdef class Ctxpopup(LayoutClass):
226 def horizontal_get(self): 283 def horizontal_get(self):
227 return bool(elm_ctxpopup_horizontal_get(self.obj)) 284 return bool(elm_ctxpopup_horizontal_get(self.obj))
228 285
229 def item_append(self, label, evasObject icon = None, func = None, 286 def item_append(self, label, evasObject icon=None,
230 *args, **kwargs): 287 func=None, *args, **kwargs):
231 """A constructor for a :py:class:`CtxpopupItem`. 288 """A constructor for a :py:class:`CtxpopupItem`.
232 289
233 :see: :py:func:`CtxpopupItem.append_to` 290 :see: :py:func:`CtxpopupItem.append_to`
@@ -257,6 +314,85 @@ cdef class Ctxpopup(LayoutClass):
257 else: 314 else:
258 return None 315 return None
259 316
317 def item_prepend(self, label, evasObject icon=None,
318 func=None, *args, **kwargs):
319 """A constructor for a :py:class:`CtxpopupItem`.
320
321 :see: :py:func:`CtxpopupItem.prepend_to`
322
323 ..versionadded:: 1.11
324
325 """
326 cdef:
327 Elm_Object_Item *item
328 Evas_Smart_Cb cb = NULL
329 CtxpopupItem ret = CtxpopupItem.__new__(CtxpopupItem)
330
331 if func is not None and callable(func):
332 cb = _object_item_callback
333
334 if isinstance(label, unicode): label = PyUnicode_AsUTF8String(label)
335
336 item = elm_ctxpopup_item_prepend(self.obj,
337 <const char *>label if label is not None else NULL,
338 icon.obj if icon is not None else NULL,
339 cb, <void*>ret)
340
341 if item != NULL:
342 ret._set_obj(item)
343 ret.cb_func = func
344 ret.args = args
345 ret.kwargs = kwargs
346 return ret
347 else:
348 return None
349
350 property items:
351 """ Get the list of items in the ctxpopup widget.
352
353 This list is not to be modified in any way and is only valid until
354 the object internal items list is changed. It should be fetched again
355 with another call to this function when changes happen.
356
357 :type: list of :py:class:`CtxpopupItem`
358
359 ..versionadded:: 1.11
360
361 """
362 def __get__(self):
363 return _object_item_list_to_python(elm_ctxpopup_items_get(self.obj))
364
365 def items_get(self):
366 return _object_item_list_to_python(elm_ctxpopup_items_get(self.obj))
367
368 property first_item:
369 """ The first item of the Ctxpopup.
370
371 :type: :py:class:`CtxpopupItem`
372
373 ..versionadded:: 1.11
374
375 """
376 def __get__(self):
377 return _object_item_to_python(elm_ctxpopup_first_item_get(self.obj))
378
379 def first_item_get(self):
380 return _object_item_to_python(elm_ctxpopup_first_item_get(self.obj))
381
382 property last_item:
383 """ The last item of the Ctxpopup.
384
385 :type: :py:class:`CtxpopupItem`
386
387 ..versionadded:: 1.11
388
389 """
390 def __get__(self):
391 return _object_item_to_python(elm_ctxpopup_last_item_get(self.obj))
392
393 def last_item_get(self):
394 return _object_item_to_python(elm_ctxpopup_last_item_get(self.obj))
395
260 property direction_priority: 396 property direction_priority:
261 """The direction priority order of a ctxpopup. 397 """The direction priority order of a ctxpopup.
262 398
diff --git a/examples/elementary/test_ctxpopup.py b/examples/elementary/test_ctxpopup.py
index ce1120f..af874a0 100644
--- a/examples/elementary/test_ctxpopup.py
+++ b/examples/elementary/test_ctxpopup.py
@@ -59,10 +59,33 @@ def cb_item1(li, item):
59 it = item_new(cp, "Sate date and time", "clock") 59 it = item_new(cp, "Sate date and time", "clock")
60 it.disabled = True 60 it.disabled = True
61 61
62 ic = Icon(cp, standard="home", resizable=(False,False))
63 cp.item_prepend("Prepended item", ic, cb_items)
64
62 (x, y) = li.evas.pointer_canvas_xy_get() 65 (x, y) = li.evas.pointer_canvas_xy_get()
63 cp.move(x, y) 66 cp.move(x, y)
64 cp.show() 67 cp.show()
65 68
69 print("\n### Testing items getters 1")
70 for it in cp.items:
71 print("ITEM: " + it.text)
72
73 print("\n### Testing items getters 2")
74 print("FIRST ITEM: " + cp.first_item.text)
75 print("LAST ITEM: " + cp.last_item.text)
76
77 print("\n### Testing items getters 3")
78 it = cp.first_item
79 while it:
80 print("ITEM: " + it.text)
81 it = it.next
82
83 print("\n### Testing items getters 4")
84 it = cp.last_item
85 while it:
86 print("ITEM: " + it.text)
87 it = it.prev
88
66def cb_item2(li, item): 89def cb_item2(li, item):
67 cp = Ctxpopup(li) 90 cp = Ctxpopup(li)
68 it = item_new(cp, "", "home") 91 it = item_new(cp, "", "home")