[nautilus-python/nautilus-3.0] Convert the update_complete closure to a PyGBoxed closure



commit 84c9d80cca137a3c9b97efc9091ac97b66921c51
Author: Adam Plumb <adamplumb gmail com>
Date:   Mon Mar 14 15:08:57 2011 -0400

    Convert the update_complete closure to a PyGBoxed closure

 examples/update-file-info-async.py |    6 +-----
 src/nautilus-python-object.c       |    3 ++-
 src/nautilus-python.c              |   19 ++++++++++++++++++-
 src/nautilus-python.h              |    3 +++
 4 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/examples/update-file-info-async.py b/examples/update-file-info-async.py
index fa02702..f4e4114 100644
--- a/examples/update-file-info-async.py
+++ b/examples/update-file-info-async.py
@@ -7,13 +7,9 @@ class UpdateFileInfoAsync(gobject.GObject, Nautilus.InfoProvider):
     
     def update_file_info_full(self, provider, handle, closure, file):
         print "update_file_info_full"
-        print handle
         gobject.timeout_add_seconds(3, self.update_cb, provider, handle, closure)
         return Nautilus.OperationResult.IN_PROGRESS
         
     def update_cb(self, provider, handle, closure):
         print "update_cb"
-        Nautilus.info_provider_update_complete_invoke(self.hello, provider, handle, Nautilus.OperationResult.FAILED)
-        
-    def hello(self):
-        print "HELLO"
+        Nautilus.info_provider_update_complete_invoke(closure, provider, handle, Nautilus.OperationResult.FAILED)
diff --git a/src/nautilus-python-object.c b/src/nautilus-python-object.c
index 83c9823..bb99384 100644
--- a/src/nautilus-python-object.c
+++ b/src/nautilus-python-object.c
@@ -398,6 +398,7 @@ nautilus_python_object_update_file_info (NautilusInfoProvider 		*provider,
     PyObject *py_ret = NULL;
 	PyGILState_STATE state = pyg_gil_state_ensure();
 	PyObject *py_handle = nautilus_python_boxed_new (_PyNautilusOperationHandle_Type, *handle, FALSE);
+	PyObject *py_update_complete = nautilus_python_boxed_new (_PyGClosure_Type, update_complete, FALSE);
 
   	debug_enter();
 
@@ -409,7 +410,7 @@ nautilus_python_object_update_file_info (NautilusInfoProvider 		*provider,
 									 METHOD_PREFIX "update_file_info_full", "(NNNN)",
 									 pygobject_new((GObject*)provider),
 									 py_handle,
-									 pyg_boxed_new(G_TYPE_CLOSURE, update_complete, TRUE, TRUE),
+									 py_update_complete,
 									 pygobject_new((GObject*)file));
 	}
 	else if (PyObject_HasAttrString(object->instance, "update_file_info"))
diff --git a/src/nautilus-python.c b/src/nautilus-python.c
index 3307690..4487d9e 100644
--- a/src/nautilus-python.c
+++ b/src/nautilus-python.c
@@ -73,7 +73,7 @@ np_init_pygobject(void)
 static inline gboolean
 np_init_pygi(void)
 {
-	PyObject *gi;
+	PyObject *gi, *gobject;
 	
 	gi = PyImport_ImportModule ("gi");
 	if (gi == NULL)
@@ -82,6 +82,23 @@ np_init_pygi(void)
         g_warning("could not import gi");
         return FALSE;
 	}
+
+	gobject = PyImport_ImportModule("gi.repository.GObject");
+	if (gobject)
+	{
+		_PyGClosure_Type = (PyTypeObject *) PyObject_GetAttrString(gobject, "Closure");
+		if (_PyGClosure_Type == NULL)
+		{
+			PyErr_Print();
+			return FALSE;
+		}
+	}
+	else
+	{
+		PyErr_Print();
+		return FALSE;
+	}	
+
 	
 	return TRUE;
 }
diff --git a/src/nautilus-python.h b/src/nautilus-python.h
index f15244f..ee56f4e 100644
--- a/src/nautilus-python.h
+++ b/src/nautilus-python.h
@@ -48,6 +48,9 @@ extern NautilusPythonDebug nautilus_python_debug;
 PyTypeObject *_PyGtkWidget_Type;
 #define PyGtkWidget_Type (*_PyGtkWidget_Type)
 
+PyTypeObject *_PyGClosure_Type;
+#define PyGClosure_Type (*_PyGClosure_Type)
+
 PyTypeObject *_PyNautilusColumn_Type;
 #define PyNautilusColumn_Type (*_PyNautilusColumn_Type)
 



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