tasn pushed a commit to branch master.

commit 97c051eab3f381010e0c8dc29662c626997f8041
Author: Simon Busch <[email protected]>
Date:   Sat Jan 10 12:35:41 2009 +0000

    complete elementary.Toolbar
    
    
    SVN revision: 38534
---
 elementary/elementary.c_elementary.pyx | 108 +++++++++++++++++++--------------
 include/elementary/c_elementary.pxd    |  17 +++++-
 tests/test.py                          |   9 +--
 3 files changed, 82 insertions(+), 52 deletions(-)

diff --git a/elementary/elementary.c_elementary.pyx 
b/elementary/elementary.c_elementary.pyx
index 062781a..3edbdbd 100644
--- a/elementary/elementary.c_elementary.pyx
+++ b/elementary/elementary.c_elementary.pyx
@@ -35,8 +35,6 @@ def init():
 
     elm_init(argc, argv)
 
-    evas.python.PyMem_Free(argv)
-
 def shutdown():
     elm_shutdown()
 
@@ -86,7 +84,7 @@ cdef class Object(evas.c_evas.Object):
         # _object_callback looks for the object, saved in Evas_Object in the 
callback list
         # and calls every func that matched the event
         
-        mapping = _callback_mappings.get(<long>self.obj,None)
+        mapping = _callback_mappings.get(<long>self.obj, None)
         if mapping is None:
             mapping = dict()
             mapping["__class__"] =  self
@@ -98,7 +96,7 @@ cdef class Object(evas.c_evas.Object):
         
         # register callback
         e = event
-        c_evas.evas_object_smart_callback_add(self.obj, event, 
_object_callback,<char *>e)
+        c_evas.evas_object_smart_callback_add(self.obj, event, 
_object_callback, <char *>e)
             
     def _callback_remove(self, event):
         """Removes all callback functions for the event
@@ -108,7 +106,7 @@ cdef class Object(evas.c_evas.Object):
         @parm: B{event} Name of the event whose events should be removed
         """
 
-        mapping = _callback_mappings.get(<long>self.obj,None)
+        mapping = _callback_mappings.get(<long>self.obj, None)
         if mapping is not None:
             mapping.pop(event)
             _callback_mappings[<long>self.obj] = mapping
@@ -131,16 +129,6 @@ cdef class Window(Object):
         """
         self._set_obj(elm_win_add(NULL, name, type))
     
-    """
-    def _print_debug_infos(self):
-        cdef Elm_Win *win
-        cdef int w, h
-        
-        win = <Elm_Win*>c_evas.evas_object_data_get(self.obj, "__Elm")
-        c_evas.evas_object_geometry_get(self.obj,NULL,NULL,&w,&h)
-        print "object-width: %i" % w
-        print "object-height: %i" % h
-    """
     property canvas:
         def __get__(self):
             """
@@ -436,17 +424,8 @@ cdef class Frame(Object):
     def style_set(self, style):
         elm_frame_style_set(self.obj, style)
 
-    # TODO
-    """
-    def best_content_location_get(self, pref_axis):
-        cdef Elm_Hover_Axis axis
-        if pref_axis == ELM_HOVER_AXIS_NONE:
-            axis = Elm_Hover_Axis.ELM_HOVER_AXIS_NONE
-        elif pref_axis == ELM_HOVER_AXIS_HORIZONTAL:
-            axis = Elm_Hover_Axis.ELM_HOVER_AXIS_HORIZONTAL
-
+    def best_content_location_get(self, axis):
         elm_hover_best_content_location_get(self.obj, axis)
-    """
         
 cdef class Table(Object):
     def __init__(self, c_evas.Object parent):
@@ -672,6 +651,22 @@ cdef class Photo(Object):
     def size_set(self, size):
         elm_photo_size_set(self.obj, size)
 
+
+cdef object _hoversel_callback_mapping
+_hoversel_callback_mapping = dict()
+
+cdef void _hoversel_callback(void *data, c_evas.Evas_Object *obj, void 
*event_info):
+    mapping = _hoversel_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 HoverselItem:
+    pass
+
 cdef class Hoversel(Object):
     def __init__(self, c_evas.Object parent):
         self._set_obj(elm_hoversel_add(parent.obj))
@@ -701,10 +696,15 @@ cdef class Hoversel(Object):
     def hover_end(self):
         elm_hoversel_hover_end(self.obj)
     
-    def item_add(self, label, icon_file, icon_type, callback, data):
-        pass
-        
+    def item_add(self, label, icon_file, icon_type, callback):
+        cdef Elm_Hoversel_Item *item
+        item = elm_hoversel_item_add(self.obj, label, icon_file, icon_type, 
_hoversel_callback, NULL)
 
