| 1 | from wxPython.wx import * |
| 2 | from wxPython.grid import * |
| 3 | |
| 4 | #--------------------------------------------------------------------------- |
| 5 | |
| 6 | class HugeTable(wxPyGridTableBase): |
| 7 | |
| 8 | """ |
| 9 | This is all it takes to make a custom data table to plug into a |
| 10 | wxGrid. There are many more methods that can be overridden, but |
| 11 | the ones shown below are the required ones. This table simply |
| 12 | provides strings containing the row and column values. |
| 13 | """ |
| 14 | |
| 15 | def __init__(self, log): |
| 16 | wxPyGridTableBase.__init__(self) |
| 17 | self.log = log |
| 18 | |
| 19 | self.odd=wxGridCellAttr() |
| 20 | self.odd.SetBackgroundColour("sky blue") |
| 21 | self.even=wxGridCellAttr() |
| 22 | self.even.SetBackgroundColour("sea green") |
| 23 | |
| 24 | def GetAttr(self, row, col, kind): |
| 25 | attr = [self.even, self.odd][row % 2] |
| 26 | attr.IncRef() |
| 27 | return attr |
| 28 | |
| 29 | def GetNumberRows(self): |
| 30 | return 10000 |
| 31 | |
| 32 | def GetNumberCols(self): |
| 33 | return 10000 |
| 34 | |
| 35 | def IsEmptyCell(self, row, col): |
| 36 | return False |
| 37 | |
| 38 | def GetValue(self, row, col): |
| 39 | return str( (row, col) ) |
| 40 | |
| 41 | def SetValue(self, row, col, value): |
| 42 | self.log.write('SetValue(%d, %d, "%s") ignored.\n' % (row, col, value)) |
| 43 | |
| 44 | |
| 45 | #--------------------------------------------------------------------------- |
| 46 | |
| 47 | |
| 48 | |
| 49 | class HugeTableGrid(wxGrid): |
| 50 | def __init__(self, parent, log): |
| 51 | wxGrid.__init__(self, parent, -1) |
| 52 | |
| 53 | table = HugeTable(log) |
| 54 | |
| 55 | # The second parameter means that the grid is to take ownership of the |
| 56 | # table and will destroy it when done. Otherwise you would need to keep |
| 57 | # a reference to it and call it's Destroy method later. |
| 58 | self.SetTable(table, True) |
| 59 | |
| 60 | EVT_GRID_CELL_RIGHT_CLICK(self, self.OnRightDown) #added |
| 61 | |
| 62 | def OnRightDown(self, event): #added |
| 63 | print "hello" |
| 64 | print self.GetSelectedRows() #added |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | #--------------------------------------------------------------------------- |
| 71 | |
| 72 | class TestFrame(wxFrame): |
| 73 | def __init__(self, parent, log): |
| 74 | wxFrame.__init__(self, parent, -1, "Huge (virtual) Table Demo", size=(640,480)) |
| 75 | grid = HugeTableGrid(self, log) |
| 76 | |
| 77 | grid.SetReadOnly(5,5, True) |
| 78 | |
| 79 | #--------------------------------------------------------------------------- |
| 80 | |
| 81 | if __name__ == '__main__': |
| 82 | import sys |
| 83 | app = wxPySimpleApp() |
| 84 | frame = TestFrame(None, sys.stdout) |
| 85 | frame.Show(True) |
| 86 | app.MainLoop() |
| 87 | |
| 88 | |
| 89 | #--------------------------------------------------------------------------- |