]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GridEnterHandler.py
Added color setting tool to the RichTextCtrl sample
[wxWidgets.git] / wxPython / demo / GridEnterHandler.py
1
2 import wx
3 import wx.grid as gridlib
4
5 #---------------------------------------------------------------------------
6
7 class NewEnterHandlingGrid(gridlib.Grid):
8 def __init__(self, parent, log):
9 gridlib.Grid.__init__(self, parent, -1)
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
19 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
20
21
22 def OnKeyDown(self, evt):
23 if evt.KeyCode() != wx.WXK_RETURN:
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())
33
34 if not success:
35 newRow = self.GetGridCursorRow() + 1
36
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
48 class TestFrame(wx.Frame):
49 def __init__(self, parent, log):
50 wx.Frame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
51 grid = NewEnterHandlingGrid(self, log)
52
53
54
55 #---------------------------------------------------------------------------
56
57 if __name__ == '__main__':
58 import sys
59 app = wx.PySimpleApp()
60 frame = TestFrame(None, sys.stdout)
61 frame.Show(True)
62 app.MainLoop()
63
64
65 #---------------------------------------------------------------------------