I have a list L of objects of my class A. This class implements __str__/__repr__, so each object has it's own string representation (not necessary unique). I have a GUI in pygtk, where I have a TreeView widget with only one column. I want to populate it with string representations of the objects in L, but then I want to get selected items as objects, not as string. Is there a way to make TreeView to store list of objects, but display them as stings? If not, then what is the best way to know what objects are selected in the TreeView?
The problem also is that depending on some conditions I can populate TreeView not with the whole L, but with some sublist of it, and so indexes of items in TreeView won't correspond to ones in L.
If the strings are unique you can use a dictionary to link the strings with the objects by using the strings as keys. In this case you can find the objects by its string.
Custom objects in ListStore/TreeStore