[pygtk] Re: How do I get the previous gtk.TreeIter in a TreeModel?

Jeffrey Barish jeff_barish at earthlink.net
Wed Jul 9 22:58:09 WST 2008


Rich Burridge wrote:
> Given a gtk.TreeIter in a gtk.TreeModel, from:
>
http://www.pygtk.org/docs/pygtk/class-gtktreemodel.html#method-gtktreemodel--iter-next
> 
> I can see how to get the gtk.TreeIter pointing to the next row.
> But how to I get a gtk.TreeIter pointing to the previous row?
> 
> Just in case I'm taking the wrong approach here, what I want to do is move
> one (or more) selected rows, up one row.
> 
> I was expecting the code for the callback for the "Move up one" button
> to be something like:
> 
>     def textMoveUpOneButtonClicked(self, widget):
>         textSelection = self.getTextAttributesView.get_selection()
>         [model, paths] = textSelection.get_selected_rows()
>         for path in paths:
>             iter = model.get_iter(path)
>             prevIter = model.iter_prev(iter)
>             model.swap(iter, prevIter)
> 
> but there is no gtk.TreeMode.iter_prev() function.

Perhaps {TreeStore,ListStore}.insert_{before,after} would be useful.  Also,
you could manipulate path arithmetically (e.g., path[0] - 1) and then
convert path to iter.  Beware, though, if you are using a TreeStore rather
than a ListStore.  Also, I wonder whether you have considered using
drag-and-drop for rearranging rows rather than move buttons.
-- 
Jeffrey Barish



More information about the pygtk mailing list