summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/caja-python-object.c81
-rw-r--r--src/caja-python.c132
-rw-r--r--src/caja-python.h3
3 files changed, 37 insertions, 179 deletions
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 */