Search code examples
pythonpython-3.xgtk3pygobjecttreemodel

GenericTreeModel with PyGObject Introspection Gtk+ 3?


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.


Solution

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