]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/GridEnterHandler.py
Send an extra size event after creation to work around an apparent bug
[wxWidgets.git] / wxPython / demo / GridEnterHandler.py
CommitLineData
8fa876ca
RD
1
2import wx
3import wx.grid as gridlib
f6bcfd97
BP
4
5#---------------------------------------------------------------------------
6
8fa876ca 7class NewEnterHandlingGrid(gridlib.Grid):
f6bcfd97 8 def __init__(self, parent, log):
8fa876ca 9 gridlib.Grid.__init__(self, parent, -1)
f6bcfd97
BP
10 self.log = log
11
12 self.CreateGrid(20, 6)
13
14 self.SetCellValue(0, 0, "Enter moves to the right")
15 self.SetCellValue(0, 5, "Enter wraps to next row")
16 self.SetColSize(0, 150)
17 self.SetColSize(5, 150)
18
8fa876ca 19 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
f6bcfd97
BP
20
21
22 def OnKeyDown(self, evt):
8fa876ca 23 if evt.KeyCode() != wx.WXK_RETURN:
f6bcfd97
BP
24 evt.Skip()
25 return
26
27 if evt.ControlDown(): # the edit control needs this key
28 evt.Skip()
29 return
30
31 self.DisableCellEditControl()
32 success = self.MoveCursorRight(evt.ShiftDown())
8fa876ca 33
f6bcfd97
BP
34 if not success:
35 newRow = self.GetGridCursorRow() + 1
8fa876ca 36
f6bcfd97
BP
37 if newRow < self.GetTable().GetNumberRows():
38 self.SetGridCursor(newRow, 0)
39 self.MakeCellVisible(newRow, 0)
40 else:
41 # this would be a good place to add a new row if your app
42 # needs to do that
43 pass
44
45
46#---------------------------------------------------------------------------
47
8fa876ca 48class TestFrame(wx.Frame):
f6bcfd97 49 def __init__(self, parent, log):
8fa876ca 50 wx.Frame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
f6bcfd97
BP
51 grid = NewEnterHandlingGrid(self, log)
52
53
54
55#---------------------------------------------------------------------------
56
57if __name__ == '__main__':
58 import sys
8fa876ca 59 app = wx.PySimpleApp()
f6bcfd97 60 frame = TestFrame(None, sys.stdout)
1e4a197e 61 frame.Show(True)
f6bcfd97
BP
62 app.MainLoop()
63
64
65#---------------------------------------------------------------------------