2011-11-02 25 views
3

谷歌搜索沒有任何結果...按Enter鍵時,網格的默認行爲是向下移動光標。但我必須在當前單元格中打開單元格編輯器。我可以輕鬆掛鉤關鍵事件,但我怎樣才能打開編輯器?在wx.grid中輸入關鍵行爲

回答

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