Qui, 2004-11-18 �s 16:06 +0000, Stuart Hughes escreveu: > Hi everyone, > > 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. This is what I tried: > > while iter: > self.lstore.remove(iter) > > But this just got stuck in a tight loop as iter does not seem to > increment to the next row (possibly the pygtk2reference I have is old or > wrong). > > So I tried: > > while iter: > iter = self.lstore.remove(iter) > > But remove seems just to return True, so I get an exception. > > So I tried: > > while iter: > self.lstore.remove(iter) > iter = self.lstore.iter_next(iter)
The problem is that an iterator is like a C pointer. You removed the
row, therefore the pointer no longer points to a valid location. I
think it should be more like this: say 'last_keep_iter' is the iterator
for the last row you want to keep; then:
while True:
iter = self.lstore.iter_next(last_keep_iter)
if iter is None:
break
self.lstore.remove(iter)
I hope this works.
>
> 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)
>
>
> Any ideas/suggestions warmly appreciated.
>
> Regards, Stuart
>
>
>
>
>
>
>
>
> _______________________________________________
> pygtk mailing list [EMAIL PROTECTED]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
--
Gustavo J. A. M. Carneiro
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
The universe is always one step beyond logic.
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
