def delete_element(self, tree_id):
"""
Delete element with Treeview id *tree_id* from the tree, from the element
dictionary, and from the associated data structure. Recursively
deletes all children of *tree_id*.
The tree should be refreshed using :py:meth:`refresh_tree` after
each deletion. This is the responsibility of the caller.
"""
#if self.treeview.exists(tree_id):
if tree_id in self.element_dict:
# recursively delete children
if self.element_dict[tree_id].children is not None:
for child in self.element_dict[tree_id].children:
self.delete_element(child.treeview_id)
# check if deleting the root element
if self.root_element.treeview_id == tree_id:
# clear the root element
self.root_element = None
else:
try:
# remove the element from its parent's list of children
self.element_dict[tree_id].parent.remove_child_id(tree_id)
except AttributeError:
raise AttributeError("Non-root element lacks proper parent")
# delete the element from the dictionary
del self.element_dict[tree_id]
评论列表
文章目录