[pygtk] Indexing ListStore with iterators
Brad Schick
schickb at gmail.com
Thu Jul 19 09:27:33 WST 2007
While writing a custom sort function for a gtk.ListStore, I found that
using the provided iterator to access the model doesn't work
correctly. In the example sort method below, the two print statements
product different results:
def sort_func( self, model, iter1, iter2 ):
#the following print different values
print model[iter1][0], model[iter2][0]
print model[model.get_path(iter1)][0], model[model.get_path(iter2)][0]
...
I'm not sure if this is a bug, or just not supported because the pygtk
docs only describe using strings and path tuples for python style
indexing. But it seems like using iterators should work as well.
Unfortunately I haven't produced a small repros case. But I did create
a workaround, like this:
class IndexableListStore( gtk.ListStore ):
def __getitem__( self, index ) :
if type(index) == gtk.TreeIter :
index = self.get_path( index )
return gtk.ListStore.__getitem__( self, index )
If this is a bug, and a repro case would help, I'll work on that. If
it is a missing feature, consider this a request :)
-Brad
More information about the pygtk
mailing list