2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
import wx
|
|
|
|
import wx.grid as gridlib
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class NewEnterHandlingGrid(gridlib.Grid):
|
2000-07-15 15:51:35 -04:00
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
gridlib.Grid.__init__(self, parent, -1)
|
2000-07-15 15:51:35 -04:00
|
|
|
self.log = log
|
|
|
|
|
|
|
|
self.CreateGrid(20, 6)
|
|
|
|
|
|
|
|
self.SetCellValue(0, 0, "Enter moves to the right")
|
|
|
|
self.SetCellValue(0, 5, "Enter wraps to next row")
|
|
|
|
self.SetColSize(0, 150)
|
|
|
|
self.SetColSize(5, 150)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
def OnKeyDown(self, evt):
|
2006-09-08 16:09:27 -04:00
|
|
|
if evt.GetKeyCode() != wx.WXK_RETURN:
|
2000-07-15 15:51:35 -04:00
|
|
|
evt.Skip()
|
|
|
|
return
|
|
|
|
|
|
|
|
if evt.ControlDown(): # the edit control needs this key
|
|
|
|
evt.Skip()
|
|
|
|
return
|
|
|
|
|
|
|
|
self.DisableCellEditControl()
|
|
|
|
success = self.MoveCursorRight(evt.ShiftDown())
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
if not success:
|
|
|
|
newRow = self.GetGridCursorRow() + 1
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
if newRow < self.GetTable().GetNumberRows():
|
|
|
|
self.SetGridCursor(newRow, 0)
|
|
|
|
self.MakeCellVisible(newRow, 0)
|
|
|
|
else:
|
|
|
|
# this would be a good place to add a new row if your app
|
|
|
|
# needs to do that
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestFrame(wx.Frame):
|
2000-07-15 15:51:35 -04:00
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Frame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
|
2000-07-15 15:51:35 -04:00
|
|
|
grid = NewEnterHandlingGrid(self, log)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
2003-12-08 20:23:28 -05:00
|
|
|
app = wx.PySimpleApp()
|
2000-07-15 15:51:35 -04:00
|
|
|
frame = TestFrame(None, sys.stdout)
|
2003-03-25 01:35:27 -05:00
|
|
|
frame.Show(True)
|
2000-07-15 15:51:35 -04:00
|
|
|
app.MainLoop()
|
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|