wx.TreeCtrl 项目
我正在尝试使用 TreeCtrl 来表示文件夹结构。对于每个文件夹,我需要知道它的绝对路径和名称。我目前正在做这样的事情:
self.root = self.tree.AddRoot(project.name)
self.tree.SetPyData(self.root, None)
self.root.path = root
---- other code -----
childItem = self.tree.AppendItem(self.root, child.name)
childItem.path = self.root.path + "/" + child.name
但现在在一个事件中我需要获取路径字符串。到目前为止,我失败的方法是:
self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded, self.tree)
----- other code -------
def OnItemExpanded(self, evt):
selected = evt.GetItem()
print selected.path
现在失败了,因为: AttributeError: 'TreeItemId' object has no attribute 'path' 。根据我在这里的理解,该事件只为我提供了树中某个项目的 Id,而不是由“childItem = self.tree.AppendItem(self.root, child.name)”产生的实际项目?如果是这种情况,我怎样才能找到该项目?
问候, 博格丹
I'm trying to use a TreeCtrl to represent a folder structure. For each folder I need to know it's absolute path and name. I'm currently doing something like this:
self.root = self.tree.AddRoot(project.name)
self.tree.SetPyData(self.root, None)
self.root.path = root
---- other code -----
childItem = self.tree.AppendItem(self.root, child.name)
childItem.path = self.root.path + "/" + child.name
But now on an event I will need to get the path string. So far my approach that fails is:
self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded, self.tree)
----- other code -------
def OnItemExpanded(self, evt):
selected = evt.GetItem()
print selected.path
Now this fails because: AttributeError: 'TreeItemId' object has no attribute 'path' . From what I understand here the event only gives me a Id to a Item from the tree and not the actual Item that resulted from the "childItem = self.tree.AppendItem(self.root, child.name)" ? If that is the case how can I get to that item ?
regards,
Bogdan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.path 属性是什么?这是您正在创建的东西还是 TreeItemId 对象的实际成员(这是从“AppendItem”方法返回的对象)?我没有看到任何关于它的文档。
如果要在子项中存储任意数据,请使用 SetPyData/GetPyData 方法。
然后在你的处理程序中:
What is the .path property? Is this something you are creating or an actual member of the TreeItemId object (this is the object returned from the "AppendItem" method)? I do not see any docs on it.
If you want to store arbitrary data in the child items use SetPyData/GetPyData methods.
Then in your handler: