WxPython。 wx.propgrid。删除属性

时间:2018-12-07 06:58:01

标签: python python-3.x wxpython python-3.4

有一个属性网格,在网格中有一个类别“ uSignals”:

import wx.propgrid as wxpg

self.pg = wxpg.PropertyGrid(self, size=(500, 600), style=wxpg.PG_SPLITTER_AUTO_CENTER|wxpg.PG_TOOLBAR)

self.uSignals = uSignals = pg.Append(wxpg.PropertyCategory('User signals')) # user signals
self.uSignalsChildren = [] # list of children in the node uSignals

在此类别中,用户添加更多类别:

def AddSignal(self, event):
    newSignal = wxpg.PropertyCategory(self.GenerateSignalName())
    self.pg.AppendIn(self.uSignals, newSignal)
    self.uSignalsChildren.append(newSignal)

用户可以删除添加的属性。写了以下内容(如果有人只知道如何删除一个属性,我将不胜感激):

def OnDeleteSignal(self, event):
    p = self.pg.GetSelection()
    index = p.GetIndexInParent()
    self.uSignalsChildren.remove(p)
    self.uSignals.DeleteChildren() # remove all nested properties
    # add properties besides deleting (removed it from the list of uSignalsChildren)
    for signal in self.uSignalsChildren:
        self.pg.AppendIn(self.uSignals, signal)

问题:调用OnDeleteSignal时,尝试添加属性(还原不需要删除的属性)时,程序崩溃。 “ python.exe”程序崩溃了。

0 个答案:

没有答案