tasn pushed a commit to branch master.

commit dfcf6fd084ac3305eb7be7729c46dda78a476f3e
Author: Simon Busch <[email protected]>
Date:   Tue Mar 10 21:18:55 2009 +0000

    Some changes on the object class
    
    - new calls: scale_set, scale_get, focus, _get_obj_addr
    - ability to commit data to a callback function
    
    SVN revision: 39437
---
 elementary/elementary.c_elementary_object.pxi | 56 ++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 5 deletions(-)

diff --git a/elementary/elementary.c_elementary_object.pxi 
b/elementary/elementary.c_elementary_object.pxi
index 5481581..3da7eab 100644
--- a/elementary/elementary.c_elementary_object.pxi
+++ b/elementary/elementary.c_elementary_object.pxi
@@ -16,6 +16,22 @@
 # along with python-elementary.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+cdef object _callback_mappings
+_callback_mappings = dict()
+
+cdef void _object_callback(void *data, c_evas.Evas_Object *obj, void 
*event_info):
+    try:
+        mapping = _callback_mappings.get(<long>obj,None)
+        if mapping is not None:
+            func = mapping.get(<char*>data,None)
+        
+            if not callable(func):
+                raise TypeError("func is not callable")
+        
+            func(mapping["__class__"],<char*>data, mapping.get("__data__", 
None))
+    except Exception, e:
+        traceback.print_exc()
+
 cdef class Object(evas.c_evas.Object):
     """
     elementary.Object
@@ -24,8 +40,18 @@ cdef class Object(evas.c_evas.Object):
     widgets are based on this class
     """
 
+    def scale_set(self, scale):
+        elm_object_scale_set(self.obj, scale)
+        
+    def scale_get(self):
+        cdef double scale
+        scale = elm_object_scale_get(self.obj)
+        return scale
+    
+    def focus(self):
+        elm_object_focus(self.obj)
     
-    def _callback_add(self, event, func):
+    def _callback_add(self, event, args, data = None):
         """Add a callback for this object
 
         Add a function as new callback-function for a specified event. The
@@ -34,21 +60,33 @@ cdef class Object(evas.c_evas.Object):
         @parm: B{event} Name of the event
         @parm: B{func} Function should be called, when the event occured
         """
-        if not callable(func):
-            raise TypeError("func is not callable")
         
         # implement per object event <> func list in global var 
_callback_mappings
         # _object_callback looks for the object, saved in Evas_Object in the 
callback list
         # and calls every func that matched the event
         
+        # if func is an array with two elements the first element is the 
callback
+        # function and the second the data
+        # This allows to assign a callback function to a widget with one line 
...
+        if type(args) == tuple:
+            if len(args) == 2:
+                callback = args[0]
+                data = args[1]
+        else:
+            callback = args
+            
+        if not callable(callback):
+            raise TypeError("callback is not callable")
+        
         mapping = _callback_mappings.get(<long>self.obj, None)
         if mapping is None:
             mapping = dict()
             mapping["__class__"] =  self
-            mapping[event] = func
+            mapping[event] = callback
+            mapping["__data__"] = data
             _callback_mappings[<long>self.obj] = mapping
         else:
-            mapping[event] = func
+            mapping[event] = callback
             _callback_mappings[<long>self.obj] = mapping
         
         # register callback
@@ -67,4 +105,12 @@ cdef class Object(evas.c_evas.Object):
         if mapping is not None:
             mapping.pop(event)
             _callback_mappings[<long>self.obj] = mapping
+            
+    def _get_obj_addr(self):
+        """
+        Return the adress of the internal save Evas_Object
+        
+        @return: Address of saved Evas_Object
+        """
+        return <long>self.obj
 

-- 

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