python - Gtk.TreeModel 子类化

标签 python gtk3 pygobject treemodel

作为法国人,我的英语不好,抱歉。

我将使用 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/

相关文章:

Python 随机正 bigint - sql 数据类型

c - gtk_action_group_new() 和 GtkStock - 用什么代替?

python - PyGI : Create pixbuf from 0

Python GI Notify 如何调用 Gtk.main()?

python - 对 pygtk3 的自省(introspection)可能吗?

python - 我应该使用型号 ID 来处理订单号吗?

python - 如何在 python 中过滤 .json 数组,以便每个元素中仅显示一个参数?

python - Gtk3 Python - 永久可见的 SearchBar

python - pyplot.contourf() 在指定级别参数时返回错误

gtk3 - Vala 为更高的 GTK/GDK 版本生成不推荐使用的警告