A script, given in the Post Script, tests the new qtree.yieldVisible 
generator against a much simpler generator, qtree.slowYieldVisible.

Initially this script failed due to what is, in fact, a pretty nifty 
feature, the ability to expand and contract clone *positions* separately 
from the expanded bit in the common vnode, p.v. So the code to expand all 
positions must be something like:

for p in c.all_positions():
    p.v.expandedPositions = []
for p in c.all_positions():
    p.v.expand()
    p.v.expandedPositions.append(p.copy())

Another way to do this correctly is:

for p in c.all_positions():
        p.expand()

But using the corresponding vnode method does not work:

for v in c.all_nodes():
    v.expand()

This does (apparently) work:

for v in c.all_nodes():
    v.expand()
c.redraw()

but calling c.redraw() is a big cheat, because *we are testing the c.redraw 
logic*.

Neither the old redraw code nor the new fast-draw code ever uses 
v.expandedPositions.  This doesn't prove that the new code is correct, it 
just shows that it's equivalent (in this regard) to the old ;-) 

*Summary*

I mention these details because testing the drawing code isn't as 
straightforward as one might think.  A great feature, one that anyone using 
clones uses without realizing it, complicates redraw.  This is one of many 
such facts of life about Leo.  Neither architectural improvements nor 
clever programming is going to sidestep v.expandedPositions.

Edward

P.S. Here is my present testing script, which does pass:

g.cls()
tree = c.frame.tree
if 1: # works
    for p in c.all_positions():
        p.expand()
elif 1: # works
    for p in c.all_positions():
        p.v.expandedPositions = []
    for p in c.all_positions():
        p.v.expand()
        p.v.expandedPositions.append(p.copy())
else: # Doesn't work without the call to c.redraw()
    for v in c.all_nodes():
        v.expand()
    c.redraw() # This would be **wrong**.
aList1 = [z.copy() for z in tree.slowYieldVisible(c.rootPosition())]
aList2 = [z.copy() for z in tree.yieldVisible(c.rootPosition())]
v1 = [z.v for z in aList1]
v2 = [z.v for z in aList2]
try:
    i = 0
    while i < min(len(aList1), len(aList2)) and aList1[i] == aList2[i]:
        # print(i, aList1[i].h)
        i += 1
    if i == len(aList1) == len(aList2):
        print('OK')
    else:
        print('FAIL', i, len(aList1), len(aList2))
    assert aList1 == aList2, (len(aList1), len(aList2))
    assert v1 == v2, (len(v1), len(v2))
finally:
    for v in c.all_nodes():
        v.contract()
    c.redraw()

EKR

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to