def get_visible(config): """ Return a dict mapping node IDs (config names or menu node IDs) to True/False for their visibility """ result = {} menus = [] # when walking the menu the first time, only # record whether the config symbols are visible # and make a list of menu nodes (that are not symbols) def handle_node(node): sym = node.item try: visible = (sym.visibility != 0) result[node] = visible except AttributeError: menus.append(node) for n in config.node_iter(): handle_node(n) # now, figure out visibility for each menu. A menu is visible if any of its children are visible for m in reversed(menus): # reverse to start at leaf nodes result[m] = any(v for (n, v) in result.items() if n.parent == m) # return a dict mapping the node ID to its visibility. result = dict( (confgen.get_menu_node_id(n), v) for (n, v) in result.items()) return result
def get_visible(config): """ Return a dict mapping node IDs (config names or menu node IDs) to True/False for their visibility """ result = {} menus = [] # when walking the menu the first time, only # record whether the config symbols are visible # and make a list of menu nodes (that are not symbols) def handle_node(node): sym = node.item try: visible = (sym.visibility != 0) result[node] = visible except AttributeError: menus.append(node) config.walk_menu(handle_node) # now, figure out visibility for each menu. A menu is visible if any of its children are visible for m in reversed(menus): # reverse to start at leaf nodes result[m] = any(v for (n,v) in result.items() if n.parent == m) # return a dict mapping the node ID to its visibility. result = dict((confgen.get_menu_node_id(n),v) for (n,v) in result.items()) return result