作为法国人,我的英语不好,抱歉。
我将使用 python 和 pygtk 运行的应用程序升级为适用于 Gtk3 的 python 和 pyobject。很难找到关于 pyGobject 的完整文档,我想用 sqlalchemy 映射树模型。
当我想要子类化 Gtk.TreeModel 时,我陷入了这个错误:
class AlchemyListStore(Gtk.TreeModel):
def __init__(self, types):
Gtk.TreeModel.__init__(self)
...
第一行返回:
...
File "/usr/lib64/python3.5/site-packages/gi/types.py", line 205, in _type_register
_gobject.type_register(cls, namespace.get('__gtype_name__'))
TypeError: argument must be a GObject subclass
在 pyGtk 下,它是 gtk.GenericTreeModel 并且运行良好......
我在 Wikibooks 上找到一个 C 语言的例子,我引用:
[...] we need some boilerplate code to register our custom model with the GObject type system.
它如何与 pyObject 一起工作?这是一条好赛道吗? 预先感谢您的帮助:)
最佳答案
Gtk.TreeModel
是一个接口(interface)而不是一个类,因此:
class AlchemyListStore(GObject.Object, Gtk.TreeModel):
def __init__(self):
super().__init__()
关于python - Gtk.TreeModel 子类化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42432728/