在python3 / pygobjects / gtk + 3应用程序中,我试图通过Gio.PropertyAction
通过togglebuttons控制属性。不幸的是,我似乎无法创建动作。
我把它归结为这个最小的例子:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, Gtk, GObject
class Obj(GObject.GObject):
prop = GObject.property(type = int)
def __init__(self):
action = Gio.PropertyAction.new('act', self, 'prop')
obj = Obj()
产生此错误:
(test.py:9099): GLib-GIO-CRITICAL **: g_property_action_new: assertion 'G_IS_OBJECT (object)' failed
Traceback (most recent call last):
File "./test.py", line 11, in <module>
obj = Obj()
File "./test.py", line 9, in __init__
action = Gio.PropertyAction.new('act', self, 'prop')
TypeError: constructor returned NULL
根据Python GTK+ 3 Tutorial,这是处理属性的正确方法。但奇怪的是,Python GI API Reference不知道GObject.GObject
,但只有GObject.Object
,并且要求Gio.PropertyAction.new
作为第二个参数(比较Gio.PropertyAction.new)。
我做错了什么?
答案 0 :(得分:0)
错误是,我没有调用父构造函数,即GObject.GObject
的构造函数。以下作品:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, Gtk, GObject
class Obj(GObject.GObject):
prop = GObject.property(type = int)
def __init__(self):
super().__init__()
action = Gio.PropertyAction.new('act', self, 'prop')
obj = Obj()