pythongtk3pygobjecttreemodel

Gtk.TreeModel subclassing


being french I am bad in english, sorry.

I upgrade an application running with python and pygtk with python and pyobject for Gtk3. It is difficult to find complete documentation on pyGobject, and I want to map a treemodel with sqlalchemy.

I'm stuck on this error when I want subclassing Gtk.TreeModel :

class AlchemyListStore(Gtk.TreeModel):

def __init__(self, types):
     Gtk.TreeModel.__init__(self)
     ...

The first line return:

...
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

Under pyGtk, it was gtk.GenericTreeModel and it worked well...

I found on Wikibooks a example in C and I quote:

[...] we need some boilerplate code to register our custom model with the GObject type system.

How does it work with pyObject? Is this a good track? Thank you in advance for your help :)


Solution

  • Gtk.TreeModel is an interface not a class so:

    class AlchemyListStore(GObject.Object, Gtk.TreeModel):
        def __init__(self):
            super().__init__()