Here is a very fast way to iterate all positions for a given vnode:
from leo.core.leoNodes import Position
# or if inside Leo script and you have p instance
# Position = type(p)
def iter_all_positions(v, stack=None):
"""Generates all positions p in this outline where p.v is v"""
if stack is None:stack = []
def allinds(par, ch):
for i, x in enumerate(par.children):
if x is ch: yield i
def stack2pos(stack):
v, i = stack[-1]
return Position(v, i, stack[:-1])
for par in set(v.parents):
for i in allinds(par, v):
stack.insert(0, (v, i))
if par is c.hiddenRootNode:
yield stack2pos(stack)
else:
yield from iter_all_positions(par, stack)
stack.pop(0)
The positions generated are not necessarily in the outline order.
HTH Vitalije
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/cc30c7c6-4067-482d-8fd8-ec54381fea91%40googlegroups.com.