+        # Save the callback
+        mapping = dict()
+        mapping["class"] = self
+        mapping["callback"] = callback
+        _hoversel_callback_mapping[<long>item] = mapping
  
 cdef object _toolbar_callback_mapping
 _toolbar_callback_mapping = dict()
@@ -718,6 +718,35 @@ cdef void _toolbar_callback(void *data, c_evas.Evas_Object 
*obj, void *event_inf
     else:
         print "DEBUG: no callback there for the item!"
 
+cdef class ToolbarItem:
+    """
+    A item for the toolbar
+    """
+    cdef Elm_Toolbar_Item *item
+
+    def __new__(self):
+        self.item = NULL
+
+    def __init__(self, c_evas.Object toolbar, c_evas.Object icon, label, 
callback):
+        if icon is not None:
+            self.item = elm_toolbar_item_add(toolbar.obj, icon.obj, label, 
_toolbar_callback, NULL)
+        else:
+            self.item = elm_toolbar_item_add(toolbar.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>self.item] = mapping
+
+    def delete(self):
+        """Delete the item"""
+        elm_toolbar_item_del(self.item)
+
+    def select(self):
+        """Select the item"""
+        elm_toolbar_item_select(self.item)
+
 cdef class Toolbar(Object):
     """
     A toolbar
@@ -747,18 +776,10 @@ cdef class Toolbar(Object):
         @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
-       
+        # Everything is done in the ToolbarItem class, because of wrapping the
+        # C structures in python classes
+        return ToolbarItem(self, icon, label, callback)
+
     property clicked:
         def __set__(self, value):
             """
@@ -767,9 +788,6 @@ cdef class Toolbar(Object):
             @parm: L{value} callback function
             """
             self._callback_add("clicked", value)
-       
-    
-
-
-
 
+cdef class List(Object):
+    pass
diff --git a/include/elementary/c_elementary.pxd 
b/include/elementary/c_elementary.pxd
index be818d9..ca73384 100644
--- a/include/elementary/c_elementary.pxd
+++ b/include/elementary/c_elementary.pxd
@@ -56,6 +56,11 @@ cdef enum Elm_Icon_Type:
     ELM_ICON_NONE
     ELM_ICON_FILE
     ELM_ICON_STANDARD
+
+cdef enum Elm_List_Mode:
+    ELM_LIST_COMPRESS
+    ELM_LIST_SCROLL
+    ELM_LIST_LIMIT
     
 cdef extern from "Ecore_X.h":
     ctypedef unsigned int Ecore_X_ID
@@ -92,6 +97,7 @@ cdef extern from "Elementary.h":
     cdef struct Elm_Entry_Anchorblock_Info
     cdef struct Elm_Hoversel_Item
     cdef struct Elm_Toolbar_Item
+    cdef struct Elm_List_Item
 
     # Basic elementary functions
     void elm_init(int argc,char** argv)
@@ -256,4 +262,13 @@ cdef extern from "Elementary.h":
     void         elm_toolbar_item_del(Elm_Toolbar_Item *item)
     void         elm_toolbar_item_select(Elm_Toolbar_Item *item)
     void         elm_toolbar_scrollable_set(evas.c_evas.Evas_Object *obj, 
evas.c_evas.Evas_Bool scrollable)
-    
+
+    # List object
+    evas.c_evas.Evas_Object *elm_list_add(evas.c_evas.Evas_Object *parent)
+    Elm_List_Item *elm_list_item_append(evas.c_evas.Evas_Object *obj, char 
*label, evas.c_evas.Evas_Object *icon, evas.c_evas.Evas_Object *indicator, 
evas.c_evas.Evas_Object *end, void (*func)(void *data, evas.c_evas.Evas_Object 
*obj, void *event_info), void *data)
+
+# Forward declaration of some classes
+cdef class Object
+cdef class Hoversel(Object)
+cdef class Toolbar(Object)
+cdef class List(Object)
diff --git a/tests/test.py b/tests/test.py
index 45482f4..495adca 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -563,10 +563,6 @@ def tb_4(obj, event, *args, **kargs):
 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)
     win.title_set("Entry Scrolled")
@@ -596,11 +592,12 @@ def toolbar_clicked(obj, event, *args, **kargs):
   
     ic = elementary.Icon(win)
     ic.file_set("images/logo_small.png")
-    tb.item_add(ic, "Hello", tb_1)
+    item = tb.item_add(ic, "Hello", tb_1)
     
     ic = elementary.Icon(win)
     ic.file_set("images/logo_small.png")
-    tb.item_add(ic, "World,", tb_2)
+    item = tb.item_add(ic, "World,", tb_2)
+    item.select()
 
     ic = elementary.Icon(win)
     ic.file_set("images/logo_small.png")

-- 

------------------------------------------------------------------------------
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