1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
#!/usr/bin/python
"""
__version__ = "$Revision: 1.12 $"
__date__ = "$Date: 2004/09/09 21:08:46 $"
"""
from PythonCard import dialog, model
import wx
from wx import grid
import sys
class Minimal(model.Background):
def on_initialize(self, event):
self.log = sys.stdout
self.moveTo = None
## wx.EVT_IDLE(self, self.OnIdle)
mygrid = self.components.mygrid
mygrid.CreateGrid(25, 25) #, wxGrid.wxGridSelectRows)
##mygrid.EnableEditing(False)
# simple cell formatting
mygrid.SetColSize(3, 200)
mygrid.SetRowSize(4, 45)
mygrid.SetCellValue(0, 0, "First cell")
mygrid.SetCellValue(1, 1, "Another cell")
mygrid.SetCellValue(2, 2, "Yet another cell")
mygrid.SetCellValue(3, 3, "This cell is read-only")
mygrid.SetCellFont(0, 0, wx.Font(12, wx.ROMAN, wx.ITALIC, wx.NORMAL))
mygrid.SetCellTextColour(1, 1, wx.RED)
mygrid.SetCellBackgroundColour(2, 2, wx.CYAN)
mygrid.SetReadOnly(3, 3, True)
mygrid.SetCellEditor(5, 0, grid.GridCellNumberEditor(1,1000))
mygrid.SetCellValue(5, 0, "123")
mygrid.SetCellEditor(6, 0, grid.GridCellFloatEditor())
mygrid.SetCellValue(6, 0, "123.34")
mygrid.SetCellEditor(7, 0, grid.GridCellNumberEditor())
mygrid.SetCellValue(6, 3, "You can veto editing this cell")
# attribute objects let you keep a set of formatting values
# in one spot, and reuse them if needed
attr = grid.GridCellAttr()
attr.SetTextColour(wx.BLACK)
attr.SetBackgroundColour(wx.RED)
attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
# you can set cell attributes for the whole row (or column)
mygrid.SetRowAttr(5, attr)
mygrid.SetColLabelValue(0, "Custom")
mygrid.SetColLabelValue(1, "column")
mygrid.SetColLabelValue(2, "labels")
mygrid.SetColLabelAlignment(wx.ALIGN_LEFT, wx.ALIGN_BOTTOM)
#mygrid.SetDefaultCellOverflow(False)
#r = wx.GridCellAutoWrapStringRenderer()
#mygrid.SetCellRenderer(9, 1, r)
# overflow cells
mygrid.SetCellValue( 9, 1, "This default cell will overflow into neighboring cells, but not if you turn overflow off.");
mygrid.SetCellSize(11, 1, 3, 3);
mygrid.SetCellAlignment(11, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE);
mygrid.SetCellValue(11, 1, "This cell is set to span 3 rows and 3 columns");
sizer1 = wx.BoxSizer(wx.VERTICAL)
sizer1.Add(self.components.mygrid, 1, wx.EXPAND)
sizer1.Fit(self)
sizer1.SetSizeHints(self)
self.panel.SetSizer(sizer1)
self.panel.SetAutoLayout(1)
self.panel.Layout()
## def OnCellLeftClick(self, event):
def on_mygrid_mouseClick(self, event):
self.log.write("mouseClick: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_mouseContextClick(self, event):
self.log.write("mouseContextClick: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_mouseDoubleClick(self, event):
self.log.write("mouseDoubleClick: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_mouseContextDoubleClick(self, event):
self.log.write("mouseContextDoubleClick: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_labelClick(self, event):
self.log.write("labelClick: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_labelContextClick(self, event):
self.log.write("labelContextClick: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_labelDoubleClick(self, event):
self.log.write("labelDoubleClick: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_labelContextDoubleClick(self, event):
self.log.write("labelContextDoubleClick: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_rowSize(self, event):
self.log.write("rowSize: row %d, %s\n" %
(event.GetRowOrCol(), event.position))
event.skip()
def on_mygrid_columnSize(self, event):
self.log.write("columnSize: col %d, %s\n" %
(event.GetRowOrCol(), event.position))
event.skip()
def on_mygrid_rangeSelect(self, event):
if event.Selecting():
self.log.write("rangeSelect: top-left %s, bottom-right %s\n" %
(event.GetTopLeftCoords(), event.GetBottomRightCoords()))
event.skip()
def on_mygrid_cellChange(self, event):
self.log.write("cellChange: (%d,%d) %s\n" %
(event.row, event.column, event.position))
# Show how to stay in a cell that has bad data. We can't just
# call SetGridCursor here since we are nested inside one so it
# won't have any effect. Instead, set coordinants to move to in
# idle time.
value = self.components.mygrid.GetCellValue(event.row, event.column)
if value == 'no good':
self.moveTo = event.row, event.column
def on_idle(self, event):
if self.moveTo != None:
self.components.mygrid.SetGridCursor(self.moveTo[0], self.moveTo[1])
self.moveTo = None
event.skip()
def on_mygrid_selectCell(self, event):
self.log.write("selectCell: (%d,%d) %s\n" %
(event.row, event.column, event.position))
# Another way to stay in a cell that has a bad value...
mygrid = self.components.mygrid
row = mygrid.GetGridCursorRow()
col = mygrid.GetGridCursorCol()
if mygrid.IsCellEditControlEnabled():
mygrid.HideCellEditControl()
mygrid.DisableCellEditControl()
value = mygrid.GetCellValue(row, col)
if value == 'no good 2':
return # cancels the cell selection
event.skip()
def on_mygrid_editorShown(self, event):
if event.row == 6 and event.column == 3:
result = dialog.messageDialog(self, "Are you sure you wish to edit this cell?",
"Checking", wx.YES_NO)
if not result.accepted:
event.Veto()
return
self.log.write("editorShown: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_editorHidden(self, event):
if event.row == 6 and event.column == 3:
result = dialog.messageDialog(self, "Are you sure you wish to finish editing this cell?",
"Checking", wx.YES_NO)
if not result.accepted:
event.Veto()
return
self.log.write("on_mygrid_editorHidden: (%d,%d) %s\n" %
(event.row, event.column, event.position))
event.skip()
def on_mygrid_editorCreated(self, event):
self.log.write("on_mygrid_editorCreated: (%d, %d) %s\n" %
(event.row, event.column, event.GetControl()))
if __name__ == '__main__':
app = model.Application(Minimal)
app.MainLoop()
|