tasn pushed a commit to branch master.

commit 47dd204e2cd5295f8b91750f36891f42d6433232
Author: Simon Busch <[email protected]>
Date:   Wed Jan 7 22:21:28 2009 +0000

    Add working elementary.Toolbar
    
    
    SVN revision: 38497
---
 elementary/elementary.c_elementary.pyx | 45 ++++++++++++++++++++++++++++++++--
 include/elementary/c_elementary.pxd    | 11 ---------
 tests/test.py                          | 43 +++++++++++++++++++++++++++-----
 3 files changed, 80 insertions(+), 19 deletions(-)

diff --git a/elementary/elementary.c_elementary.pyx 
b/elementary/elementary.c_elementary.pyx
index 961eca9..062781a 100644
--- a/elementary/elementary.c_elementary.pyx
+++ b/elementary/elementary.c_elementary.pyx
@@ -710,21 +710,62 @@ cdef object _toolbar_callback_mapping
 _toolbar_callback_mapping = dict()
 
 cdef void _toolbar_callback(void *data, c_evas.Evas_Object *obj, void 
*event_info):
-    pass
+    mapping = _toolbar_callback_mapping.get(<long>event_info)
+    if mapping is not None:
+        callback = mapping["callback"] 
+        if callback is not None and callable(callback):
+            callback(mapping["class"], "clicked")
+    else:
+        print "DEBUG: no callback there for the item!"
 
 cdef class Toolbar(Object):
+    """
+    A toolbar
+    """
     def __init__(self, c_evas.Object parent):
         self._set_obj(elm_toolbar_add(parent.obj))
+
+    def scrollable_set(self, scrollable):
+        """
+        Set the scrollable property
+
+        @parm: L{scrollable}
+        """
+        if scrollable:
+            elm_toolbar_scrollable_set(self.obj, 1)
+        else:
+            elm_toolbar_scrollable_set(self.obj, 0)
        
     def item_add(self, c_evas.Object icon, label, callback):
+        """
+        Adds a new item to the toolbar
+
+        @note: Never pass the the same icon object to more than one item. For 
+               a every item you must create a new icon!
+
+        @parm: L{icon} icon for the item
+        @parm: L{label} label for the item
+        @parm: L{callback} function to click if the user clicked on the item
+        """
         cdef Elm_Toolbar_Item *item
         if icon is not None:
             item = elm_toolbar_item_add(self.obj, icon.obj, label, 
_toolbar_callback, NULL)
         else:
             item = elm_toolbar_item_add(self.obj, NULL, label, 
_toolbar_callback, NULL)
-        
+    
+        # Add a new callback in our mapping dict
+        mapping = dict()
+        mapping["class"] = self
+        mapping["callback"] = callback
+        _toolbar_callback_mapping[<long>item] = mapping
+       
     property clicked:
         def __set__(self, value):
+            """
+            Set the callback function for the clicked-event
+
+            @parm: L{value} callback function
+            """
             self._callback_add("clicked", value)
        
     
diff --git a/include/elementary/c_elementary.pxd 
b/include/elementary/c_elementary.pxd
index 6bcd393..be818d9 100644
--- a/include/elementary/c_elementary.pxd
+++ b/include/elementary/c_elementary.pxd
@@ -61,17 +61,6 @@ cdef extern from "Ecore_X.h":
     ctypedef unsigned int Ecore_X_ID
     ctypedef Ecore_X_ID Ecore_X_Window
 
-# Dirty hack to manage callback functions for the toolbar
-"""
-cdef struct Elm_Toolbar_Item:
-    evas.c_evas.Evas_Object *obj
-    evas.c_evas.Evas_Object *base
-    char *label
-    void (*func) (void *data, evas.c_evas.Evas_Object *obj, void *event_info)
-    void *data
-    evas.c_evas.Evas_Bool selected
-"""
-
 # For Debugging
 """
 cdef extern from "Ecore_Evas.h":
diff --git a/tests/test.py b/tests/test.py
index e53ad33..45482f4 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -549,7 +549,23 @@ def entry_scrolled_clicked(obj, event, *args, **kargs):
     bx.show()
 
 def tb_1(obj, event, *args, **kargs):
-    print "toolbar-item: test"
+    print "toolbar-item: test 1"
+
+def tb_2(obj, event, *args, **kargs):
+    print "toolbar-item: test 2"
+
+def tb_3(obj, event, *args, **kargs):
+    print "toolbar-item: test 3"
+
+def tb_4(obj, event, *args, **kargs):
+    print "toolbar-item: test 4"
+
+def tb_5(obj, event, *args, **kargs):
+    print "toolbar-item: test 5"
+
+
+
+
 
 def toolbar_clicked(obj, event, *args, **kargs):
     win = elementary.Window("entry-scrolled", elementary.ELM_WIN_BASIC)
@@ -565,6 +581,7 @@ def toolbar_clicked(obj, event, *args, **kargs):
     win.resize_object_add(bx)
     bx.size_hint_weight_set(1.0, 1.0)
     bx.show()
+   
     
     ic = elementary.Icon(win)
     ic.file_set("images/logo_small.png")
@@ -576,12 +593,26 @@ def toolbar_clicked(obj, event, *args, **kargs):
     tb = elementary.Toolbar(win)
     tb.size_hint_weight_set(0.0, 0.0)
     tb.size_hint_align_set(-1.0, 0.0)
-    
+  
+    ic = elementary.Icon(win)
+    ic.file_set("images/logo_small.png")
     tb.item_add(ic, "Hello", tb_1)
-    tb.item_add(ic, "World,", tb_1)
-    tb.item_add(ic, "here", tb_1)
-    tb.item_add(ic, "comes", tb_1)
-    tb.item_add(ic, "python-elementary!", tb_1)
+    
+    ic = elementary.Icon(win)
+    ic.file_set("images/logo_small.png")
+    tb.item_add(ic, "World,", tb_2)
+
+    ic = elementary.Icon(win)
+    ic.file_set("images/logo_small.png")
+    tb.item_add(ic, "here", tb_3)
+
+    ic = elementary.Icon(win)
+    ic.file_set("images/logo_small.png")
+    tb.item_add(ic, "comes", tb_4)
+    
+    ic = elementary.Icon(win)
+    ic.file_set("images/logo_small.png")
+    tb.item_add(ic, "python-elementary!", tb_5)
 
     bx.pack_end(tb)
     tb.show()

-- 

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar

Reply via email to