class SapGuiTree: class TreeType(enum.Enum): SIMPLE = 0 LIST = 1 COLUMN = 2 @classmethod def show(cls, tree, node, indention): print(indention, node, [ tree.GetItemText(node, column_name) for column_name in tree.GetColumnNames() ], { 'isFolder': tree.isFolder(node), 'IsFolderExpandable': tree.IsFolderExpandable(node), 'IsFolderExpanded': tree.IsFolderExpanded(node) } ) @classmethod def expand_all_nodes(cls, session): tree = session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[0]/shell/shellcont[1]/shell") def _expand_all(node, indention=''): if tree.IsFolderExpandable(node) and (not tree.IsFolderExpanded(node)): tree.ExpandNode(node) SapGuiTree.show(tree, node, indention=indention) all_sub_nodes = tree.GetSubNodesCol(node) for sub_node in all_sub_nodes or []: _expand_all(sub_node, indention= indention + ' ' * 2) node = tree.GetNodesCol() if node.Count > 0: _expand_all(node[0]) @classmethod def collapse_all_node(cls, session): tree = session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[0]/shell/shellcont[1]/shell") def _collapse_node(node, indention=''): all_sub_nodes = tree.GetSubNodesCol(node) reversed_all_sub_nodes = reversed([ sub_node for sub_node in all_sub_nodes or []]) for sub_node in reversed_all_sub_nodes: _collapse_node(sub_node, indention= indention + ' ' * 2) if tree.IsFolderExpandable(node) and tree.IsFolderExpanded(node): tree.CollapseNode(node) SapGuiTree.show(tree, node, indention= indention) node = tree.GetNodesCol() if node.Count > 0: _collapse_node(node[0]) def test02(session): SapGuiTree.expand_all_nodes(session) print('------------------------------------------') SapGuiTree.collapse_all_node(session) pass
https://blog.csdn.net/chenguangqi/article/details/125613054
标签:node,控件,遍历,sub,indention,tree,Tree,shellcont,nodes From: https://www.cnblogs.com/pythonClub/p/17655257.html