我正在使用wxpython 2.7.8的wx.DataViewCtrl来列出我的数据。我可以通过单击菜单第一次使用wx.DataViewCtrl:GetSelections()从列表中选择项目。通过单击关闭按钮关闭该框后,再次尝试通过单击菜单打开此框。但我不能使用wx.DataViewCtrl:GetSelections()来选择要删除/修改的项目。 wx.DataViewCtrl:GetSelections()返回空列表。但仍然是wx.DataViewCtrl框显示数据列表。
请帮帮我。最近两天我对这个问题感到震惊。谢谢。
class MainFrame(wx.Dialog):
def __init__(self, parent, title, data):
self.data = data
wx.Dialog.__init__(self, parent, title=title, size=(800, 400))
self.panel = wx.Panel(self)
self.model = UpdateModel(self.data)
def createEntityTable(self, editor_ctrl):
self.__editor_ctrl = editor_ctrl.getEditor()
self.dvc = dv.DataViewCtrl(self.panel,
style=wx.BORDER_THEME
| dv.DV_ROW_LINES # nice alternating bg colors
#| dv.DV_HORIZ_RULES
| dv.DV_VERT_RULES
| dv.DV_MULTIPLE, size = (600, 400)
)
self.dvc.AssociateModel(self.model)
self.dvc.AppendTextColumn("Name", 0, width=170, mode=dv.DATAVIEW_CELL_EDITABLE)
self.dvc.AppendTextColumn("DTD", 1, width=80, mode=dv.DATAVIEW_CELL_EDITABLE)
self.dvc.AppendTextColumn("File name", 2, width=80, mode=dv.DATAVIEW_CELL_EDITABLE)
self.dvc.AppendTextColumn("Public Id", 3, width=80, mode=dv.DATAVIEW_CELL_EDITABLE)
self.dvc.AppendTextColumn("Notation", 4, width=80, mode=dv.DATAVIEW_CELL_EDITABLE)
for c in self.dvc.Columns:
c.Sortable = True
c.Reorderable = True
self.new = wx.Button(self.panel, -1, "New")
self.Bind(wx.EVT_BUTTON, self.OnAddRow, self.new)
self.modify = wx.Button(self.panel, -1, "Modify")
self.Bind(wx.EVT_BUTTON, self.onModifyRow, self.modify)
self.delete = wx.Button(self.panel, -1, "Delete")
self.Bind(wx.EVT_BUTTON, self.OnDeleteRows, self.delete)
self.close = wx.Button(self.panel, -1, "Close")
self.Bind(wx.EVT_BUTTON, self.OnClosePanel, self.close)
dvcSizer = wx.BoxSizer(wx.HORIZONTAL)
dvcSizer.Add(self.dvc, 1, wx.EXPAND)
btnbox = wx.BoxSizer(wx.VERTICAL)
btnbox.Add(self.new, 0, wx.LEFT|wx.RIGHT, 5)
btnbox.Add(self.modify, 0, wx.LEFT|wx.RIGHT, 5)
btnbox.Add(self.delete, 0, wx.LEFT|wx.RIGHT, 5)
btnbox.Add(self.close, 0, wx.LEFT|wx.RIGHT, 5)
dvcSizer.Add(btnbox, 0, wx.TOP|wx.BOTTOM, 5)
self.panel.SetSizer(dvcSizer)
self.ShowModal()
def OnDeleteRows(self, evt):
items = self.dvc.GetSelections()
rows = [self.model.GetRow(item) for item in items]
self.model.DeleteRows(rows)
答案 0 :(得分:0)
您似乎使用了wxPython演示中的DVC_IndexListModel。您是否实施了从DeleteRows(self, rows)
派生的TestModel
中所示的方法PyDataViewIndexListModel
?这将是您的UpdateModel
。