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 HugeTable(gridlib.PyGridTableBase):
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
def __init__(self, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
gridlib.PyGridTableBase.__init__(self)
|
2000-07-15 15:51:35 -04:00
|
|
|
self.log = log
|
|
|
|
|
2003-12-11 14:55:48 -05:00
|
|
|
self.odd=gridlib.GridCellAttr()
|
2003-11-19 01:41:12 -05:00
|
|
|
self.odd.SetBackgroundColour("sky blue")
|
2003-12-11 14:55:48 -05:00
|
|
|
self.even=gridlib.GridCellAttr()
|
2003-11-19 01:41:12 -05:00
|
|
|
self.even.SetBackgroundColour("sea green")
|
|
|
|
|
2003-11-21 02:36:53 -05:00
|
|
|
def GetAttr(self, row, col, kind):
|
2003-11-19 01:41:12 -05:00
|
|
|
attr = [self.even, self.odd][row % 2]
|
|
|
|
attr.IncRef()
|
|
|
|
return attr
|
|
|
|
|
2005-04-04 18:52:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
# This is all it takes to make a custom data table to plug into a
|
|
|
|
# wxGrid. There are many more methods that can be overridden, but
|
|
|
|
# the ones shown below are the required ones. This table simply
|
|
|
|
# provides strings containing the row and column values.
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
def GetNumberRows(self):
|
|
|
|
return 10000
|
|
|
|
|
|
|
|
def GetNumberCols(self):
|
|
|
|
return 10000
|
|
|
|
|
|
|
|
def IsEmptyCell(self, row, col):
|
2003-03-25 01:35:27 -05:00
|
|
|
return False
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
def GetValue(self, row, col):
|
|
|
|
return str( (row, col) )
|
|
|
|
|
|
|
|
def SetValue(self, row, col, value):
|
|
|
|
self.log.write('SetValue(%d, %d, "%s") ignored.\n' % (row, col, value))
|
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class HugeTableGrid(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
|
|
|
|
|
|
|
table = HugeTable(log)
|
|
|
|
|
|
|
|
# The second parameter means that the grid is to take ownership of the
|
|
|
|
# table and will destroy it when done. Otherwise you would need to keep
|
|
|
|
# a reference to it and call it's Destroy method later.
|
2003-03-25 01:35:27 -05:00
|
|
|
self.SetTable(table, True)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(gridlib.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightDown)
|
2003-03-25 01:35:27 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
def OnRightDown(self, event):
|
2003-03-25 01:35:27 -05:00
|
|
|
print "hello"
|
2003-12-08 20:23:28 -05:00
|
|
|
print self.GetSelectedRows()
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
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, "Huge (virtual) Table Demo", size=(640,480))
|
2000-07-15 15:51:35 -04:00
|
|
|
grid = HugeTableGrid(self, log)
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
grid.SetReadOnly(5,5, True)
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|