【发布时间】:2011-12-20 01:47:45
【问题描述】:
谷歌搜索很多,但没有任何结果...按回车键时网格的默认行为是向下移动光标。但我必须让单元格编辑器在当前单元格中打开。可以很方便的hook按键事件,但是怎么打开编辑器呢?
【问题讨论】:
谷歌搜索很多,但没有任何结果...按回车键时网格的默认行为是向下移动光标。但我必须让单元格编辑器在当前单元格中打开。可以很方便的hook按键事件,但是怎么打开编辑器呢?
【问题讨论】:
import wx
import wx.grid
class MyGrid(wx.grid.Grid):
def __init__(self, *args, **kwargs):
wx.grid.Grid.__init__(self, *args, **kwargs)
self.CreateGrid(8, 3)
self.editor = wx.grid.GridCellChoiceEditor(["One", "Two", "Three"])
self.SetCellEditor(1, 1, self.editor)
self.SetCellValue(1, 0, "And here.")
self.SetCellValue(1, 1, "Try here.")
self.Bind(wx.EVT_KEY_DOWN, self.OnEnter)
def OnEnter(self, e):
if e.GetKeyCode() == wx.WXK_RETURN or e.GetKeyCode() == wx.WXK_NUMPAD_ENTER:
self.EnableCellEditControl()
else:
e.Skip()
class MainWindow(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.grid = MyGrid(self)
self.Show()
app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
【讨论】: