summaryrefslogtreecommitdiff
path: root/src/caja-python.c
diff options
context:
space:
mode:
authorYaakov Selkowitz <[email protected]>2012-12-20 00:40:59 -0600
committerStefano Karapetsas <[email protected]>2013-01-22 14:09:56 +0100
commit29149f504a4e5e28a19b92d9ebb831bb53100a01 (patch)
tree174a381827077bdc3b8c2a0fd3631c2f6f65983c /src/caja-python.c
parent98e016fe4f4b4409a1791ebb7565922153518907 (diff)
downloadpython-caja-29149f504a4e5e28a19b92d9ebb831bb53100a01.tar.bz2
python-caja-29149f504a4e5e28a19b92d9ebb831bb53100a01.tar.xz
Convert to g-i
Diffstat (limited to 'src/caja-python.c')
-rw-r--r--src/caja-python.c132
1 files changed, 11 insertions, 121 deletions
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