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