如何使用 Libpeas 为 Python3 Gtk 应用程序制作插件系统?

How to make a plugin system using Libpeas for a Python3 Gtk application?

我正在尝试使用 Gtk 和其他 GNOME 技术在 Python3 中创建一个应用程序。我想实现一个插件系统(最好是 libpeas),但它没有 python.

的文档

因此我将 C examples 翻译成 python。在我必须实例化 PeasExtensionSet 的地方。
第一次尝试,

pset = Peas.ExtensionSet.new(engine, Peas.Activatable, ["window",window])
pset.connect("extension-added", self.on_extension_added, None)
pset.connect("extension-removed", self.on_extension_removed, None)

Error: Expected GObject.Parameter, but got str

然后试了一下,

param = GObject.Parameter()
param.name = "something"
pset = Peas.ExtensionSet.new(engine, Peas.Activatable, [param])
pset.connect("extension-added", self.on_extension_added, None)
pset.connect("extension-removed", self.on_extension_removed, None)

Warning: can't peek value table for type '' which is not currently referenced.
Warning: gvalue.c:188: cannot initialize GValue with type '(null)', this type has no GTypeValueTable implementation
Warning: g_value_copy: assertion 'G_IS_VALUE (src_value)' failed

然后试了一下,
param.value=window

Error: cannot set a structure which has no well-defined ownership transfer rules

现在我卡在这里了。任何帮助,将不胜感激。

这是一个已知错误,正在解决 here and here

我们可以通过 API 中的一些 hacky 更改来使其工作,并通过在 extension-added 信号上执行此操作:

def on_extension_added(self, set, info, activatable):
    # main difference from how normal libpeas plugin system works
    activatable.set_object(self.public_object)
    activatable.activate()