I'm trying to write my own Gtk+3-TreeModel based on GenericTreeModel in Python3, but I this error:
AttributeError: 'gi.repository.Gtk' object has no attribute 'GenericTreeModel'
Has GenericTreeModel been renamed?
Thanks in advance.
PyGObject recently gained GenericTreeModel support through pygtkcompat.
This is new in 3.7.90 with a fix in 3.7.91
So now you should be able to migrate GenericTreeModels by using the compatibility module, at least as a start.
So I’ve been coping with this for a while. Here are my results:
As Havok already said: the GenericTreeModel
does not exist anymore and one has to use the normal gtk.TreeModel
interface and override the appropriate methods (naming them do_…
):
class TreeModel(GObject.GObject, gtk.TreeModel):
def do_get_iter(self, iter, path):
…
iter.user_data = whatever()
return True
Inheriting from ListStore or TreeStore does not work when using custom iters etc.
The repository with call information is broken (see launchpad:gtk3#1024492) so that the do_get_iter method is called without the iter argument, so you cannot set custom data on it.
To fix it change the direction for the iter
argument in /usr/share/gir-1.0/Gtk-3.0.gir
from "out"
to "in"
and run:
g-ir-compiler --output=/usr/lib/girepository-1.0/Gtk-3.0.typelib /usr/share/gir-1.0/Gtk-3.0.gir
I could not find any reference to GenericTreeModel in PyGObject nor in Gtk, but I think what you are looking for is just TreeModel:
http://developer.gnome.org/gtk3/stable/GtkTreeModel.html
TreeModel is the interface, is implemented by ListStore, TreeModelFilter, TreeModelSort and TreeStore.
>>> from gi.repository import Gtk
>>> dir(Gtk.TreeModel)
['__bool__', '__class__', '__delattr__', '__delitem__', '__dict__', '__doc__',
'__format__', '__gdoc__', '__getattribute__', '__getitem__', '__gtype__', '__hash__',
'__info__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__nonzero__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', '_convert_row', '_convert_value',
'_getiter', 'filter_new', 'foreach', 'get', 'get_column_type', 'get_flags', 'get_iter',
'get_iter_first', 'get_iter_from_string', 'get_n_columns', 'get_path',
'get_string_from_iter', 'get_value', 'iter_children', 'iter_has_child',
'iter_n_children', 'iter_next', 'iter_nth_child', 'iter_parent', 'iter_previous',
'ref_node', 'row_changed', 'row_deleted', 'row_has_child_toggled', 'row_inserted',
'set_row', 'sort_new_with_model', 'unref_node']
EDIT:
Found what you are looking for in old PyGtk API, sadly, this was a PyGtk-only creation. With the introspection stuff you just get only what Gtk directly provides, so you will have to deal with TreeModel directly.
Hope it helps.