[PATCH] two small patches for the hippo python bindings



Hi,

needed to access hippo_canvas_box_sort() from python and also found a
crasher when hippo_canvas_box_find_box_child() returned NULL.

HTH,

Tomeu
Index: python/hippo.override
===================================================================
--- python/hippo.override	(revision 7294)
+++ python/hippo.override	(working copy)
@@ -339,7 +361,10 @@
     
     box_child = hippo_canvas_box_find_box_child(HIPPO_CANVAS_BOX(self->obj), HIPPO_CANVAS_ITEM(child->obj));
 
-    return py_hippo_canvas_box_child_new(box_child);
+    if (box_child)
+        return py_hippo_canvas_box_child_new(box_child);
+    else
+        return Py_None;
 }
 %%
 override hippo_canvas_box_get_layout_children noargs

Index: python/hippo.override
===================================================================
--- python/hippo.override	(revision 7294)
+++ python/hippo.override	(working copy)
@@ -28,6 +28,38 @@
 
 extern Pycairo_CAPI_t *Pycairo_CAPI;
 
+static int
+marshal_compare_child_func(HippoCanvasItem *a, HippoCanvasItem *b, void *data)
+{
+    PyObject *py_a, *py_b;
+	PyObject *compare = (PyObject*) data;
+	PyObject *retobj;
+	PyGILState_STATE state;	
+	int retval = 0;
+	
+    state = pyg_gil_state_ensure();
+	py_a = pygobject_new(G_OBJECT(a));    
+	py_b = pygobject_new(G_OBJECT(b));
+    
+    retobj = PyEval_CallFunction(compare, "(OO)", py_a, py_b);
+
+	Py_DECREF(py_a);
+	Py_DECREF(py_b);
+
+    if (retobj == NULL) {
+        PyErr_Print();
+    } else {
+    	retval = PyInt_AsLong(retobj);
+        if (retval == -1 && PyErr_Occurred())
+            PyErr_Print();    
+    }
+	
+    Py_XDECREF(retobj);
+
+    pyg_gil_state_release(state);
+    
+    return retval;
+}
 %%
 modulename hippo
 %%
@@ -182,38 +214,6 @@
 }
 %%
 override hippo_canvas_box_insert_sorted kwargs
-static int
-marshal_canvas_box_insert_sorted(HippoCanvasItem *a, HippoCanvasItem *b, void *data)
-{
-    PyObject *py_a, *py_b;
-	PyObject *compare = (PyObject*) data;
-	PyObject *retobj;
-	PyGILState_STATE state;	
-	int retval = 0;
-	
-    state = pyg_gil_state_ensure();
-	py_a = pygobject_new(G_OBJECT(a));    
-	py_b = pygobject_new(G_OBJECT(b));
-    
-    retobj = PyEval_CallFunction(compare, "(OO)", py_a, py_b);
-
-	Py_DECREF(py_a);
-	Py_DECREF(py_b);
-
-    if (retobj == NULL) {
-        PyErr_Print();
-    } else {
-    	retval = PyInt_AsLong(retobj);
-        if (retval == -1 && PyErr_Occurred())
-            PyErr_Print();    
-    }
-	
-    Py_XDECREF(retobj);
-
-    pyg_gil_state_release(state);
-    
-    return retval;
-}
 static PyObject *
 _wrap_hippo_canvas_box_insert_sorted(PyGObject *self, PyObject *args, PyObject *kwargs)
 {
@@ -235,12 +235,34 @@
 	hippo_canvas_box_insert_sorted(HIPPO_CANVAS_BOX(self->obj), 
 								   HIPPO_CANVAS_ITEM(item->obj),
 								   flags,
-								   marshal_canvas_box_insert_sorted,
+								   marshal_compare_child_func,
 								   compare);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
 %%
+override hippo_canvas_box_sort kwargs
+static PyObject *
+_wrap_hippo_canvas_box_sort(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { "compare_func", NULL };
+	PyObject *compare;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O:HippoCanvasBox.sort", kwlist,
+    								 &compare))
+        return NULL;
+    if (!PyCallable_Check(compare)) {
+        PyErr_SetString(PyExc_TypeError, "parameter must be callable");
+        return NULL;
+    }	
+
+	hippo_canvas_box_sort(HIPPO_CANVAS_BOX(self->obj), 
+					      marshal_compare_child_func,
+						  compare);
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+%%
 override hippo_canvas_box_align kwargs
 static PyObject *
 _wrap_hippo_canvas_box_align(PyGObject *self, PyObject *args, PyObject *kwargs)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]