davemds pushed a commit to branch master.

http://git.enlightenment.org/bindings/python/python-efl.git/commit/?id=c2a34f20ad2ba457b768b66d2730617a1e0d7279

commit c2a34f20ad2ba457b768b66d2730617a1e0d7279
Author: davemds <[email protected]>
Date:   Thu Feb 27 20:52:10 2014 +0100

    Python-EFL: Colorselector new 1.9 API
---
 efl/elementary/colorselector.pxd          |  7 +++--
 efl/elementary/colorselector.pyx          | 44 ++++++++++++++++++++++++-------
 examples/elementary/test_colorselector.py | 26 ++++++++++++++++++
 3 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/efl/elementary/colorselector.pxd b/efl/elementary/colorselector.pxd
index c0f814a..8f6b018 100644
--- a/efl/elementary/colorselector.pxd
+++ b/efl/elementary/colorselector.pxd
@@ -1,5 +1,5 @@
-from efl.evas cimport Evas_Object, const_Evas_Object, const_Eina_List
-from object_item cimport Elm_Object_Item
+from efl.evas cimport Evas_Object, const_Evas_Object, const_Eina_List, 
Eina_Bool
+from object_item cimport Elm_Object_Item, const_Elm_Object_Item
 from enums cimport Elm_Colorselector_Mode
 from libc.string cimport const_char
 
@@ -16,3 +16,6 @@ cdef extern from "Elementary.h":
     void                    elm_colorselector_palette_name_set(Evas_Object 
*obj, const_char *palette_name)
     const_char *            elm_colorselector_palette_name_get(Evas_Object 
*obj)
     const_Eina_List *       
elm_colorselector_palette_items_get(const_Evas_Object *obj)
+    Eina_Bool               
elm_colorselector_palette_item_selected_get(const_Elm_Object_Item *it)
+    void                    
elm_colorselector_palette_item_selected_set(Elm_Object_Item *it, Eina_Bool 
selected)
+    Elm_Object_Item *       
elm_colorselector_palette_selected_item_get(const_Evas_Object *obj)
diff --git a/efl/elementary/colorselector.pyx b/efl/elementary/colorselector.pyx
index 1d25540..f75817b 100644
--- a/efl/elementary/colorselector.pyx
+++ b/efl/elementary/colorselector.pyx
@@ -131,6 +131,26 @@ cdef class ColorselectorPaletteItem(ObjectItem):
     def color_set(self, r, g, b, a):
         elm_colorselector_palette_item_color_set(self.item, r, g, b, a)
 
+    property selected:
+        """Whenever the palette item is selected or not.
+
+        :type: bool
+
+        .. versionadded:: 1.9
+
+        """
+        def __get__(self):
+            return bool(elm_colorselector_palette_item_selected_get(self.item))
+
+        def __set__(self, bint selected):
+            elm_colorselector_palette_item_selected_set(self.item, selected)
+
+    def selected_get(self):
+        return bool(elm_colorselector_palette_item_selected_get(self.item))
+    def selected_set(self, bint selected):
+        elm_colorselector_palette_item_selected_set(self.item, selected)
+
+
 cdef class Colorselector(LayoutClass):
 
     """This is the class that actually implements the widget."""
@@ -242,22 +262,28 @@ cdef class Colorselector(LayoutClass):
         
         """
         cdef:
-            const_Eina_List *lst = 
elm_colorselector_palette_items_get(self.obj)
-            Elm_Object_Item *obj_item
-            int r, g, b, a
             list ret = list()
-            ColorselectorPaletteItem item
+            const_Eina_List *lst = 
elm_colorselector_palette_items_get(self.obj)
 
         while lst:
-            obj_item = <Elm_Object_Item *>lst.data
-            elm_colorselector_palette_item_color_get(obj_item, &r, &g, &b, &a)
-            item = ColorselectorPaletteItem(r, g, b, a)
-            item._set_obj(obj_item)
-            ret.append(item)
+            ret.append(_object_item_to_python(<Elm_Object_Item *>lst.data))
             lst = lst.next
 
         return ret
 
+    def palette_selected_item_get(self):
+        """palette_selected_item_get()
+
+        Get the selected item in the palette.
+
+        :return: the selected item.
+        :rtype: list of :py:class:`ColorselectorPaletteItem`
+
+        .. versionadded:: 1.9
+
+        """
+        cdef Elm_Object_Item *it = 
elm_colorselector_palette_selected_item_get(self.obj)
+        return _object_item_to_python(it)
 
     def callback_changed_add(self, func, *args, **kwargs):
         """When the color value changes on selector"""
diff --git a/examples/elementary/test_colorselector.py 
b/examples/elementary/test_colorselector.py
index 2021c31..becc14c 100644
--- a/examples/elementary/test_colorselector.py
+++ b/examples/elementary/test_colorselector.py
@@ -40,6 +40,15 @@ def cb_cs_item_lp(cs, item, rect):
     b = (b * a) / 255
     rect.color = (r, g, b, a)
 
+def selected_item_get(bt, cs):
+    item = cs.palette_selected_item_get() 
+    print("Selected: {}".format(item.color if item is not None else None))
+
+def palette_items(bt, cs):
+    for item in cs.palette_items_get():
+        print("Item: {} {}".format(item.color, "<- selected" if item.selected 
else ""))
+
+
 def colorselector_clicked(obj):
     win = StandardWindow("colorselector", "ColorSelector test",
         autodel=True, size=(350,350))
@@ -111,6 +120,23 @@ def colorselector_clicked(obj):
     hbox.pack_end(bt)
     bt.show()
 
+    hbox = Box(win, horizontal=True, size_hint_align=FILL_BOTH,
+        size_hint_weight=EXPAND_HORIZ)
+    vbox.pack_end(hbox)
+    hbox.show()
+
+    bt = Button(win, text="palette items", size_hint_align=FILL_BOTH,
+        size_hint_weight=EXPAND_HORIZ)
+    bt.callback_clicked_add(palette_items, cs)
+    hbox.pack_end(bt)
+    bt.show()
+    
+    bt = Button(win, text="palette selected item", size_hint_align=FILL_BOTH,
+        size_hint_weight=EXPAND_HORIZ)
+    bt.callback_clicked_add(selected_item_get, cs)
+    hbox.pack_end(bt)
+    bt.show()
+
     win.show()
 
 

-- 


Reply via email to