[pygtk] Tutorial Question...
David M. Cook
dave at davidcook.org
Mon Aug 9 01:18:08 WST 2004
On Sun, Aug 08, 2004 at 05:45:38AM -0400, dave wrote:
> Are we supposed to be talking about TreeStore's here instead of liststores?
>
> I'm currently doing a search on a TreeStore:
> for row in treestore:
> if row[0]==searchedthing:
> return row
Here's what I came up with when someone asked about this back on 7/7:
#untested back-of-the-envelope coding!
#Uses the gtk standard of returning False on match.
def search_func(model, col, key, iter, user_data):
value = model.get_value(iter, col)
return value!=key
def search(model, col, key, iter, search_func, user_data):
if search_func(model, col, key, iter, user_data):
for i in range(model.iter_n_children()):
child = model.iter_nth_child(i)
search(model, col, key, child, search_func, user_data)
else:
yield iter
it = model.get_iter_first()
mysearch = search(model, 0, 'foobar', it, search_func)
matches = list(mysearch)
Dave Cook
More information about the pygtk
mailing list