def attachChild(self, newChild, index = None):
"""
Attach a (parentless) child. If the child has a parent
already, call its reattach method
"""
# Don't allow bidirectional parenthood
assert not self is newChild
if newChild.parent():
raise AttachmentError('Cannot attach node: %s to: %s Node is already attached to %s' \
% (newChild.prettyPrint(), self.prettyPrint(), newChild.parent().prettyPrint()))
if index == None:
if not self._children:
self._children.append(newChild)
else:
bisect.insort_right(self._children, newChild)
else:
self._children.insert(index, newChild)
newChild.setParent(self)
评论列表
文章目录