Commit b24fd963 authored by Simon van der Linden's avatar Simon van der Linden
Browse files

Initial import

parents
.libs/
.deps/
/COPYING
Makefile
Makefile.in
/aclocal.m4
/autom4te.cache/
/config.guess
/config.h
/config.h.in
/config.log
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/ltmain.sh
/m4/
/missing
/py-compile
/pygi-*.tar.gz
/stamp-h1
*.o
*.lo
*.la
*.so
*.pyc
*.gir
*.typelib
.*.swp
ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS = \
-Wall \
-g
SUBDIRS = \
gi \
tests
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
DIE=0
if [ -n "$GNOME2_DIR" ]; then
ACLOCAL_FLAGS="-I $GNOME2_DIR/share/aclocal $ACLOCAL_FLAGS"
LD_LIBRARY_PATH="$GNOME2_DIR/lib:$LD_LIBRARY_PATH"
PATH="$GNOME2_DIR/bin:$PATH"
export PATH
export LD_LIBRARY_PATH
fi
(test -f $srcdir/configure.ac) || {
echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
echo " top-level package directory"
exit 1
}
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: You must have \`autoconf' installed."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
(grep "^IT_PROG_INTLTOOL" $srcdir/configure.ac >/dev/null) && {
(intltoolize --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: You must have \`intltool' installed."
echo "You can get it from:"
echo " ftp://ftp.gnome.org/pub/GNOME/"
DIE=1
}
}
(grep "^AM_PROG_XML_I18N_TOOLS" $srcdir/configure.ac >/dev/null) && {
(xml-i18n-toolize --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: You must have \`xml-i18n-toolize' installed."
echo "You can get it from:"
echo " ftp://ftp.gnome.org/pub/GNOME/"
DIE=1
}
}
(grep "^AM_PROG_LIBTOOL" $srcdir/configure.ac >/dev/null) && {
(libtool --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: You must have \`libtool' installed."
echo "You can get it from: ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
}
(grep "^AM_GLIB_GNU_GETTEXT" $srcdir/configure.ac >/dev/null) && {
(grep "sed.*POTFILES" $srcdir/configure.ac) > /dev/null || \
(glib-gettextize --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: You must have \`glib' installed."
echo "You can get it from: ftp://ftp.gtk.org/pub/gtk"
DIE=1
}
}
(automake --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: You must have \`automake' installed."
echo "You can get it from: ftp://ftp.gnu.org/pub/gnu/"
DIE=1
NO_AUTOMAKE=yes
}
# if no automake, don't bother testing for aclocal
test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "**Error**: Missing \`aclocal'. The version of \`automake'"
echo "installed doesn't appear recent enough."
echo "You can get automake from ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
if test "$DIE" -eq 1; then
exit 1
fi
if test -z "$*"; then
echo "**Warning**: I am going to run \`configure' with no arguments."
echo "If you wish to pass any to it, please specify them on the"
echo \`$0\'" command line."
echo
fi
case $CC in
xlc )
am_opt=--include-deps;;
esac
for coin in `find $srcdir -path $srcdir/CVS -prune -o -name configure.ac -print`
do
dr=`dirname $coin`
if test -f $dr/NO-AUTO-GEN; then
echo skipping $dr -- flagged as no auto-gen
else
echo processing $dr
( cd $dr
aclocalinclude="$ACLOCAL_FLAGS"
if grep "^AM_GLIB_GNU_GETTEXT" configure.ac >/dev/null; then
echo "Creating $dr/aclocal.m4 ..."
test -r $dr/aclocal.m4 || touch $dr/aclocal.m4
echo "Running glib-gettextize... Ignore non-fatal messages."
echo "no" | glib-gettextize --force --copy
echo "Making $dr/aclocal.m4 writable ..."
test -r $dr/aclocal.m4 && chmod u+w $dr/aclocal.m4
fi
if grep "^IT_PROG_INTLTOOL" configure.ac >/dev/null; then
echo "Running intltoolize..."
intltoolize --copy --force --automake
fi
if grep "^AM_PROG_XML_I18N_TOOLS" configure.ac >/dev/null; then
echo "Running xml-i18n-toolize..."
xml-i18n-toolize --copy --force --automake
fi
if grep "^AM_PROG_LIBTOOL" configure.ac >/dev/null; then
if test -z "$NO_LIBTOOLIZE" ; then
echo "Running libtoolize..."
libtoolize --force --copy
fi
fi
echo "Running aclocal $aclocalinclude ..."
aclocal $aclocalinclude
if grep "^A[CM]_CONFIG_HEADER" configure.ac >/dev/null; then
echo "Running autoheader..."
autoheader
fi
echo "Running automake --foreign $am_opt ..."
automake --add-missing --foreign $am_opt
echo "Running autoconf ..."
autoconf
)
fi
done
conf_flags="--enable-maintainer-mode"
if test x$NOCONFIGURE = x; then
echo Running $srcdir/configure $conf_flags "$@" ...
$srcdir/configure $conf_flags "$@" \
&& echo Now type \`make\' to compile. || exit 1
else
echo Skipping configure process.
fi
AC_INIT(pygi, 0.1)
AM_INIT_AUTOMAKE(foreign)
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_MACRO_DIR(m4)
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES])
AM_MAINTAINER_MODE
AC_ISC_POSIX
AC_PROG_CC
AM_PROG_CC_STDC
AC_HEADER_STDC
AM_PROG_LIBTOOL
# Python
AM_PATH_PYTHON(2.5.2)
AC_PATH_TOOL(PYTHON_CONFIG, "/python${PYTHON_VERSION}-config")
if test -z "$PYTHON_CONFIG"; then
AC_MSG_ERROR(Python development tools not found)
fi
PYTHON_INCLUDES=`$PYTHON_CONFIG --includes`
AC_SUBST(PYTHON_INCLUDES)
save_CPPFLAGS="${CPPFLAGS}"
CPPFLAGS+="${PYTHON_INCLUDES}"
AC_CHECK_HEADER(Python.h, , AC_MSG_ERROR(Python headers not found))
CPPFLAGS="${save_CPPFLAGS}"
# GNOME
PKG_CHECK_MODULES(GNOME,
glib-2.0 >= 2.22
gobject-introspection-1.0 >= 0.6.4
pygobject-2.0 >= 2.20
)
INTROSPECTION_SCANNER=`$PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0`
INTROSPECTION_COMPILER=`$PKG_CONFIG --variable=g_ir_compiler gobject-introspection-1.0`
AC_SUBST(INTROSPECTION_SCANNER)
AC_SUBST(INTROSPECTION_COMPILER)
AC_OUTPUT(
Makefile
gi/Makefile
gi/repository/Makefile
gi/overrides/Makefile
tests/Makefile
)
PLATFORM_VERSION = 2.0
pkgincludedir = $(includedir)/pygtk-$(PLATFORM_VERSION)
pkgpyexecdir = $(pyexecdir)/gtk-2.0
SUBDIRS = \
repository \
overrides
pygidir = $(pkgpyexecdir)/gi
pygi_PYTHON = \
types.py \
module.py \
importer.py \
__init__.py
_gi_la_CFLAGS = \
$(PYTHON_INCLUDES) \
$(GNOME_CFLAGS)
_gi_la_LDFLAGS = \
-module \
-avoid-version \
-export-symbols-regex init_gi
_gi_la_LIBADD = \
$(GNOME_LIBS)
_gi_la_SOURCES = \
pygi-repository.c \
pygi-repository.h \
pygi-info.c \
pygi-info.h \
pygi-struct.c \
pygi-struct.h \
pygi-argument.c \
pygi-argument.h \
pygi-type.c \
pygi-type.h \
pygi.h \
pygi-private.h \
pygobject-external.h \
gimodule.c
pygi_LTLIBRARIES = _gi.la
.la.so:
$(LN_S) .libs/$@ $@ || true
all: $(pygi_LTLIBRARIES:.la=.so)
clean-local:
rm -f $(pygi_LTLIBRARIES:.la=.so)
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2005-2009 Johan Dahlin <johan@gnome.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
from __future__ import absolute_import
from ._gi import _API
/* -*- Mode: C; c-basic-offset: 4 -*-
* vim: tabstop=4 shiftwidth=4 expandtab
*
* Copyright (C) 2005-2009 Johan Dahlin <johan@gnome.org>
*
* gimodule.c: wrapper for the gobject-introspection library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include "pygi-private.h"
#include <pygobject.h>
static PyObject *
_wrap_pyg_enum_add (PyObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "g_type", NULL };
PyObject *py_g_type;
GType g_type;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!:enum_add",
kwlist, &PyGTypeWrapper_Type, &py_g_type)) {
return NULL;
}
g_type = pyg_type_from_object(py_g_type);
if (g_type == G_TYPE_INVALID) {
return NULL;
}
return pyg_enum_add(NULL, g_type_name(g_type), NULL, g_type);
}
static PyObject *
_wrap_pyg_flags_add (PyObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "g_type", NULL };
PyObject *py_g_type;
GType g_type;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!:flags_add",
kwlist, &PyGTypeWrapper_Type, &py_g_type)) {
return NULL;
}
g_type = pyg_type_from_object(py_g_type);
if (g_type == G_TYPE_INVALID) {
return NULL;
}
return pyg_flags_add(NULL, g_type_name(g_type), NULL, g_type);
}
static PyObject *
_wrap_pyg_set_object_has_new_constructor (PyObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "g_type", NULL };
PyObject *py_g_type;
GType g_type;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O!:set_object_has_new_constructor",
kwlist, &PyGTypeWrapper_Type, &py_g_type)) {
return NULL;
}
g_type = pyg_type_from_object(py_g_type);
if (!g_type_is_a(g_type, G_TYPE_OBJECT)) {
PyErr_SetString(PyExc_TypeError, "must be a subtype of GObject");
return NULL;
}
pyg_set_object_has_new_constructor(g_type);
Py_RETURN_NONE;
}
static PyMethodDef _pygi_functions[] = {
{ "enum_add", (PyCFunction)_wrap_pyg_enum_add, METH_VARARGS | METH_KEYWORDS },
{ "flags_add", (PyCFunction)_wrap_pyg_flags_add, METH_VARARGS | METH_KEYWORDS },
{ "set_object_has_new_constructor", (PyCFunction)_wrap_pyg_set_object_has_new_constructor, METH_VARARGS | METH_KEYWORDS },
{ NULL, NULL, 0 }
};
struct PyGI_API PyGI_API = {
pygi_type_import_by_g_type
};
PyMODINIT_FUNC
init_gi(void)
{
PyObject *m;
PyObject *api;
m = Py_InitModule("_gi", _pygi_functions);
if (m == NULL) {
return;
}
if (pygobject_init(-1, -1, -1) == NULL) {
return;
}
if (_pygobject_import() < 0) {
return;
}
_pygi_repository_register_types(m);
_pygi_info_register_types(m);
_pygi_struct_register_types(m);
_pygi_argument_init();
api = PyCObject_FromVoidPtr((void *)&PyGI_API, NULL);
if (api == NULL) {
return;
}
PyModule_AddObject(m, "_API", api);
}
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2005-2009 Johan Dahlin <johan@gnome.org>
#
# importer.py: dynamic importer for introspected libraries.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
from __future__ import absolute_import
import sys
import gobject
from ._gi import Repository, RepositoryError
from .module import DynamicModule
repository = Repository.get_default()
class DynamicImporter(object):
# Note: see PEP302 for the Importer Protocol implemented below.
def __init__(self, path):
self.path = path
def find_module(self, fullname, path=None):
if not fullname.startswith(self.path):
return
path, namespace = fullname.rsplit('.', 1)
if path != self.path:
return
try:
repository.require(namespace)
except RepositoryError:
pass
else:
return self
def load_module(self, fullname):
if fullname in sys.modules:
return sys.modules[name]
path, namespace = fullname.rsplit('.', 1)
# Workaround for GObject
if namespace == 'GObject':
sys.modules[fullname] = gobject
return gobject
# Look for an overrides module
overrides_name = 'gi.overrides.%s' % namespace
try:
overrides_type_name = '%sModule' % namespace
overrides_module = __import__(overrides_name, fromlist=[overrides_type_name])
module_type = getattr(overrides_module, overrides_type_name)
except ImportError, e:
module_type = DynamicModule
module = module_type.__new__(module_type)
module.__dict__ = {
'__file__': '<%s>' % fullname,
'__name__': fullname,
'__namespace__': namespace,
'__loader__': self
}
sys.modules[fullname] = module
module.__init__()
return module
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2007-2009 Johan Dahlin <johan@gnome.org>
#
# module.py: dynamic module for introspected libraries.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
from __future__ import absolute_import
import os
import gobject
from ._gi import \
Repository, \
FunctionInfo, \
RegisteredTypeInfo, \
EnumInfo, \
ObjectInfo, \
InterfaceInfo, \
ConstantInfo, \
StructInfo, \
Struct, \
enum_add, \
flags_add
from .types import \
GObjectMeta, \
StructMeta, \
Boxed, \
Function
repository = Repository.get_default()
def get_parent_for_object(object_info):
parent_object_info = object_info.get_parent()
if not parent_object_info:
return object
namespace = parent_object_info.get_namespace()
name = parent_object_info.get_name()
# Workaround for GObject.Object and GObject.InitiallyUnowned.
if namespace == 'GObject' and name == 'Object' or name == 'InitiallyUnowned':
return gobject.GObject