if iter does not override the __nonzero__ method from object, the
while loop will always evaluate iter as true.  The documenation says
that listtstore.remove sets iter to the next valid row so the original
unless it is the last row in which case the iter is invalidated.  so
the while loop needs to check if iter is valid using
liststore.iter_is_valid:

while self.lstore.iter_is_valid(iter):
       self.lstore.remove(iter)

if remove invalidates iter rather than setting it to the next line,
the documentation needs to be updated.

-Chris
On 18 Nov 2004 14:46:38 -0600, Doug Quale <[EMAIL PROTECTED]> wrote:
> Stuart Hughes <[EMAIL PROTECTED]> writes:
> 
> 
> 
> > I'm reading data from a file into a gtk.ListStore.  Sometimes the
> > number of rows in the file can reduce, so I want to be able to refresh
> > the valid rows, and delete the remaining invalid rows so they don't
> > show up.
> >
> > After refreshing the valid rows (the data runs out), I have an iter
> > that points at the first row that I need to remove.
> >
> > So I tried:
> >
> > while iter:
> >      self.lstore.remove(iter)
> >      iter = self.lstore.iter_next(iter)
> >
> > This mostly works, but sometimes I get:
> >
> >   GtkWarning: file gtkliststore.c: line 590
> > (gtk_list_store_iter_next): assertion `GTK_LIST_STORE
> > (tree_model)->stamp == iter->stamp' failed
> >    iter = self.lstore.iter_next(iter)
> 
> This looks close.  Once you remove(iter), iter is no longer valid so
> you shouldn't use it any longer.  In particular the iter_next(iter)
> following remove(iter) is an error.  GTK+ might not catch this every
> time, but sometimes you would probably get an assertion failure like
> the one you see.
> 
> I think you can make this work if you get the next iter and save it
> before the remove() like this
> 
>     while iter:
>         next = self.lststore.iter_next(iter)
>         self.lstsore.remove(iter)
>         iter = next
> 
> 
> _______________________________________________
> pygtk mailing list   [EMAIL PROTECTED]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
> 


-- 
Christopher Lambacher
[EMAIL PROTECTED]
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to