如何从Python GObject Instropection访问GParamSpec相关函数?

如何从Python GObject Instropection访问GParamSpec相关函数?,python,gstreamer,pygobject,gobject,Python,Gstreamer,Pygobject,Gobject,我想知道GObject内省目前是否已经中断(至少在Python中是如此) 1.简短代码示例 让我们尝试这段代码以获得GParamSpec结构: # 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

我想知道GObject内省目前是否已经中断(至少在Python中是如此)

1.简短代码示例 让我们尝试这段代码以获得
GParamSpec
结构:

# 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")
现在如果我这样做

>>> type(bitrate_property)
gobject.GParamSpec
所有这些似乎都很好,因为
GParamSpec
结构是其基础

2.问题 但是,如果我尝试在Python中实际使用这些结构,我会得到一个异常,但绝对没有任何提示,以便解决问题:

>>> 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
>>GObject.ParamSpec.get\u名称(比特率\u属性)
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
---->1 GObject.ParamSpec.get_name(比特率_属性)
TypeError:参数self:应为GObject.ParamSpec,但得到了GObject.GParamSpec
3.明显的问题,没有解决方案? 问题是显而易见的:它需要一个
ParamSpec
对象,但它得到了 改为使用
GParamSpec
对象。但是,

  • 文档似乎暗示
    GParamSpec
    是正确的对象(至少在C中是这样)
  • find_属性
    返回一个
    GParamSpec
    ,就像它在C中一样
  • GObject.GParamSpec
    中没有等价的函数,但这些函数确实存在(至少在C中是这样)
  • 即使需要强制转换,也没有明显的方法按照要求将
    gobject.GParamSpec
    强制转换为
    gobject.ParamSpec
那是虫子吗?我错过什么了吗


编辑:


为了完整性,我的最终目的是从
GParamSpec
struct中检索有效值。不是它们当前的/默认的。我还想检查我给
set\u属性
方法的值是否已被接受。我需要
GParamSpec
类型、有效范围(如果适用)或可能值列表(在枚举中)。其中大部分已经在
GObject.ParamSpec

中的函数中实现,我不确定
GObject.ParamSpec
vs
GObject.GParamSpec
中发生了什么,但是您可以作为属性访问param spec的成员:

>>> bitrate_property = element.find_property('bitrate')
>>> print(bitrate_property)
<GParamInt 'bitrate'>
>>> type(bitrate_property)
<type 'gobject.GParamSpec'>
>>> bitrate_property.name
'bitrate'
>>> bitrate_property.minimum
8
>>> bitrate_property.maximum
320
>>比特率\u属性=元素。查找\u属性(“比特率”)
>>>打印(比特率\u属性)
>>>类型(比特率\u属性)
>>>比特率_property.name
“比特率”
>>>比特率_属性最小值
8.
>>>比特率_属性最大值
320

我对Python内省一无所知,但我认为您最终需要的数据是GParamSpec的一个子类型,比如GParamSpecInt。你能把它从结构成员中拉出来吗?