'Set sorting key or func for use with __iter__.
This affects the whole tree from this node.'

def set_sorting(self, key, reverse):

    if ((self.sort_key != key) or (self.sort_reverse != reverse)):
        nodes_to_flag_unsorted = collections.deque([self])
        while nodes_to_flag_unsorted:
            current_node = nodes_to_flag_unsorted.pop()
            current_node.children_sorted = False
            current_node.sort_key = key
            current_node.reverse_sorting = reverse
            nodes_to_flag_unsorted.extend(current_node.children)
