[pygtk] traversing a TreeView

Christian Bird cabird at gmail.com
Wed Jul 7 09:13:28 WST 2004

I've got a question about the best way to iterate over the items in a
TreeView starting with an arbitrary item in the treeview.  I'm trying
to implement a search that starts with the row selected by the user
and then continues searching down the rows, but I can't figure out a
decent way to do it.  Here's the basic layout of my code:

def onSearchActivated(self, widget):
    searchText = widget.get_text()
    (path, column) = self.treeView.get_cursor()
    iter = self.treeStore.get_iter(path)

    for searchIter in <something here>:
        item = self.treeStore.get_value(searchIter, 0)
        if item.prompt.find(searchText) > -1:
            searchPath = self.treeStore.get_path(searchIter)
            self.treeView.set_cursor(searchPath, column, 0)

Does anyone know how to do this?  I'm using python 2.3 so generators
are perfectly acceptable (and preferred since they remove the search
logic from the traversal logic).  I thought of doing a depth first
search, but I want to traverse to siblings of the user selected row's
parent.  Basically, any row that is visually underneath/below the
current row when the tree is completely expanded out.  If anyone has
done this before, I'd love some advice.  Thanks.

Christian Bird

More information about the pygtk mailing list