Events 使用带有ultimatelistctrl(wxpython)的选择小部件
我有一个包含三列的UltimateListCtrl。 第一个简单地显示索引,第二个有一个选择小部件来选择操作,第三个有一些StaticText小部件(参数),它们的数量和标识取决于第2列中的选择 当选择被改变时,我会收到一条关于它的命令事件,但我无法确定我在哪个单元格中。 我需要这个来更改第三列中的小部件 随附相关代码:Events 使用带有ultimatelistctrl(wxpython)的选择小部件,events,wxpython,choice,Events,Wxpython,Choice,我有一个包含三列的UltimateListCtrl。 第一个简单地显示索引,第二个有一个选择小部件来选择操作,第三个有一些StaticText小部件(参数),它们的数量和标识取决于第2列中的选择 当选择被改变时,我会收到一条关于它的命令事件,但我无法确定我在哪个单元格中。 我需要这个来更改第三列中的小部件 随附相关代码: def addAction(self, action): # set the Choice in the cell index = self.list.Inse
def addAction(self, action):
# set the Choice in the cell
index = self.list.InsertStringItem(sys.maxint, '')
self.list.SetStringItem(index, self.columns['#'], str(index))
self.list.SetStringItem(index, self.columns['Action'], '')
self.list.SetStringItem(index, self.columns['Parameters'], '')
item = self.list.GetItem(index, self.columns['Action'])
choice = wx.Choice(self.list, -1, name=action.name,
choices=[availableAction.name for availableAction in self.availableActions])
choice.Bind(wx.EVT_CHOICE, self.onActionChange)
item.SetWindow(choice, expand=True)
self.list.SetItem(item)
# set the third column's widgets
self.setItemParameters(index, action)
def onActionChange(self, event):
action = copy.deepcopy(self.availableActionsDict[event.GetString()])
# This doesn't work because this event doesn't have a GetIndex() function
self.setItemParameters(event.GetIndex(), action)
正如您在代码中看到的,我想找到changed Choice小部件的索引。
有人知道怎么做吗?
我试图通过查看列表中当前选定/关注的项目来获取项目索引,但它与正在更改的选项不一致。明白了!
我保持原样,只需使用SetClientData()为每个Choice小部件指定其在列表中的位置:
def addAction(self, action):
# set the Choice in the cell
index = self.list.InsertStringItem(sys.maxint, '')
self.list.SetStringItem(index, self.columns['#'], str(index))
self.list.SetStringItem(index, self.columns['Action'], '')
self.list.SetStringItem(index, self.columns['Parameters'], '')
item = self.list.GetItem(index, self.columns['Action'])
choice = wx.Choice(self.list, -1, name=action.name,
choices=[availableAction.name for availableAction in self.availableActions])
choice.SetClientData(0, index)
choice.Bind(wx.EVT_CHOICE, self.onActionChange)
item.SetWindow(choice, expand=True)
self.list.SetItem(item)
# set the third column's widgets
self.setItemParameters(index, action)
def onActionChange(self, event):
action = copy.deepcopy(self.availableActionsDict[event.GetString()])
self.setItemParameters(event.GetEventObject().GetClientData(0), action)
我确实需要在每次索引更改时更新它(比如从列表中间删除一个项目),但我可以接受
任何其他解决方案将不胜感激