diff options
-rw-r--r-- | README | 5 | ||||
-rw-r--r-- | configure.in | 47 | ||||
-rw-r--r-- | src/caja-python-object.c | 81 | ||||
-rw-r--r-- | src/caja-python.c | 132 | ||||
-rw-r--r-- | src/caja-python.h | 3 |
5 files changed, 59 insertions, 209 deletions
@@ -16,10 +16,9 @@ Try to copy test.py to that directory for an example Requirements ============ -Caja 1.1.0 +Caja 1.1.0 Python 2.3 -PyGtk 2.8.0 -PyGObject 2.16.0 +PyGObject 2.28.0 Problems ======== diff --git a/configure.in b/configure.in index 7fdcc63..e89e6b2 100644 --- a/configure.in +++ b/configure.in @@ -13,8 +13,6 @@ AC_CONFIG_MACRO_DIR([m4]) AC_SUBST(ACLOCAL_AMFLAGS, "-I m4 -I .") CAJA_REQUIRED=1.1.0 -PYGTK_REQUIRED=2.8.0 -PYGOBJECT_REQUIRED=2.16.0 AC_PROG_CC AC_DISABLE_STATIC @@ -40,35 +38,29 @@ dnl ************************************************** AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)]) AM_CHECK_PYTHON_LIBS(,[AC_MSG_ERROR(could not find Python lib)]) +if test "`pkg-config --variable=datadir pygobject-3.0`" != "" ; then + PYGOBJECT_VERSION=pygobject-3.0 + PYGOBJECT_MAJOR_VERSION=3 + PYGOBJECT_MINOR_VERSION=0 + PYGOBJECT_MICRO_VERSION=0 +else + PYGOBJECT_VERSION=pygobject-2.0 + PYGOBJECT_MAJOR_VERSION=2 + PYGOBJECT_MINOR_VERSION=28 + PYGOBJECT_MICRO_VERSION=2 +fi -PKG_CHECK_MODULES(CAJA_PYTHON, [pygtk-2.0 >= $PYGTK_REQUIRED - pygobject-2.0 >= $PYGOBJECT_REQUIRED - libcaja-extension >= $CAJA_REQUIRED]) - -AC_MSG_CHECKING(for pygtk defs) -PYGTK_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0` -AC_SUBST(PYGTK_DEFSDIR) -AC_MSG_RESULT($PYGTK_DEFSDIR) - -AC_MSG_CHECKING(for pygtk codegen) -PYGTK_CODEGEN="$PYTHON `$PKG_CONFIG --variable=codegendir pygtk-2.0`/codegen.py" -AC_SUBST(PYGTK_CODEGEN) -AC_MSG_RESULT($PYGTK_CODEGEN) +PYGOBJECT_REQUIRED=$PYGOBJECT_MAJOR_VERSION.$PYGOBJECT_MINOR_VERSION.$PYGOBJECT_MICRO_VERSION +AC_DEFINE_UNQUOTED(PYGOBJECT_MAJOR_VERSION,[$PYGOBJECT_MAJOR_VERSION], [PyGObject major version.]) +AC_DEFINE_UNQUOTED(PYGOBJECT_MINOR_VERSION,[$PYGOBJECT_MINOR_VERSION], [PyGObject minor version.]) +AC_DEFINE_UNQUOTED(PYGOBJECT_MICRO_VERSION,[$PYGOBJECT_MICRO_VERSION], [PyGObject micro version.]) -AC_MSG_CHECKING(for pygobject defs) -PYGOBJECT_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygobject-2.0` -AC_SUBST(PYGOBJECT_DEFSDIR) -AC_MSG_RESULT($PYGOBJECT_DEFSDIR) +PKG_CHECK_MODULES(CAJA_PYTHON, [$PYGOBJECT_VERSION >= $PYGOBJECT_REQUIRED + libcaja-extension >= $CAJA_REQUIRED]) -PYGOBJECT_DATADIR=`$PKG_CONFIG --variable=datadir pygobject-2.0` +PYGOBJECT_DATADIR=`$PKG_CONFIG --variable=datadir $PYGOBJECT_VERSION` AC_SUBST(PYGOBJECT_DATADIR) -PYGOBJECT_PYGDOCS="`$PKG_CONFIG --variable=pygdocs pygobject-2.0`" -AC_SUBST(PYGOBJECT_PYGDOCS) - -PYGOBJECT_FIXXREF="$PYTHON `$PKG_CONFIG --variable=fixxref pygobject-2.0`" -AC_SUBST(PYGOBJECT_FIXXREF) - CAJA_LIBDIR=`$PKG_CONFIG --variable=libdir libcaja-extension` AC_SUBST(CAJA_LIBDIR) AC_DEFINE_UNQUOTED(CAJA_LIBDIR, "$CAJA_LIBDIR", [Caja libdir]) @@ -104,6 +96,7 @@ AC_OUTPUT([ echo echo " caja-python $VERSION" echo -echo " Caja Prefix: ${prefix}" +echo " Caja Prefix: ${prefix}" +echo " PyGObject Version: ${PYGOBJECT_VERSION}" echo " Documentation: ${enable_gtk_doc}" echo diff --git a/src/caja-python-object.c b/src/caja-python-object.c index 7a2025d..fb9d3d7 100644 --- a/src/caja-python-object.c +++ b/src/caja-python-object.c @@ -128,6 +128,17 @@ free_pygobject_data_list(GList *list) g_list_foreach(list, (GFunc)free_pygobject_data, NULL); } +static PyObject * +caja_python_boxed_new (PyTypeObject *type, gpointer boxed, gboolean free_on_dealloc) +{ + PyGBoxed *self = (PyGBoxed *) type->tp_alloc (type, 0); + self->gtype = pyg_type_from_object ( (PyObject *) type); + self->boxed = boxed; + self->free_on_dealloc = free_on_dealloc; + + return (PyObject *) self; +} + #define METHOD_NAME "get_property_pages" static GList * caja_python_object_get_property_pages (CajaPropertyPageProvider *provider, @@ -149,7 +160,7 @@ caja_python_object_get_property_pages (CajaPropertyPageProvider *provider, "(N)", py_files); HANDLE_RETVAL(py_ret); - HANDLE_LIST(py_ret, CajaPropertyPage, "caja.PropertyPage"); + HANDLE_LIST(py_ret, CajaPropertyPage, "Caja.PropertyPage"); beach: Py_XDECREF(py_ret); @@ -222,7 +233,6 @@ caja_python_object_get_file_items (CajaMenuProvider *provider, GList *ret = NULL; PyObject *py_ret = NULL, *py_files; PyGILState_STATE state = pyg_gil_state_ensure(); - PyObject *provider_version = NULL; debug_enter(); @@ -252,7 +262,7 @@ caja_python_object_get_file_items (CajaMenuProvider *provider, HANDLE_RETVAL(py_ret); - HANDLE_LIST(py_ret, CajaMenuItem, "caja.MenuItem"); + HANDLE_LIST(py_ret, CajaMenuItem, "Caja.MenuItem"); beach: free_pygobject_data_list(files); @@ -299,7 +309,7 @@ caja_python_object_get_background_items (CajaMenuProvider *provider, HANDLE_RETVAL(py_ret); - HANDLE_LIST(py_ret, CajaMenuItem, "caja.MenuItem"); + HANDLE_LIST(py_ret, CajaMenuItem, "Caja.MenuItem"); beach: free_pygobject_data(file, NULL); @@ -309,58 +319,10 @@ caja_python_object_get_background_items (CajaMenuProvider *provider, } #undef METHOD_NAME -#define METHOD_NAME "get_toolbar_items" -static GList * -caja_python_object_get_toolbar_items (CajaMenuProvider *provider, - GtkWidget *window, - CajaFileInfo *file) -{ - CajaPythonObject *object = (CajaPythonObject*)provider; - GList *ret = NULL; - PyObject *py_ret = NULL; - PyGILState_STATE state = pyg_gil_state_ensure(); - - debug_enter(); - - CHECK_OBJECT(object); - - 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, CajaMenuItem, "caja.MenuItem"); - - beach: - free_pygobject_data(file, NULL); - Py_XDECREF(py_ret); - pyg_gil_state_release(state); - return ret; -} -#undef METHOD_NAME - static void caja_python_object_menu_provider_iface_init (CajaMenuProviderIface *iface) { iface->get_background_items = caja_python_object_get_background_items; - iface->get_toolbar_items = caja_python_object_get_toolbar_items; iface->get_file_items = caja_python_object_get_file_items; } @@ -370,7 +332,7 @@ caja_python_object_get_columns (CajaColumnProvider *provider) { CajaPythonObject *object = (CajaPythonObject*)provider; GList *ret = NULL; - PyObject *py_ret; + PyObject *py_ret = NULL; PyGILState_STATE state = pyg_gil_state_ensure(); \ debug_enter(); @@ -383,10 +345,11 @@ caja_python_object_get_columns (CajaColumnProvider *provider) HANDLE_RETVAL(py_ret); - HANDLE_LIST(py_ret, CajaColumn, "caja.Column"); + HANDLE_LIST(py_ret, CajaColumn, "Caja.Column"); beach: - Py_XDECREF(py_ret); + if (py_ret != NULL) + Py_XDECREF(py_ret); pyg_gil_state_release(state); return ret; } @@ -406,6 +369,7 @@ caja_python_object_cancel_update (CajaInfoProvider *provider, { CajaPythonObject *object = (CajaPythonObject*)provider; PyGILState_STATE state = pyg_gil_state_ensure(); + PyObject *py_handle = caja_python_boxed_new (_PyCajaOperationHandle_Type, handle, FALSE); debug_enter(); @@ -415,7 +379,7 @@ caja_python_object_cancel_update (CajaInfoProvider *provider, PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME, "(NN)", pygobject_new((GObject*)provider), - pyg_pointer_new(G_TYPE_POINTER, handle)); + py_handle); beach: pyg_gil_state_release(state); @@ -432,7 +396,8 @@ caja_python_object_update_file_info (CajaInfoProvider *provider, CajaPythonObject *object = (CajaPythonObject*)provider; CajaOperationResult ret = CAJA_OPERATION_COMPLETE; PyObject *py_ret = NULL; - PyGILState_STATE state = pyg_gil_state_ensure(); \ + PyGILState_STATE state = pyg_gil_state_ensure(); + PyObject *py_handle = caja_python_boxed_new (_PyCajaOperationHandle_Type, *handle, FALSE); debug_enter(); @@ -443,7 +408,7 @@ caja_python_object_update_file_info (CajaInfoProvider *provider, py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX "update_file_info_full", "(NNNN)", pygobject_new((GObject*)provider), - pyg_pointer_new(G_TYPE_POINTER, *handle), + py_handle, pyg_boxed_new(G_TYPE_CLOSURE, update_complete, TRUE, TRUE), pygobject_new((GObject*)file)); } diff --git a/src/caja-python.c b/src/caja-python.c index 01b3bc6..3826c1e 100644 --- a/src/caja-python.c +++ b/src/caja-python.c @@ -23,7 +23,8 @@ #include <Python.h> #include <pygobject.h> -#include <pygtk/pygtk.h> +#include <gmodule.h> +#include <gtk/gtk.h> #include "caja-python.h" #include "caja-python-object.h" @@ -44,73 +45,16 @@ static GArray *all_types = NULL; static inline gboolean np_init_pygobject(void) { - PyObject *gobject = PyImport_ImportModule("gobject"); - if (gobject != NULL) - { - PyObject *mdict = PyModule_GetDict(gobject); - PyObject *cobject = PyDict_GetItemString(mdict, "_PyGObject_API"); - if (PyCObject_Check(cobject)) - { - _PyGObject_API = (struct _PyGObject_Functions *)PyCObject_AsVoidPtr(cobject); - } - else - { - PyErr_SetString(PyExc_RuntimeError, - "could not find _PyGObject_API object"); - PyErr_Print(); - return FALSE; - } - } - else - { - PyErr_Print(); - g_warning("could not import gobject"); - return FALSE; - } - return TRUE; -} + PyObject *gobject = pygobject_init (PYGOBJECT_MAJOR_VERSION, PYGOBJECT_MINOR_VERSION, PYGOBJECT_MICRO_VERSION); -static inline gboolean -np_init_pygtk(void) -{ - PyObject *pygtk = PyImport_ImportModule("gtk._gtk"); - if (pygtk != NULL) - { -#ifdef Py_CAPSULE_H - void *capsule = PyCapsule_Import("gtk._gtk._PyGtk_API", 0); - if (capsule) - { - _PyGtk_API = (struct _PyGtk_FunctionStruct*)capsule; - } -#endif - if (!_PyGtk_API) - { - PyObject *module_dict = PyModule_GetDict(pygtk); - PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API"); - if (PyCObject_Check(cobject)) - { - _PyGtk_API = (struct _PyGtk_FunctionStruct*) - PyCObject_AsVoidPtr(cobject); - } - else - { - PyErr_SetString(PyExc_RuntimeError, - "could not find _PyGtk_API object"); - PyErr_Print(); - return FALSE; - } - } - } - else - { - PyErr_Print(); - g_warning("could not import gtk._gtk"); + if (gobject == NULL) { + PyErr_Print (); return FALSE; } + return TRUE; } - static void caja_python_load_file(GTypeModule *type_module, const gchar *filename) @@ -193,6 +137,7 @@ caja_python_load_dir (GTypeModule *module, { g_warning("caja_python_init_python failed"); g_dir_close(dir); + break; } /* sys.path.insert(0, dirname) */ @@ -209,8 +154,7 @@ caja_python_load_dir (GTypeModule *module, static gboolean caja_python_init_python (void) { - PyObject *pygtk, *mdict, *require; - PyObject *sys_path, *tmp, *caja, *gtk, *pygtk_version, *pygtk_required_version; + PyObject *caja; GModule *libpython; char *argv[] = { "caja", NULL }; @@ -246,23 +190,6 @@ caja_python_init_python (void) return FALSE; } - /* pygtk.require("2.0") */ - debug("pygtk.require(\"2.0\")"); - pygtk = PyImport_ImportModule("pygtk"); - if (!pygtk) - { - PyErr_Print(); - return FALSE; - } - mdict = PyModule_GetDict(pygtk); - require = PyDict_GetItemString(mdict, "require"); - PyObject_CallObject(require, Py_BuildValue("(S)", PyString_FromString("2.0"))); - if (PyErr_Occurred()) - { - PyErr_Print(); - return FALSE; - } - /* import gobject */ debug("init_pygobject"); if (!np_init_pygobject()) @@ -271,59 +198,21 @@ caja_python_init_python (void) return FALSE; } - /* import gtk */ - debug("init_pygtk"); - if (!np_init_pygtk()) - { - g_warning("pygtk initialization failed"); - return FALSE; - } - - /* gobject.threads_init() */ - debug("pyg_enable_threads"); - setenv("PYGTK_USE_GIL_STATE_API", "", 0); - pyg_enable_threads(); - - /* gtk.pygtk_version < (2, 4, 0) */ - gtk = PyImport_ImportModule("gtk"); - mdict = PyModule_GetDict(gtk); - pygtk_version = PyDict_GetItemString(mdict, "pygtk_version"); - pygtk_required_version = Py_BuildValue("(iii)", 2, 4, 0); - if (PyObject_Compare(pygtk_version, pygtk_required_version) == -1) - { - g_warning("PyGTK %s required, but %s found.", - PyString_AsString(PyObject_Repr(pygtk_required_version)), - PyString_AsString(PyObject_Repr(pygtk_version))); - Py_DECREF(pygtk_required_version); - return FALSE; - } - Py_DECREF(pygtk_required_version); - - /* sys.path.insert(., ...) */ - debug("sys.path.insert(0, ...)"); - sys_path = PySys_GetObject("path"); - PyList_Insert(sys_path, 0, - (tmp = PyString_FromString(CAJA_LIBDIR "/caja-python"))); - Py_DECREF(tmp); - /* import caja */ g_setenv("INSIDE_CAJA_PYTHON", "", FALSE); debug("import caja"); - caja = PyImport_ImportModule("caja"); + caja = PyImport_ImportModule("gi.repository.Caja"); if (!caja) { PyErr_Print(); return FALSE; } - /* Extract types and interfaces from caja */ - mdict = PyModule_GetDict(caja); - _PyGtkWidget_Type = pygobject_lookup_class(GTK_TYPE_WIDGET); g_assert(_PyGtkWidget_Type != NULL); #define IMPORT(x, y) \ - _PyCaja##x##_Type = (PyTypeObject *)PyDict_GetItemString(mdict, y); \ + _PyCaja##x##_Type = (PyTypeObject *)PyObject_GetAttrString(caja, y); \ if (_PyCaja##x##_Type == NULL) { \ PyErr_Print(); \ return FALSE; \ @@ -338,6 +227,7 @@ caja_python_init_python (void) IMPORT(MenuProvider, "MenuProvider"); IMPORT(PropertyPage, "PropertyPage"); IMPORT(PropertyPageProvider, "PropertyPageProvider"); + IMPORT(OperationHandle, "OperationHandle"); #undef IMPORT diff --git a/src/caja-python.h b/src/caja-python.h index ec6c4c8..9eb312e 100644 --- a/src/caja-python.h +++ b/src/caja-python.h @@ -76,4 +76,7 @@ PyTypeObject *_PyCajaPropertyPage_Type; PyTypeObject *_PyCajaPropertyPageProvider_Type; #define PyCajaPropertyPageProvider_Type (*_PyCajaPropertyPageProvider_Type) +PyTypeObject *_PyCajaOperationHandle_Type; +#define PyCajaOperationHandle_Type (*_PyCajaOperationHandle_Type) + #endif /* CAJA_PYTHON_H */ |