'Delete children from start to stop and replace with t even if t is
a list (nil-root tree).  num of children can increase or decrease.
For huge child lists, inserting children can force walking rest of
children to set their childindex; could be slow.'

def replaceChildren(self, startChildIndex, stopChildIndex, newTree):

    if ((startChildIndex >= len(self.children)) or (stopChildIndex >= len(self.children))):
        raise IndexError('indexes    invalid')
    replacingHowMany = ((stopChildIndex - startChildIndex) + 1)
    if newTree.isNil():
        newChildren = newTree.children
    else:
        newChildren = [newTree]
    replacingWithHowMany = len(newChildren)
    delta = (replacingHowMany - replacingWithHowMany)
    if (delta == 0):
        for (idx, child) in enumerate(newChildren):
            self.children[(idx + startChildIndex)] = child
            child.parent = self
            child.childIndex = (idx + startChildIndex)
    else:
        del self.children[startChildIndex:(stopChildIndex + 1)]
        self.children[startChildIndex:startChildIndex] = newChildren
        self.freshenParentAndChildIndexes(startChildIndex)
