Fix DeleteChildren in HyperTreeList

The TreeListItem.DeleteChildren() method iterates over the list of a
parent item's children (self._children) and calls tree.Delete(child)
on each one (hypertreelist.py line 1365):
	for child in list(self._children):
		child.DeleteChildren(tree)
		if tree:
			tree.Delete(child)

The TreeListMainWindow.Delete(item) method however removes the child
from its parent's list directly (hypertreelist.py line 2546):
	parent = item.GetParent()
	if parent:
		parent.GetChildren().remove(item)  # remove by value

This ends up modifying the list as we are iterating over it. The end
result is that every other child and its children do not get cleaned up
properly before being deleted. The biggest issue being that any windows
belonging to the children won't be destroyed, and instead orphaned in
the control.
This commit is contained in:
cbeytas
2018-11-29 22:52:49 -05:00
parent f6e7064b55
commit 72d5646f17

View File

@@ -1361,8 +1361,8 @@ class TreeListItem(GenericTreeItem):
:param `tree`: the main :class:`TreeListMainWindow` instance.
"""
for child in self._children:
# Iterate over copy of self._children as tree.Delete() will modify it.
for child in list(self._children):
child.DeleteChildren(tree)
if tree:
tree.Delete(child)