]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GridSimple.py
1 from wxPython
.wx
import *
2 from wxPython
.grid
import *
4 #---------------------------------------------------------------------------
6 class SimpleGrid(wxGrid
):
7 def __init__(self
, parent
, log
):
8 wxGrid
.__init
__(self
, parent
, -1)
11 self
.CreateGrid(25, 25)
13 # simple cell formatting
14 self
.SetColSize(3, 200)
15 self
.SetRowSize(4, 45)
16 self
.SetCellValue(0, 0, "First cell")
17 self
.SetCellValue(1, 1, "Another cell")
18 self
.SetCellValue(2, 2, "Yet another cell")
19 self
.SetCellFont(0, 0, wxFont(12, wxROMAN
, wxITALIC
, wxNORMAL
))
20 self
.SetCellTextColour(1, 1, wxRED
)
21 self
.SetCellBackgroundColour(2, 2, wxCYAN
)
23 # attribute objects let you keep a set of formatting values
24 # in one spot, and reuse them if needed
25 attr
= wxGridCellAttr()
26 attr
.SetTextColour(wxBLACK
)
27 attr
.SetBackgroundColour(wxRED
)
28 attr
.SetFont(wxFont(10, wxSWISS
, wxNORMAL
, wxBOLD
))
30 # you can set cell attributes for the whole row (or column)
31 self
.SetRowAttr(5, attr
)
35 EVT_GRID_CELL_LEFT_CLICK(self
, self
.OnCellLeftClick
)
36 EVT_GRID_CELL_RIGHT_CLICK(self
, self
.OnCellRightClick
)
37 EVT_GRID_CELL_LEFT_DCLICK(self
, self
.OnCellLeftDClick
)
38 EVT_GRID_CELL_RIGHT_DCLICK(self
, self
.OnCellRightDClick
)
40 EVT_GRID_LABEL_LEFT_CLICK(self
, self
.OnLabelLeftClick
)
41 EVT_GRID_LABEL_RIGHT_CLICK(self
, self
.OnLabelRightClick
)
42 EVT_GRID_LABEL_LEFT_DCLICK(self
, self
.OnLabelLeftDClick
)
43 EVT_GRID_LABEL_RIGHT_DCLICK(self
, self
.OnLabelRightDClick
)
45 EVT_GRID_ROW_SIZE(self
, self
.OnRowSize
)
46 EVT_GRID_COL_SIZE(self
, self
.OnColSize
)
48 EVT_GRID_RANGE_SELECT(self
, self
.OnRangeSelect
)
49 EVT_GRID_CELL_CHANGE(self
, self
.OnCellChange
)
50 EVT_GRID_SELECT_CELL(self
, self
.OnSelectCell
)
52 EVT_GRID_EDITOR_SHOWN(self
, self
.OnEditorShown
)
53 EVT_GRID_EDITOR_HIDDEN(self
, self
.OnEditorHidden
)
56 def OnCellLeftClick(self
, evt
):
57 self
.log
.write("OnCellLeftClick: (%d,%d) %s\n" %
58 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
61 def OnCellRightClick(self
, evt
):
62 self
.log
.write("OnCellRightClick: (%d,%d) %s\n" %
63 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
66 def OnCellLeftDClick(self
, evt
):
67 self
.log
.write("OnCellLeftDClick: (%d,%d) %s\n" %
68 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
71 def OnCellRightDClick(self
, evt
):
72 self
.log
.write("OnCellRightDClick: (%d,%d) %s\n" %
73 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
76 def OnLabelLeftClick(self
, evt
):
77 self
.log
.write("OnLabelLeftClick: (%d,%d) %s\n" %
78 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
81 def OnLabelRightClick(self
, evt
):
82 self
.log
.write("OnLabelRightClick: (%d,%d) %s\n" %
83 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
86 def OnLabelLeftDClick(self
, evt
):
87 self
.log
.write("OnLabelLeftDClick: (%d,%d) %s\n" %
88 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
91 def OnLabelRightDClick(self
, evt
):
92 self
.log
.write("OnLabelRightDClick: (%d,%d) %s\n" %
93 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
97 def OnRowSize(self
, evt
):
98 self
.log
.write("OnRowSize: row %d, %s\n" %
99 (evt
.GetRowOrCol(), evt
.GetPosition()))
102 def OnColSize(self
, evt
):
103 self
.log
.write("OnColSize: col %d, %s\n" %
104 (evt
.GetRowOrCol(), evt
.GetPosition()))
107 def OnRangeSelect(self
, evt
):
109 self
.log
.write("OnRangeSelect: top-left %s, bottom-right %s\n" %
110 (evt
.GetTopLeftCoords(), evt
.GetBottomRightCoords()))
113 def OnCellChange(self
, evt
):
114 self
.log
.write("OnCellChange: (%d,%d) %s\n" %
115 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
118 def OnSelectCell(self
, evt
):
119 self
.log
.write("OnSelectCell: (%d,%d) %s\n" %
120 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
123 def OnEditorShown(self
, evt
):
124 self
.log
.write("OnEditorShown: (%d,%d) %s\n" %
125 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
128 def OnEditorHidden(self
, evt
):
129 self
.log
.write("OnEditorHidden: (%d,%d) %s\n" %
130 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
134 #---------------------------------------------------------------------------
136 class TestFrame(wxFrame
):
137 def __init__(self
, parent
, log
):
138 wxFrame
.__init
__(self
, parent
, -1, "Simple Grid Demo", size
=(640,480))
139 grid
= SimpleGrid(self
, log
)
143 #---------------------------------------------------------------------------
145 if __name__
== '__main__':
147 app
= wxPySimpleApp()
148 frame
= TestFrame(None, sys
.stdout
)
153 #---------------------------------------------------------------------------