如何将额外数据添加到下面wx.TreeCtrl
命名的附加树项中fileTree
。我将文本文件中的数据读入数组以构建树。树中的附加项目是图像的文件名,但我想知道如何将完整的文件路径添加到每个项目。当我在一个项目上加倍时,必须显示完整的文件路径,而不仅仅是它的文件名。
def __init__(self, *args, **kwds):
self.fileTree = wx.TreeCtrl(self, size=(200, 100))
self.root = self.fileTree.AddRoot('Images')
self.allImages = self.fileTree.AppendItem(self.root, 'All')
imgLst=self.generateList(imagelist)# Reads a text file with filepaths into list
for item in imgLst:
tmp=item
tmp = tmp[tmp.rfind("\\")+1:tmp.rfind(".")]
self.fileTree.AppendItem(self.allImages, tmp)
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.onTreeDClick, self.fileTree)
def onTreeDClick(self,event):
print 'Double clicked on', self.fileTree.GetItemText(event.GetItem())
def generateList(self, fname):
f = open(fname, "rb")
a=[]
for line in f:
a.append(line.strip())
return a