在wx.grid中输入关键行为

时间:2011-11-02 06:51:50

标签: grid wxpython enter

在没有任何结果的情况下进行大量搜索...按下回车键时网格的默认行为是向下移动光标。但我必须在当前单元格中打开单元格编辑器。我可以轻松地挂钩键事件,但是如何打开编辑器呢?

1 个答案:

答案 0 :(得分:1)

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()