Do not try to use new pygobject api if the module is old

master
Yevgen Muntyan 2006-11-13 12:46:31 -06:00
parent a36db404ab
commit 050683cfde
5 changed files with 117 additions and 59 deletions

View File

@ -10,6 +10,7 @@ libmoomod_la_sources = \
libpymoo_la_sources = \
moopython-mod.c \
moopython-pygtkmod.h \
moopython-api.h \
moopython-loader.h \
moopython-loader.c \

View File

@ -14,12 +14,15 @@
#include "config.h"
#include <Python.h>
#define NO_IMPORT_PYGOBJECT
#define NO_IMPORT_PYGTK
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include "mooedit/mooplugin-loader.h"
#include "moopython/moopython-builtin.h"
#include "moopython/moopython-api.h"
#include "moopython/moopython-loader.h"
#include "moopython/pygtk/moo-pygtk.h"
#include "moopython/moopython-pygtkmod.h"
#include "mooutils/moopython.h"
#include "mooutils/mooutils-misc.h"
@ -42,11 +45,7 @@ _moo_python_init (void)
return FALSE;
}
#ifdef pyg_disable_warning_redirections
pyg_disable_warning_redirections ();
#else
moo_reset_log_func ();
#endif
reset_log_func ();
if (!moo_plugin_loader_lookup (MOO_PYTHON_PLUGIN_LOADER_ID))
{

View File

@ -14,12 +14,13 @@
#include "config.h"
#include <Python.h>
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include "moopython/moopython-api.h"
#include "moopython/moopython-loader.h"
#include "moopython/moopython-pygtkmod.h"
#include "mooedit/mooplugin-macro.h"
#include "mooutils/moopython.h"
#include "mooutils/mooutils-misc.h"
static PyObject *sys_module = NULL;
@ -93,13 +94,6 @@ sys_path_remove_dir (const char *dir)
}
static void
func_init_pygobject (void)
{
init_pygobject ();
}
MOO_MODULE_INIT_FUNC_DECL;
MOO_MODULE_INIT_FUNC_DECL
{
@ -141,7 +135,7 @@ MOO_MODULE_INIT_FUNC_DECL
return FALSE;
}
func_init_pygobject ();
init_pygtk_mod ();
if (PyErr_Occurred ())
{
@ -151,11 +145,7 @@ MOO_MODULE_INIT_FUNC_DECL
return FALSE;
}
#ifdef pyg_disable_warning_redirections
pyg_disable_warning_redirections ();
#else
moo_reset_log_func ();
#endif
reset_log_func ();
if (!moo_plugin_loader_lookup (MOO_PYTHON_PLUGIN_LOADER_ID))
{

View File

@ -0,0 +1,106 @@
/*
* moopython-pygtkmod.h
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
#include "mooutils/mooutils-misc.h"
G_GNUC_UNUSED static void
init_pygtk_mod (void)
{
PyObject *gobject, *pygtk;
PyObject *mdict;
PyObject *cobject;
if (!(gobject = PyImport_ImportModule ((char*) "gobject")))
return;
mdict = PyModule_GetDict (gobject);
cobject = PyDict_GetItemString (mdict, "_PyGObject_API");
if (!cobject || !PyCObject_Check (cobject))
{
PyErr_SetString (PyExc_RuntimeError,
"could not find _PyGObject_API object");
return;
}
_PyGObject_API = (struct _PyGObject_Functions *) PyCObject_AsVoidPtr (cobject);
if (!(pygtk = PyImport_ImportModule((char*) "gtk._gtk")))
return;
mdict = PyModule_GetDict (pygtk);
cobject = PyDict_GetItemString (mdict, "_PyGtk_API");
if (!cobject || !PyCObject_Check (cobject))
{
PyErr_SetString (PyExc_RuntimeError,
"could not find _PyGtk_API object");
return;
}
_PyGtk_API = (struct _PyGtk_FunctionStruct*) PyCObject_AsVoidPtr (cobject);
}
static gboolean
check_pygtk_version (const char *module,
int req_major,
int req_minor,
int req_micro)
{
PyObject *mod, *mdict, *version;
int found_major, found_minor, found_micro;
mod = PyImport_ImportModule ((char*) module);
g_return_val_if_fail (mod != NULL, FALSE);
mdict = PyModule_GetDict (mod);
version = PyDict_GetItemString (mdict, "pygobject_version");
if (!version)
version = PyDict_GetItemString (mdict, "pygtk_version");
if (!version)
return FALSE;
if (!PyArg_ParseTuple (version, (char*) "iii",
&found_major, &found_minor, &found_micro))
{
PyErr_Print ();
return FALSE;
}
if (req_major != found_major ||
req_minor > found_minor ||
(req_minor == found_minor && req_micro > found_micro))
return FALSE;
return TRUE;
}
G_GNUC_UNUSED static void
reset_log_func (void)
{
#ifdef pyg_disable_warning_redirections
if (check_pygtk_version ("gobject", 2, 12, 0))
pyg_disable_warning_redirections ();
else
moo_reset_log_func ();
#else
moo_reset_log_func ();
#endif
}

View File

@ -17,13 +17,13 @@
#include "config.h"
#endif
#include "mooutils/mooutils-misc.h"
#include "moopython/pygtk/moo-mod.h"
#include "moopython/pygtk/moo-pygtk.h"
#include "moopython/moopython-utils.h"
#include <pygobject.h> /* _PyGObjectAPI lives here */
#include <pygtk/pygtk.h>
#include <glib.h>
#include "moopython/moopython-pygtkmod.h"
static PyObject *
@ -54,44 +54,6 @@ static PyMethodDef _moo_functions[] = {
static char *_moo_module_doc = (char*)"_moo module.";
static void
func_init_pygobject (void)
{
PyObject *gobject, *pygtk;
PyObject *mdict;
PyObject *cobject;
if (!(gobject = PyImport_ImportModule ((char*) "gobject")))
return;
mdict = PyModule_GetDict (gobject);
cobject = PyDict_GetItemString (mdict, "_PyGObject_API");
if (!cobject || !PyCObject_Check (cobject))
{
PyErr_SetString (PyExc_RuntimeError,
"could not find _PyGObject_API object");
return;
}
_PyGObject_API = (struct _PyGObject_Functions *) PyCObject_AsVoidPtr (cobject);
if (!(pygtk = PyImport_ImportModule((char*) "gtk._gtk")))
return;
mdict = PyModule_GetDict (pygtk);
cobject = PyDict_GetItemString (mdict, "_PyGtk_API");
if (!cobject || !PyCObject_Check (cobject))
{
PyErr_SetString (PyExc_RuntimeError,
"could not find _PyGtk_API object");
return;
}
_PyGtk_API = (struct _PyGtk_FunctionStruct*) PyCObject_AsVoidPtr (cobject);
}
static PyObject *
py_object_from_moo_py_object (const GValue *value)
{
@ -120,7 +82,7 @@ _moo_pygtk_init (void)
{
PyObject *_moo_module, *code, *moo_mod, *submod;
func_init_pygobject ();
init_pygtk_mod ();
if (PyErr_Occurred ())
return FALSE;