Q:

Synchronizing own tree list with GTK TreeView/TreeModel in Python

In my application, I have a class that manages my tree (in brief, is like a filesystem ,where the root contains folders, that contains folder, etc. and also contains files). The problem I have now is that I have duplicated lists, i. e. the class that manages the filesystem, and separately, the TreeView/TreeModel, where I must create the tree using the data. This is needed, because my class has a lot more of methods and properties than the properties shown in the tree. For example, now, when I delete a file, I update my internal tree, and also have to remove the item from the TreeModel.
Is it possible to tell the TreeModel/TreeView to use my own class? Of course, I asume that I will have to modify the class that manages my tree, but what I would like to have is that when I add a file to a folder in my class, it would be automatically added to the TreeView, the same that when I remove it, or modify its name or properties.
Using Python 2.7.12, Ubuntu 16.04, Gtk3 (gi.repository, glade, etc.)

A:

You can have your class implement the TreeModel interface, and use it directly as the model, without having to synchronize between two classes at all!
Have your class extend Gtk.TreeModel, and implement its virtual methods.

