I am wondering whether GObject Introspection is currently broken (with Python at least)...
1. Short code example
Let's try this piece of code to obtain a GParamSpec
struct:
# Various imports
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
Gst.init(None)
# Create a Gstreamer element
element = Gst.ElementFactory.make("lamemp3enc")
bitrate_property = element.find_property("bitrate")
Now if I do,
>>> type(bitrate_property)
gobject.GParamSpec
All seems fine as the GParamSpec
structure is what various useful functions feed on.
2. Problem
However, if I try to actually use these structures in Python, I get an exception with absolutely no hint in order to sort things out:
>>> GObject.ParamSpec.get_name(bitrate_property)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-63f0daaa3a81> in <module>()
----> 1 GObject.ParamSpec.get_name(bitrate_property)
TypeError: argument self: Expected GObject.ParamSpec, but got gobject.GParamSpec
3. Obvious problem, no solution?
The problem is obvious: it is expecting a ParamSpec
object but it gets
a GParamSpec
object instead. However,
- The doc seems to imply that
GParamSpec
is the correct object (at least in C); find_property
returns aGParamSpec
, just like it does in C;- there are no equivalent functions in
GObject.GParamSpec
yet such functions do exist (at least in C); - even if a cast is needed, there is no obvious way to cast a
gobject.GParamSpec
to aGObject.ParamSpec
as requested.
Is that a bug? Am I missing something?
EDIT:
For the sake of completeness, my ultimate purpose is to retrieve valid values from GParamSpec
struct. Not their current/default ones. I also want to check whether the value I gave to the set_property
method has been accepted. I want the GParamSpec
type, its valid range (if applicable) or the list of possible values (in enums). Most of that is already implemented in the functions in GObject.ParamSpec
.