为什么 G_IS_OBJECT(对象)因 Gio.PropertyAction.new 而失败?
Why does G_IS_OBJECT (object) fail for Gio.PropertyAction.new?
在 python3/pygobjects/gtk+3 应用程序中,我试图通过 Gio.PropertyAction
通过切换按钮控制 属性。不幸的是,我似乎无法创建动作。
我把它归结为这个最小的例子:
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 this is the correct way to handle properties. Curiously though, the Python GI API Reference does not know of GObject.GObject
, but has only GObject.Object
and requires it as second argument for Gio.PropertyAction.new
(compare Gio.PropertyAction.new).
我做错了什么?
错误在于,我没有调用父构造函数,即 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()
在 python3/pygobjects/gtk+3 应用程序中,我试图通过 Gio.PropertyAction
通过切换按钮控制 属性。不幸的是,我似乎无法创建动作。
我把它归结为这个最小的例子:
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 this is the correct way to handle properties. Curiously though, the Python GI API Reference does not know of GObject.GObject
, but has only GObject.Object
and requires it as second argument for Gio.PropertyAction.new
(compare Gio.PropertyAction.new).
我做错了什么?
错误在于,我没有调用父构造函数,即 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()