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