社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

用python中的子节点迭代gtk3 treestore

Brad • 7 年前 • 1976 次点击  

我正试图搜索一个GTK 3 treestore的字符串。treestore有4列,用于具有可调用节点的treeview小部件。IM使用此函数创建节点:

def AddItem(self,ParentIter,txt,datapath='',projName=Project):         
    self.store = self.builder.get_object('theTreeStore')
    NodeId = secrets.token_hex(8) 

    if ParentIter == None:
        ParentNodeId = ''
    else:
        ParentNodeId = self.store.get_value(ParentIter, 2) 
    treeEntry = ['%s' %ParentNodeId,'%s' %txt,'%s' %NodeId,'%s' %datapath] 
    node = self.store.append(ParentIter, treeEntry) <<<<<<<<<<<<<
    self.view = self.builder.get_object('Tree')
    self.view.set_model(self.store)

    # table nodes(tParentNodeID ,tNodeTxt ,tNodeID ,tDataPath );



    sql = "INSERT INTO %s (tParentNodeID ,tNodeTxt ,tNodeID ,tDataPath ) VALUES ('%s','%s','%s','%s')" %(projName,ParentNodeId,txt,NodeId,datapath)
    self.cursor.execute(sql)
    self.mariadb_connection.commit()
    for x in self.cursor:
        print(x)
    return(node)

如您所见,树中的数据嵌套在其父级中。

现在我需要在treestore中搜索包含某个nodeid字符串的行。我一遍又一遍地阅读gtk文档,但我不知道该怎么办。我想我需要使用以下方法:

存储。获取iter() 存储.iter_children()

但是idk所有我尝试的都只返回根节点,没有子节点。

我基本上想要一个搜索函数,它将递归地搜索每个节点及其子节点,以及它们的子节点以查找字符串。像这样的:

def GetRowbyNodeID(nodeid):
     for row in treestore:
       if row[1]==nodeid:
          return(row) 
       for children in row:        
         if children[1] == nodeid    
             return(children)

代码在多个文件中,如果需要,我可以发布任何相关的函数。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/41035
文章 [ 2 ]  |  最新文章 7 年前