Some free time opened up, so I wrote c.vnode2position. It's on the
trunk at rev 1386. Here it is::
def vnode2position (self,v):
'''Given a vnode v, construct a valid position p such that p.v =
v.
'''
c = self
stack = []
while v.parents:
parent = v.parents[0]
n = parent.t.children.index(v)
stack.insert(0,(v,n),)
v = parent
v,n = stack.pop()
p = leoNodes.position(v,n,stack)
assert c.positionExists(p)
return p
Notes:
- The 'while' loop will always execute at least once because of the
hidden root vnode, so the call to stack.pop is safe.
- I was probably thinking of p.archivedPosition when I said that this
code might already exist. In fact, the two methods are quite
different.
Let me know if this works for you. I think it is an important
addition to Leo. It's possible that it might need to be modified for
chapters.
Oh! Now I remember. findPositionInChapter does something similar.
Depending on your purposes, you might have to verify that the position
exists in a desired chapter...
Edward
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---