#!/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("