【发布时间】:2016-08-15 13:31:23
【问题描述】:
我正在寻找一种方法让用户在 wxPython 网格中批量编辑数据,有点像在 Excel 中选择一个范围、键入数据并按 shift-Enter。这是我的网格的简化版本:
class MyGrid(gridlib.Grid):
def __init__(self, panel):
gridlib.Grid.__init__(self, panel)
self.Bind(gridlib.EVT_GRID_CELL_CHANGE, self.onEditCell)
self.Bind(gridlib.EVT_GRID_RANGE_SELECT, self.onSelection)
def onSelection(self, event):
if self.GetSelectionBlockTopLeft() == []:
self.selected_row_number = 0
self.selected_col_number = 0
else:
self.selected_row_number = self.GetSelectionBlockBottomRight()[0][0] - self.GetSelectionBlockTopLeft()[0][0] + 1
self.selected_col_number = self.GetSelectionBlockBottomRight()[0][1] - self.GetSelectionBlockTopLeft()[0][1] + 1
print self.selected_row_number, self.selected_col_number
def onEditCell(self,event):
print self.selected_row_number, self.selected_col_number
问题似乎是 onEditCell 事件覆盖了之前的选择。所以我可以选择例如网格中的四乘四块,onSelection 将打印 4 4。但是当我开始键入并按 Enter 时,onEditCell 将打印 0,0,就好像只选择了我正在编辑的单元格一样。如何保持选择了多少个单元格的“记忆”?谢谢,
【问题讨论】:
标签: user-interface datagrid wxpython