0

我正在制作一个树 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。

4

2 回答 2

1
def _addNodeToSchema(self,event):
    pt = event.GetPoint()
    item, _ = self.treePanel.tree.HitTest(pt)
    if item:        
        print self.treePanel.tree.GetItemText(item) #this is the label of the node

显然,必须获得点位置,并查询树中可以在该位置找到的任何元素:) 不是很OO,但我会接受。

于 2013-04-03T20:07:04.477 回答
0

'''拖拽事件多选,显示被拖拽的项目

def On_Drag(self,event):
    select = (self.custom_tree.GetSelections())
    for i in range(len(select)):
        print(self.custom_tree.GetItemText(select[i]))'''
于 2020-02-19T10:41:52.017 回答