[nautilus-python] Implemented the NautilusInfoProvider.update_complete_invoke() method, allowing the update_file_info(



commit a478da196fc5476731a5b158c2960d6d3db87c00
Author: Adam Plumb <adamplumb gmail com>
Date:   Tue Apr 27 13:03:24 2010 -0400

    Implemented the NautilusInfoProvider.update_complete_invoke() method, allowing the update_file_info() method to be used asynchronously, without blocking the nautilus GUI

 examples/documentation.py    |   23 +++++++++++++++++++++--
 src/nautilus-python-object.c |   14 +++++++++++---
 src/nautilus.override        |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 5 deletions(-)
---
diff --git a/examples/documentation.py b/examples/documentation.py
index c930df7..940c67e 100644
--- a/examples/documentation.py
+++ b/examples/documentation.py
@@ -48,13 +48,32 @@ class PropertyPageProvider:
         """
         
 class InfoProvider:
-    def update_file_info(self, file):
+    def update_file_info(self, file, info):
         """
         @param file   selected file
         @type  file   list of nautilus.FileInfo
 
+        @param info   data that needs to be passed back in a 
+                        self.update_complete_invoke(info) call
+        @type  info   dict
+
+        @returns      None, nautilus.OPERATION_COMPLETE, 
+                        nautilus.OPERATION_FAILED, or 
+                        nautilus.OPERATION_IN_PROGRESS
+
         This is used to update data for file, use the set_data method,
-        and use together with the other extensions
+        and use together with the other extensions.
+        
+        In order to use this method asynchronously, you must return the 
+        nautilus.OPERATION_IN_PROGRESS enum.  Then, when the operation has
+        completed, call the self.update_complete_invoke method, passing the info variable
+        as a parameter.
+        """
+
+    def update_complete_invoke(self, info):
+        """
+        @param  info    unique data for each update_file_info call
+        @type   info    dict
         """
 
 class Menu:
diff --git a/src/nautilus-python-object.c b/src/nautilus-python-object.c
index 13bd58b..329f4fb 100644
--- a/src/nautilus-python-object.c
+++ b/src/nautilus-python-object.c
@@ -370,19 +370,27 @@ nautilus_python_object_update_file_info (NautilusInfoProvider 		*provider,
 {
 	NautilusPythonObject *object = (NautilusPythonObject*)provider;
     NautilusOperationResult ret = NAUTILUS_OPERATION_COMPLETE;
+    
     PyObject *py_ret = NULL;
 	PyGILState_STATE state = pyg_gil_state_ensure();                                    \
+	PyObject *info = NULL;
 	
   	debug_enter();
 
 	CHECK_OBJECT(object);
 	CHECK_METHOD_NAME(object->instance);
+	
+	info = PyDict_New();
+	PyDict_SetItem(info, Py_BuildValue("s", "provider"), pygobject_new((GObject*)provider));
+	PyDict_SetItem(info, Py_BuildValue("s", "closure"), pyg_boxed_new(G_TYPE_CLOSURE, update_complete, TRUE, TRUE));
+	PyDict_SetItem(info, Py_BuildValue("s", "handle"), pyg_pointer_new(G_TYPE_POINTER, *handle));
 
     py_ret = PyObject_CallMethod(object->instance,
-								 METHOD_PREFIX METHOD_NAME, "(N)",
-								 pygobject_new((GObject*)file));
-	HANDLE_RETVAL(py_ret);
+								 METHOD_PREFIX METHOD_NAME, "(NN)",
+								 pygobject_new((GObject*)file),
+								 info);
 
+	HANDLE_RETVAL(py_ret);
 
 	if (!PyInt_Check(py_ret))
 	{
diff --git a/src/nautilus.override b/src/nautilus.override
index a45c917..07be626 100644
--- a/src/nautilus.override
+++ b/src/nautilus.override
@@ -87,3 +87,39 @@ _wrap_nautilus_menu_get_items(PyGObject *self)
     Py_INCREF(Py_None);
     return Py_None;
 }
+%%
+define NautilusInfoProvider.update_complete_invoke args
+static PyObject *
+_wrap_nautilus_info_provider_update_complete_invoke(PyGObject *self, PyObject *args)
+{
+    PyObject *info;
+    PyObject *py_closure, *py_handle;
+    PyGObject *py_provider;
+    GClosure *closure;
+    NautilusOperationHandle *handle;
+    NautilusOperationResult result = NAUTILUS_OPERATION_COMPLETE;
+
+    if (!PyArg_ParseTuple(args, "O!:NautilusInfoProvider.update_complete_invoke", 
+            &PyDict_Type, &info))
+    {
+        return NULL;
+    }
+
+    py_provider = (PyGObject *)PyDict_GetItem(info, Py_BuildValue("s", "provider"));
+    py_closure = PyDict_GetItem(info, Py_BuildValue("s", "closure"));
+    py_handle = PyDict_GetItem(info, Py_BuildValue("s", "handle"));
+
+    closure = pyg_boxed_get(py_closure, GClosure);
+    handle = pyg_pointer_get(py_handle, NautilusOperationHandle);
+
+    nautilus_info_provider_update_complete_invoke(closure, 
+        NAUTILUS_INFO_PROVIDER(py_provider->obj), handle, result);
+
+    Py_DECREF(py_provider);
+    Py_DECREF(py_closure);
+    Py_DECREF(py_handle);
+    Py_DECREF(info);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}



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