]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/GridEnterHandler.py
reSWIGged
[wxWidgets.git] / wxPython / demo / GridEnterHandler.py
... / ...
CommitLineData
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
8
9#---------------------------------------------------------------------------
10
11class NewEnterHandlingGrid(gridlib.Grid):
12 def __init__(self, parent, log):
13 gridlib.Grid.__init__(self, parent, -1)
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
23 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
24
25
26 def OnKeyDown(self, evt):
27 if evt.KeyCode() != wx.WXK_RETURN:
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())
37
38 if not success:
39 newRow = self.GetGridCursorRow() + 1
40
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
52class TestFrame(wx.Frame):
53 def __init__(self, parent, log):
54 wx.Frame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
55 grid = NewEnterHandlingGrid(self, log)
56
57
58
59#---------------------------------------------------------------------------
60
61if __name__ == '__main__':
62 import sys
63 app = wx.PySimpleApp()
64 frame = TestFrame(None, sys.stdout)
65 frame.Show(True)
66 app.MainLoop()
67
68
69#---------------------------------------------------------------------------