Johan Dahlin <[EMAIL PROTECTED]>:
> tor 2003-03-13 klockan 06.29 skrev Eric S. Raymond:
> > Code:
> >
> > def load_record(self, parent, value):
> > "Load a record with a specified value."
> > # This conditional works around an apparent bug.
> > # iter_children doesn't accept None as a synonym for the root.
> > sibling = None
> > if parent != None:
> > print "Looking at: ", parent
> > sibling = self.gtk_model.iter_children(parent)
> > while sibling:
> > if cmp(self.gtk_model.get_value(sibling, OakumGUI.payload_column),
> > value) > 0:
> > break
> > sibling = self.gtk_model.iter_next(sibling)
> > recordlevel = self.gtk_model.insert_before(parent, sibling)
> >
> >
> > Error trace:
> >
> > Looking at: <GtkTreeIter at 0x83afbe8>
> > Traceback (most recent call last):
> > File "./oakum.py", line 1047, in on_data_field_accept
> > self.add_item_post(here)
> > File "./oakum.py", line 980, in add_item_post
> > newrow = self.load_name(zc,text,dnsrecord)
> > File "./oakum.py", line 781, in load_name
> > namelevel = self.load_record(zone_cursor, dns_name)
> > File "./oakum.py", line 767, in load_record
> > sibling = self.gtk_model.iter_children(parent)
> > TypeError: parent should be a GtkTreeIter
>
> Is parent really a GtkTreeIter, are you sure it's not invalidated?
> http://doc/gtk/gtk/2.0/gtktreemodel.html#GTK-TREE-MODEL-ITER-CHILDREN
I'm not sure. I ended up coding this in a different way that avoided the
problem. I can tell you what I *suspect* went wrong -- it looks like
throwing iters as the value associated with an exception invalidates them.
> If you're using a GtkTreeStore model, there should only be one way of
> getting iters invalidated (According to GtkTreeView hacker kris):
>
> <kris> there the iter only gets invalidated when it's poiting to the
> last row being removed
An iter becomes invalid when its row is removed. OK, that makes sense.
Are there any other known circumstances that can invalidate an iter?
> > I had previously noted that iter_children doesn't accept a None
> > argument as an iter object meaning the model root.
>
> This could easily be added, so if None is specified the iter is fetch by
> calling get_iter_root()
That should be fixed, yes.
Also, the diagnostic emitted when a function chokes on an invalid but nonzero
iterator should *not* be a TypeError -- this is misleading, because actually
the type is right but the payload is invalid. It's more like a Python
ValueError.
I suggest that throwing a value error with a message like "iterator invalid"
would be better.
--
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/