我正在制作一个树 ctrl,需要找出双击的来源。
代码:
def _initElementsOfTreePanel(self, panel):
tree = wx.TreeCtrl(panel, -1, wx.Point(0, 0), wx.DefaultSize, wx.NO_BORDER | wx.TR_DEFAULT_STYLE)
root = tree.AddRoot("Elements")
items = []
imglist = wx.ImageList(16, 16, True, 2)
imglist.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
imglist.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16)))
tree.AssignImageList(imglist)
# # Create the element Tree (the left hand side panel). Places in it all the found functions
def appendSubitems(item, func_list, tree):
print item
for func in func_list:
itemid = tree.AppendItem(item, func.__name__, 1)
print"GUIFrame._initElementsofTreePanel, func:",func.__name__,"id:",itemid
# print "TreeItemId:",
appendSubitems(tree.AppendItem(root, "Input functions", 0), self._elemdisco.input_functions, tree)
appendSubitems(tree.AppendItem(root, "Processing functions", 0), self._elemdisco.processing_functions, tree)
appendSubitems(tree.AppendItem(root, "Output functions", 0), self._elemdisco.output_functions, tree)
appendSubitems(tree.AppendItem(root, "Other functions", 0), self._elemdisco.other_functions, tree)
tree.ExpandAll()
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self._addNodeToSchema, self.treePanel.tree)
def _addNodeToSchema(self,event):
print event.GetItem()
现在输出显示,无论双击哪个节点,它都会识别出相同的项目触发了事件。它不对应于我知道我添加的任何项目的 ID,也没有根的 ID。
任何人都知道我如何获得对树中对象的引用?我基本上想得到它的名字,但是这个 API 不会让我:P
[编辑]:求解器,但我认为这是一个框架错误。无论双击实际发生在何处,事件都没有理由返回相同的 TreeItemID。