On Wed, Jun 18, 2008 at 3:48 PM, Terry Brown <[EMAIL PROTECTED]>
wrote:

>
> Whoops, I now find my second approach doesn't work, so back to the
> original question, what's the neatest way to remove nodes matching a
> criteria?


The only good answer is: carefully.  The problem is that deleting a node
invalidates positions.

So my untested guess for how to do this is:

while True:
   if << node matches criterion >>
       << delete the node >>
   else:
       break

In your example, this would translate to:

p = c.currentPosition()
c.beginUpdate()
try:
   while True:
       for child in p.children_iter():
           if child.headString().startswith('*'):
               c.setChanged(True)
               g.es(child.headString())
               child.doDelete()
               break # inhibit 'else' clause of the 'for' loop.
       else: break
finally:
   c.endUpdate()

This should work because p's position doesn't change when it's children are
deleted.  The general case is even harder.  One might have to iterate
repeatedly over the entire outline.

Edward

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to