On Sun, 7 Mar 2010 07:46:53 -0600
Kent Tenney <[email protected]> wrote:
> r 3038
>
> I want a list of this node and it's siblings ascending, evidently
> I'm missing something.
Here's my version. You're issue was calling getNthChild from p when you needed
to call it from p's parent. But then you run into the weird way there's not
root level position, so you need a special case for a top level node. Maybe
the function should be called "get_preceeding_siblings". Also index doesn't
need to be passed in really.
Cheers -Terry
def get_children_to(p, index):
"""Return a list of children, not going below ``index``
"""
children = []
counter = 0
parent = p.parent()
if not parent: # top level node case
sib = c.rootPosition()
while sib != p:
children.append(sib)
sib = sib.next()
return children
while True:
children.append(parent.getNthChild(counter))
counter = counter + 1
if counter > index: break
return children
p = c.currentPosition()
index = p.childIndex()
result = get_children_to(p, index)
n = result[0]
g.es("%s %s" % (n, p))
g.es(n.h)
g.es(result)
> I get an error in the snippet below, n.h complains that
> None type has no headstring.
>
> def get_children_to(p, index):
> """Return a list of children, not going below ``index``
> """
> children = []
> counter = 0
> while True:
> children.append(p.getNthChild(counter))
> counter = counter + 1
> if counter > index: break
> return children
>
> p = c.currentPosition()
> index = p.childIndex()
>
> result = get_children_to(p, index)
> n = result[0]
> g.es("%s %s" % (n, p))
> g.es(n.h)
>
> Thanks,
> Kent
>
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected].
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.