首页 > 其他分享 >遍历Tree控件中的节点

遍历Tree控件中的节点

时间:2023-08-24 21:56:20浏览次数:43  
标签:node 控件 遍历 sub indention tree Tree shellcont nodes

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

相关文章

  • windows 桌面GUI自动化- 14.pywinauto 找到多个相同控件使用found_index
    前言pywinauto在查找到多个相同控件时操作会报错,可以使用found_index选择其中的一个查找到多个查找control_type="MenuBar"的所有控件frompywinautoimportApplicationapp=Application('uia').start("notepad.exe")win=app.window(title_re="无标题-记事本")#......
  • LinkButton控件,点击按钮带参数到后台
    LinkButton实现带参数到后台方法详解一:LinkButton控件常用的属性Text:用于设置控件显示的文本内容。ToolTip:鼠标悬停在控件上时显示的提示信息。CommandArgument:用于向服务器端的事件处理程序传递额外的参数。CommandName:用于标识LinkButton的命令名称,用于区分不同的......
  • windows 桌面GUI自动化- 12.pywinauto 组合框控件ComboBox操作
    前言pywinauto组合框控件ComboBox操作场景记事本-另存为-编码选择,下图这种就是组合框控件ComboBoxselect选择官网给的教程是通过select选择选项示例frompywinautoimportApplicationapp=Application('uia').start("notepad.exe")win=app.window(title_re="......
  • windows 桌面GUI自动化- 11.pywinauto 窗口和控件截图capture_as_image()
    前言pywinauto对窗口和控件截图capture_as_image()窗口截图对连接的窗口截图frompywinautoimportApplicationapp=Application('uia').start("notepad.exe")win=app.window(title_re="无标题-记事本")#对窗口截图win.capture_as_image().save('not.pn......
  • element 树形控件,父节点不显示复选框,子节点显示复选框,需增加特定样式
      代码复用参考: /deep/.stafftree.el-tree.el-tree-node.is-leaf+.el-checkbox.el-checkbox__inner{display:inline-block;}/deep/.stafftree.el-tree.el-tree-node.el-checkbox.el-checkbox__inner{display:none;}::v-deep.el-tr......
  • 遍历
     计算机科学中的树在计算机科学中,树(英语:tree)是一种抽象数据类型(ADT)或是实现这种抽象数据类型的数据结构,用来模拟具有树状结构性质的数据集合。它是由n(n>0)个有限节点组成一个具有层次关系的集合。把它叫做“树”是因为它看起来像一棵倒挂的树,也就是说它是根朝上,而叶朝下的。它......
  • 「题解」Codeforces 825G Tree Queries
    点权转边权,把边权设为两个端点的\(\min\),然后发现询问\(x\)的答案,就是询问\(x\)与所有黑点的虚树,边权的\(\min\)是多少。假设要判定答案是否\(\geqk\),那么就是询问\(x\)只经过\(\geqk\)是否能到达所有黑点,于是想到建立Kruskal重构树,那么\(x\)与所有黑点的LCA......
  • windows 桌面GUI自动化- 8.pywinauto 获取控件属性和文本内容
    前言控件操作完成后,一般需要获取控件的属性对结果断言,判断是否符合预期。查看控件类型wrapper_object()方法可以查看控件类型frompywinautoimportApplicationapp=Application('uia').start("notepad.exe")win=app.window(title_re="无标题-记事本")m=win.ch......
  • 常见控件说明
    阅读目录1.文本框 常见的控件: 1.文本输入框(TextBox) 2.按钮控件(Button) 3.下拉选框(DropList) 4.日期/时间控件(Date/TimePicker) 5.(图片、文件)上传控件(Upload)  6.树形控件(TreeView) 7.列表框(ListBox) 8.多格式文本框(RichTextBox)  9.Tab控件10.其他控......
  • DevExpress WPF HeatMap组件,一个高度可自定义的热图控件!
    像所有DevExpress UI组件一样,HeatMap组件针对速度进行了优化,包括数十个自定义设置和高级API,因此用户可以快速将美观的数据可视化集成到下一个WPF应用程序中。P.S:DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创......