Add overrides for GObject Introspection

This commit is contained in:
Thibault Saunier 2012-08-08 13:59:09 -04:00
parent a4b7a67f84
commit 7ee9ce29ea
7 changed files with 240 additions and 3 deletions

View file

@ -1,4 +1,4 @@
SUBDIRS = common examples testsuite
SUBDIRS = common examples testsuite gi
# include before EXTRA_DIST for win32 assignment
include $(top_srcdir)/common/win32.mak

View file

@ -7,6 +7,8 @@ AC_INIT(GStreamer GObject Introspectin tests for Python , 0.11.92,
http://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer,
gst-python)
AG_GST_INIT
dnl initialize automake
AM_INIT_AUTOMAKE([-Wno-portability 1.10])
@ -36,10 +38,9 @@ AC_SUBST(ACLOCAL_AMFLAGS, "-I m4 -I common/m4")
dnl required versions of other packages
dnl Note that they are runtime requirements
AC_SUBST(GST_REQ, 0.11.92)
AC_SUBST(GSTPB_REQ, 0.11.92)
dnl check for python
dnl AM_PATH_PYTHON(2.2)
dnl AM_PATH_PYTHON(2.5)
AM_PATH_PYTHON
AC_MSG_CHECKING(for python >= 2.5)
prog="
@ -55,10 +56,37 @@ then
else
AC_MSG_ERROR(too old)
fi
AS_AC_EXPAND(PYTHONDIR, $pythondir)
AS_AC_EXPAND(PYEXECDIR, $pyexecdir)
AC_ARG_WITH([pygi_overrides_dir],
AC_HELP_STRING([--with-pygi-overrides-dir], [Path to pygobject overrides directory]))
AC_MSG_CHECKING(for pygobject overrides directory)
if test "x$with_pygi_overrides_dir" = "x" ; then
overrides_dir="`$PYTHON -c 'import gi; print(gi._overridesdir)' 2>/dev/null`"
# fallback if the previous failed
if test "x$overrides_dir" = "x" ; then
overrides_dir="${pyexecdir}/gi/overrides"
fi
else
overrides_dir="$with_pygi_overrides_dir"
fi
PYGI_OVERRIDES_DIR="$overrides_dir"
AC_SUBST(PYGI_OVERRIDES_DIR)
AC_MSG_RESULT($PYGI_OVERRIDES_DIR)
dnl and set the override directory
AC_ARG_WITH([pygi_overrides_dir],
AC_HELP_STRING([--with-pygi-overrides-dir], [Path to pygobject overrides directory]))
AG_GST_VALGRIND_CHECK
dnl set release date/time
#AG_GST_SET_PACKAGE_RELEASE_DATETIME_WITH_NANO([$PACKAGE_VERSION_NANO],
#["${srcdir}/gst-python.doap"],
#[$PACKAGE_VERSION_MAJOR.$PACKAGE_VERSION_MINOR.$PACKAGE_VERSION_MICRO])
AC_OUTPUT([
Makefile
@ -66,4 +94,6 @@ AC_OUTPUT([
common/m4/Makefile
examples/Makefile
testsuite/Makefile
gi/Makefile
gi/overrides/Makefile
])

1
gi/Makefile.am Normal file
View file

@ -0,0 +1 @@
SUBDIRS = overrides

29
gi/__init__.py Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env python
#
# __init__.py
#
# Copyright (C) 2012 Thibault Saunier <thibaul.saunier@collabora.com>
#
# This program 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 program 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 program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# 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 3, or (at your option)
# any later version.
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

169
gi/overrides/Gst.py Normal file
View file

@ -0,0 +1,169 @@
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Gst.py
#
# Copyright (C) 2012 Thibault Saunier <thibault.saunier@collabora.com>
#
# This program 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 program 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 program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# 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 3, or (at your option)
# any later version.
import sys
from ..overrides import override
from ..importer import modules
if sys.version_info >= (3, 0):
_basestring = str
_callable = lambda c: hasattr(c, '__call__')
else:
_basestring = basestring
_callable = callable
Gst = modules['Gst']._introspection_module
__all__ = []
if Gst._version == '0.10':
import warnings
warn_msg = "You have imported the Gst 0.10 module. Because Gst 0.10 \
was not designed for use with introspection some of the \
interfaces and API will fail. As such this is not supported \
by the GStreamer development team and we encourage you to \
port your app to Gst 1 or greater. gst-python is the recomended \
python module to use with Gst 0.10"
warnings.warn(warn_msg, RuntimeWarning)
class Caps(Gst.Caps):
def __new__(cls, *kwargs):
if not kwargs:
return Caps.new_empty()
elif len(kwargs) > 1:
raise TypeError("wrong arguments when creating GstCaps object")
elif isinstance(kwargs[0], str):
return Caps.from_string(kwargs[0])
elif isinstance(kwargs[0], Caps):
return kwargs[0].copy()
raise TypeError("wrong arguments when creating GstCaps object")
def __str__(self):
return self.to_string()
Caps = override(Caps)
__all__.append('Caps')
class ElementFactory(Gst.ElementFactory):
# ElementFactory
def get_longname(self):
return self.get_metadata("long-name")
def get_description(self):
return self.get_metadata("description")
def get_klass(self):
return self.get_metadata("klass")
ElementFactory = override(ElementFactory)
__all__.append('ElementFactory')
class Fraction(Gst.Fraction):
def __init__(self, num, denom=1):
def __gcd(a, b):
while b != 0:
tmp = a
a = b
b = tmp % b
return abs(a)
def __simplify():
num = self.num
denom = self.denom
if num < 0:
num = -num
denom = -denom
# Compute greatest common divisor
gcd = __gcd(num, denom)
if gcd != 0:
num /= gcd
denom /= gcd
self.num = num
self.denom = denom
self.num = num
self.denom = denom
__simplify()
self.type = "fraction"
def __repr__(self):
return '<Gst.Fraction %d/%d>' % (self.num, self.denom)
def __value__(self):
return self.num / self.denom
def __eq__(self, other):
if isinstance(other, Fraction):
return self.num * other.denom == other.num * self.denom
return False
def __ne__(self, other):
return not self.__eq__(other)
def __mul__(self, other):
if isinstance(other, Fraction):
return Fraction(self.num * other.num,
self.denom * other.denom)
elif isinstance(other, int):
return Fraction(self.num * other, self.denom)
raise TypeError
__rmul__ = __mul__
def __div__(self, other):
if isinstance(other, Fraction):
return Fraction(self.num * other.denom,
self.denom * other.num)
elif isinstance(other, int):
return Fraction(self.num, self.denom * other)
return TypeError
def __rdiv__(self, other):
if isinstance(other, int):
return Fraction(self.denom * other, self.num)
return TypeError
def __float__(self):
return float(self.num) / float(self.denom)
Fraction = override(Fraction)
__all__.append('Fraction')
initialized, argv = Gst.init_check(sys.argv)
import _gi_gst
print _gi_gst
sys.argv = list(argv)
if not initialized:
raise RuntimeError("Gst couldn't be initialized")

4
gi/overrides/Makefile.am Normal file
View file

@ -0,0 +1,4 @@
# We install everything in the gi/overrides folder
pygioverridesdir = $(PYGI_OVERRIDES_DIR)
pygioverrides_PYTHON = Gst.py

4
gi/overrides/__init__.py Normal file
View file

@ -0,0 +1,4 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
print __path__, __name__