Search code examples
pythonpython-3.xpluginsgnomegnome-3

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


I'm trying to make an application in Python3 with Gtk and other GNOME technologies. I want to implement a plugin system(preferably libpeas) but it has no documentation for python.

Hence I was translating the C examples, to python. At the point where I have to instantiate PeasExtensionSet.
First tried,

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

Then tried,

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

Then tried,
param.value=window

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

Now I got stuck here. Any help would be appreciated.


Solution

  • This is a known bug and is being tackled here and here.

    We can make it work with some hacky changes in the API and by doing this on the extension-added signal:

    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()