From 74782ee345e88367f4c4a6bf80e308e2c2a40690 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 4 Oct 2005 14:59:07 +0000 Subject: [PATCH] move over some of the extend stuff that I want to use right now Original commit message from CVS: * configure.ac: * gst/Makefile.am: * gst/extend/Makefile.am: * gst/extend/__init__.py: * gst/extend/pygobject.py: * gst/extend/utils.py: move over some of the extend stuff that I want to use right now --- ChangeLog | 10 +++ configure.ac | 1 + gst/Makefile.am | 2 + gst/extend/Makefile.am | 4 + gst/extend/__init__.py | 21 +++++ gst/extend/pygobject.py | 172 ++++++++++++++++++++++++++++++++++++++++ gst/extend/utils.py | 75 ++++++++++++++++++ 7 files changed, 285 insertions(+) create mode 100644 gst/extend/Makefile.am create mode 100644 gst/extend/__init__.py create mode 100644 gst/extend/pygobject.py create mode 100644 gst/extend/utils.py diff --git a/ChangeLog b/ChangeLog index 295757733b..b43a039925 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-10-04 Thomas Vander Stichele + + * configure.ac: + * gst/Makefile.am: + * gst/extend/Makefile.am: + * gst/extend/__init__.py: + * gst/extend/pygobject.py: + * gst/extend/utils.py: + move over some of the extend stuff that I want to use right now + 2005-10-04 Edward Hervey * codegen/codegen.py: diff --git a/configure.ac b/configure.ac index 700cfbe602..7278af6147 100644 --- a/configure.ac +++ b/configure.ac @@ -146,6 +146,7 @@ AC_OUTPUT([ Makefile codegen/Makefile gst/Makefile + gst/extend/Makefile examples/Makefile pkgconfig/Makefile pkgconfig/gst-python.pc diff --git a/gst/Makefile.am b/gst/Makefile.am index 2c7add5881..1e32cbb804 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -77,3 +77,5 @@ interfaces.c: $(INTERFACES_DEFS) $(INTERFACES_OVERRIDES) $(GEN_FILES) --prefix py$* $*.defs) > gen-$*.c \ && cp gen-$*.c $*.c \ && rm -f gen-$*.c + +SUBDIRS = extend diff --git a/gst/extend/Makefile.am b/gst/extend/Makefile.am new file mode 100644 index 0000000000..56f0639a14 --- /dev/null +++ b/gst/extend/Makefile.am @@ -0,0 +1,4 @@ +pkgpythondir = $(pythondir)/gst/extend + +pygstdir = $(pkgpythondir) +pygst_PYTHON = __init__.py pygobject.py utils.py diff --git a/gst/extend/__init__.py b/gst/extend/__init__.py new file mode 100644 index 0000000000..350c71d2ce --- /dev/null +++ b/gst/extend/__init__.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- Mode: Python -*- +# vi:si:et:sw=4:sts=4:ts=4 +# +# GStreamer python bindings +# Copyright (C) 2002 David I. Lehn +# 2004 Johan Dahlin + +# 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 diff --git a/gst/extend/pygobject.py b/gst/extend/pygobject.py new file mode 100644 index 0000000000..04d378ffb7 --- /dev/null +++ b/gst/extend/pygobject.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python +# -*- Mode: Python -*- +# vi:si:et:sw=4:sts=4:ts=4 +# +# GStreamer python bindings +# Copyright (C) 2004 Johan Dahlin + +# 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 + +""" +PyGTK helper functions +""" + +import sys + +import gobject + +def gobject_set_property(object, property, value): + """ + Set the given property to the given value on the given object. + + @type object: L{gobject.GObject} + @type property: string + @param value: value to set property to + """ + for pspec in gobject.list_properties(object): + if pspec.name == property: + break + else: + raise errors.PropertyError( + "Property '%s' in element '%s' does not exist" % ( + property, object.get_property('name'))) + + if pspec.value_type in (gobject.TYPE_INT, gobject.TYPE_UINT, + gobject.TYPE_INT64, gobject.TYPE_UINT64): + try: + value = int(value) + except ValueError: + msg = "Invalid value given for property '%s' in element '%s'" % ( + property, object.get_property('name')) + raise errors.PropertyError(msg) + + elif pspec.value_type == gobject.TYPE_BOOLEAN: + if value == 'False': + value = False + elif value == 'True': + value = True + else: + value = bool(value) + elif pspec.value_type in (gobject.TYPE_DOUBLE, gobject.TYPE_FLOAT): + value = float(value) + elif pspec.value_type == gobject.TYPE_STRING: + value = str(value) + # FIXME: this is superevil ! we really need to find a better way + # of checking if this property is a param enum + # also, we only allow int for now + elif repr(pspec.__gtype__).startswith("