[nautilus-python] Rename the update_file_info_async method to *_full, and created new _full methods for all three Menu
- From: Adam Plumb <adamplumb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-python] Rename the update_file_info_async method to *_full, and created new _full methods for all three Menu
- Date: Thu, 29 Apr 2010 18:29:08 +0000 (UTC)
commit ed0110225a0f78b5f5f2dda85ebf9f7648812175
Author: Adam Plumb <adamplumb gmail com>
Date: Thu Apr 29 14:28:35 2010 -0400
Rename the update_file_info_async method to *_full, and created new _full methods for all three MenuProvider methods, which allows extensions to emit the items_updated signal.
examples/documentation.py | 88 ++++++++++++++++++++++++++-----
src/nautilus-python-object.c | 117 ++++++++++++++++++++++++++++++++----------
src/nautilus.override | 9 +--
3 files changed, 165 insertions(+), 49 deletions(-)
---
diff --git a/examples/documentation.py b/examples/documentation.py
index c7e70da..fe4d416 100644
--- a/examples/documentation.py
+++ b/examples/documentation.py
@@ -6,6 +6,21 @@ class ColumnProvider:
"""
class MenuProvider:
+ """
+
+ Have your extension sub-class nautilus.MenuProvider and implement the following
+ methods (new code should use the ***_full methods). Any implemented methods
+ will be called by Nautilus to provide a list of nautilus.MenuItems.
+
+ Signals:
+ items_updated: Emitting this signal will cause Nautilus to refresh the
+ menu items returned by a ***_full call. The ***_full methods were
+ created with the extra provider parameter, which is required to
+ emit the items_updated signal. You can emit the signal like so:
+
+ provider.emit("items_updated")
+
+ """
def get_file_items(self, window, files):
"""
@param window the window it was sent from
@@ -16,6 +31,18 @@ class MenuProvider:
@rtype a sequence of nautilus.MenuItems
"""
+ def get_file_items_full(self, provider, window, files):
+ """
+ @param provider a NautilusMenuProvider object
+ @type provider nautilus.MenuProvider
+ @param window the window it was sent from
+ @type window gtk.Window
+ @param files selected files
+ @type files list of nautilus.FileInfo
+ @returns menu items to show
+ @rtype a sequence of nautilus.MenuItems
+ """
+
def get_background_items(self, window, file):
"""
@param window the window it was sent from
@@ -26,6 +53,18 @@ class MenuProvider:
@rtype a sequence of nautilus.MenuItems
"""
+ def get_background_full(self, provider, window, file):
+ """
+ @param provider a NautilusMenuProvider object
+ @type provider nautilus.MenuProvider
+ @param window the window it was sent from
+ @type window gtk.Window
+ @param file file that was clicked on
+ @type file nautilus.FileInfo
+ @returns menu items to show
+ @rtype a sequence of nautilus.MenuItems
+ """
+
def get_toolbar_items(self, window, file):
"""
@param window the window it was sent from
@@ -36,6 +75,18 @@ class MenuProvider:
@rtype a sequence of nautilus.MenuItems
"""
+ def get_toolbar_items_full(self, provider, window, file):
+ """
+ @param provider a NautilusMenuProvider object
+ @type provider nautilus.MenuProvider
+ @param window the window it was sent from
+ @type window gtk.Window
+ @param file file that was clicked on
+ @type file nautilus.FileInfo
+ @returns menu items to show
+ @rtype a sequence of nautilus.MenuItems
+ """
+
class PropertyPageProvider:
def get_property_pages(self, files):
"""
@@ -57,18 +108,19 @@ class InfoProvider:
and use together with the other extensions.
"""
- def update_file_info_async(self, file, handle, info):
+ def update_file_info_full(self, provider, handle, closure, file):
"""
- @param file selected file
- @type file list of nautilus.FileInfo
+ @param provider a NautilusInfoProvider object
+ @type provider nautilus.InfoProvider
@param handle unique handle for identifying this update_file_info call
@type handle gpointer
- @param info data that needs to be passed back in a
- self.update_complete_invoke(info) call
- {"handle":<gpointer>, "provider":<gobject>, "closure":<gclosure>}
- @type info dict
+ @param closure a GClosure that is sent to nautilus to report the update is finished
+ @type closure GClosure
+
+ @param file selected file
+ @type file list of nautilus.FileInfo
@returns None, nautilus.OPERATION_COMPLETE,
nautilus.OPERATION_FAILED, or
@@ -79,7 +131,7 @@ class InfoProvider:
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 handle and info variables
+ completed, call the self.update_complete_invoke method, passing the provider, handle and closure variables
as parameters.
Note: This method exists for backwards compatibility reasons. If your
@@ -87,30 +139,36 @@ class InfoProvider:
usage, you must switch to this method.
"""
- def cancel_update(self, handle):
+ def cancel_update(self, provider, handle):
"""
+ @param provider a NautilusInfoProvider object
+ @type provider nautilus.InfoProvider
+
@param handle unique handle for determining which file update call
has been canceled
@type handle gpointer
- This method is called by nautilus when an update_file_info call is being
+ This method is called by nautilus when an update_file_info_full call is being
canceled. This may happen because the user is moving directories or a file
has been deleted, etc. You may use the handle parameter here to match the
handle parameter passed in update_file_info_async.
"""
- def update_complete_invoke(self, handle, info):
+ def update_complete_invoke(self, provider, handle, closure):
"""
+ @param provider a NautilusInfoProvider object
+ @type provider nautilus.InfoProvider
+
@param handle unique handle for determining which file update call
has been canceled
@type handle gpointer
- @param info data for each update_file_info call
- @type info dict
+ @param closure a GClosure that is sent to nautilus to report the update is finished
+ @type closure GClosure
- The extension must call this method for each update_file_info method that
+ The extension must call this method for each update_file_info_full method that
returns the OPERATION_IN_PROGRESS enum. The method must be called with
- the handle and info parameters passed to the update_file_info_async method.
+ the provider, handle, and closure parameters passed to the update_file_info_full method.
"""
class Menu:
diff --git a/src/nautilus-python-object.c b/src/nautilus-python-object.c
index 69f9b1f..b360b71 100644
--- a/src/nautilus-python-object.c
+++ b/src/nautilus-python-object.c
@@ -128,6 +128,23 @@ free_pygobject_data_list(GList *list)
g_list_foreach(list, (GFunc)free_pygobject_data, NULL);
}
+static gboolean
+nautilus_python_provider_api_match(PyObject *instance, gchar *version)
+{
+ PyObject *provider_version;
+ gboolean result = FALSE;
+
+ provider_version = PyObject_GetAttrString(instance, "NAUTILUS_PYTHON_PROVIDER_API");
+ if(provider_version != NULL && g_strcmp0(PyString_AsString(provider_version), version) == 0)
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
#define METHOD_NAME "get_property_pages"
static GList *
nautilus_python_object_get_property_pages (NautilusPropertyPageProvider *provider,
@@ -222,16 +239,34 @@ nautilus_python_object_get_file_items (NautilusMenuProvider *provider,
GList *ret = NULL;
PyObject *py_ret = NULL, *py_files;
PyGILState_STATE state = pyg_gil_state_ensure();
+ PyObject *provider_version = NULL;
debug_enter();
- CHECK_OBJECT(object);
- CHECK_METHOD_NAME(object->instance);
+ CHECK_OBJECT(object);
- CONVERT_LIST(py_files, files);
+ if (PyObject_HasAttrString(object->instance, "get_file_items_full"))
+ {
+ CONVERT_LIST(py_files, files);
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX "get_file_items_full",
+ "(NNN)",
+ pygobject_new((GObject *)provider),
+ pygobject_new((GObject *)window),
+ py_files);
+ }
+ else if (PyObject_HasAttrString(object->instance, "get_file_items"))
+ {
+ CONVERT_LIST(py_files, files);
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
+ "(NN)",
+ pygobject_new((GObject *)window),
+ py_files);
+ }
+ else
+ {
+ goto beach;
+ }
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
- "(NN)", pygobject_new((GObject *)window), py_files);
HANDLE_RETVAL(py_ret);
HANDLE_LIST(py_ret, NautilusMenuItem, "nautilus.MenuItem");
@@ -258,12 +293,26 @@ nautilus_python_object_get_background_items (NautilusMenuProvider *provider,
debug_enter();
CHECK_OBJECT(object);
- CHECK_METHOD_NAME(object->instance);
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
- "(NN)",
- pygobject_new((GObject *)window),
- pygobject_new((GObject *)file));
+ if (PyObject_HasAttrString(object->instance, "get_background_items_full"))
+ {
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX "get_background_items_full",
+ "(NNN)",
+ pygobject_new((GObject *)provider),
+ pygobject_new((GObject *)window),
+ pygobject_new((GObject *)file));
+ }
+ else if (PyObject_HasAttrString(object->instance, "get_background_items"))
+ {
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
+ "(NN)",
+ pygobject_new((GObject *)window),
+ pygobject_new((GObject *)file));
+ }
+ else
+ {
+ goto beach;
+ }
HANDLE_RETVAL(py_ret);
@@ -286,17 +335,32 @@ nautilus_python_object_get_toolbar_items (NautilusMenuProvider *provider,
NautilusPythonObject *object = (NautilusPythonObject*)provider;
GList *ret = NULL;
PyObject *py_ret = NULL;
- PyGILState_STATE state = pyg_gil_state_ensure(); \
+ PyGILState_STATE state = pyg_gil_state_ensure();
debug_enter();
CHECK_OBJECT(object);
- CHECK_METHOD_NAME(object->instance);
- py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
- "(NN)",
- pygobject_new((GObject *)window),
- pygobject_new((GObject *)file));
+ if (PyObject_HasAttrString(object->instance, "get_toolbar_items_full"))
+ {
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX "get_toolbar_items_full",
+ "(NNN)",
+ pygobject_new((GObject *)provider),
+ pygobject_new((GObject *)window),
+ pygobject_new((GObject *)file));
+ }
+ else if (PyObject_HasAttrString(object->instance, "get_toolbar_items"))
+ {
+ py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
+ "(NN)",
+ pygobject_new((GObject *)window),
+ pygobject_new((GObject *)file));
+ }
+ else
+ {
+ goto beach;
+ }
+
HANDLE_RETVAL(py_ret);
HANDLE_LIST(py_ret, NautilusMenuItem, "nautilus.MenuItem");
@@ -366,7 +430,8 @@ nautilus_python_object_cancel_update (NautilusInfoProvider *provider,
CHECK_METHOD_NAME(object->instance);
PyObject_CallMethod(object->instance,
- METHOD_PREFIX METHOD_NAME, "(N)",
+ METHOD_PREFIX METHOD_NAME, "(NN)",
+ pygobject_new((GObject*)provider),
pyg_pointer_new(G_TYPE_POINTER, handle));
beach:
@@ -389,21 +454,17 @@ nautilus_python_object_update_file_info (NautilusInfoProvider *provider,
debug_enter();
CHECK_OBJECT(object);
-
- if (PyObject_HasAttrString(object->instance, "update_file_info_async"))
- {
- PyObject *info = NULL;
- 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));
+ if (PyObject_HasAttrString(object->instance, "update_file_info_full"))
+ {
py_ret = PyObject_CallMethod(object->instance,
- METHOD_PREFIX "update_file_info_async", "(NNN)",
- pygobject_new((GObject*)file),
+ METHOD_PREFIX "update_file_info_full", "(NNNN)",
+ pygobject_new((GObject*)provider),
pyg_pointer_new(G_TYPE_POINTER, *handle),
- info);
+ pyg_boxed_new(G_TYPE_CLOSURE, update_complete, TRUE, TRUE),
+ pygobject_new((GObject*)file));
}
- else if (PyObject_HasAttrString(object->instance, METHOD_NAME))
+ else if (PyObject_HasAttrString(object->instance, "update_file_info"))
{
py_ret = PyObject_CallMethod(object->instance,
METHOD_PREFIX METHOD_NAME, "(N)",
diff --git a/src/nautilus.override b/src/nautilus.override
index de97286..137f0d0 100644
--- a/src/nautilus.override
+++ b/src/nautilus.override
@@ -92,22 +92,19 @@ 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, "OO!:NautilusInfoProvider.update_complete_invoke",
- &py_handle, &PyDict_Type, &info))
+ if (!PyArg_ParseTuple(args, "O!OO:NautilusInfoProvider.update_complete_invoke",
+ &PyNautilusMenuProvider_Type, &py_provider,
+ &py_handle, &py_closure))
{
return NULL;
}
- py_provider = (PyGObject *)PyDict_GetItem(info, Py_BuildValue("s", "provider"));
- py_closure = PyDict_GetItem(info, Py_BuildValue("s", "closure"));
-
closure = pyg_boxed_get(py_closure, GClosure);
handle = pyg_pointer_get(py_handle, NautilusOperationHandle);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]