为什么SetCellEditor在self.m\u grid\u 3.ClearGrid()之后重新应用时会导致错误

2024-04-25 15:02:24 发布

您现在位置:Python中文网/ 问答频道 /正文

每次使用组合框选择新值时,下面的代码都会填充一个网格。 代码第一次运行时,它工作正常,并在第4列的每个单元格中创建一个带有下拉列表的填充网格。但是,当我选择第二个新值,函数执行self.m\u grid\u 3.ClearGrid()并重新填充时,我得到以下错误。你知道吗

  self.m_grid3.SetCellEditor(row, col, self.choice_editor)
  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\grid.py", line 2000, in SetCellEditor
  return _grid.Grid_SetCellEditor(*args, **kwargs)
  TypeError: in method 'Grid_SetCellEditor', expected argument 4 of type 'wxGridCellEditor *'

在col4中选择一个下拉列表会使python崩溃。你知道吗

你知道我怎么解决这个问题吗。你知道吗

这是有问题的代码。你知道吗

class Inspection(BulkUpdate):
    def __init__(self, parent):
        BulkUpdate.__init__(self, parent)
        list = EmployeeList()
        list_climbers = list.get_climbers()
        for name in list_climbers:
            self.edit_kit_comboBox.Append(str(name.employee))
        choices = ["Yes", "No", "Not Checked"]
        self.choice_editor = wx.grid.GridCellChoiceEditor(choices, True)


    def on_engineer_select( self, event ):
        self.m_grid3.ClearGrid()
        person = self.edit_kit_comboBox.GetValue()
        list = KitList()
        equipment = list.list_of_equipment(person, 1)
        rows = len(equipment)

        for row in range(0, rows):
            for col in range(0, 5):
                print "row = %s col = %s" % (row, col)
                if col == 4:
                    self.m_grid3.SetCellValue(row, col+2, str(equipment[row][col]))
                    self.m_grid3.SetCellValue(row, col, "Pass")
                    self.m_grid3.SetCellEditor(row, col, self.choice_editor)
                else:
                    self.m_grid3.SetCellValue(row, col, str(equipment[row][col]))

代码在第二次填充网格时停止在第二个循环上。 我已经想了好几天了。你知道吗


Tags: 代码inself网格coleditorlistgrid
2条回答

尝试将此添加到__init__

self.choice_editor.IncRef()
< P>我猜想,当调用^ {< CD2>}时,编辑器对象的C++部分被删除。给它额外的引用告诉网格你想要保持它。你知道吗

取加的答案

self.choice_editor.IncRef()

我将选项列表定义和

self.choice_editor.IncRef()

所以现在看起来像这样

def on_engineer_select( self, event ):
    self.m_grid3.ClearGrid()
    choices = ["Pass", "Fail", "Not Checked"]
    self.choice_editor = wx.grid.GridCellChoiceEditor(choices, False)
    person = self.edit_kit_comboBox.GetValue()
    list = KitList()
    equipment = list.list_of_equipment(person, 1)
    print "Length of equipment = %s" % len(equipment)
    rows = len(equipment)
    for row in range(0, rows):
        for col in range(0, 5):
            print "row = %s col = %s" % (row, col)
            if col == 4:
                self.choice_editor.IncRef()
                self.m_grid3.SetCellValue(row, col+2, str(equipment[row][col]))
                self.m_grid3.SetCellValue(row, col+1, str(date.today()))
                self.m_grid3.SetCellEditor(row, col, self.choice_editor)
                self.m_grid3.SetCellValue(row, col, "Pass")

            else:
                self.m_grid3.SetCellValue(row, col, str(equipment[row][col]))

现在代码可以按需要工作了。你知道吗

相关问题 更多 >