]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/GridSimple.py
Added first stab at GetBoundingRect for generic tree control
[wxWidgets.git] / wxPython / demo / GridSimple.py
CommitLineData
f6bcfd97
BP
1from wxPython.wx import *
2from wxPython.grid import *
3
4#---------------------------------------------------------------------------
5
6class SimpleGrid(wxGrid):
7 def __init__(self, parent, log):
8 wxGrid.__init__(self, parent, -1)
9 self.log = log
10
11 self.CreateGrid(25, 25)
12
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)
22
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))
29
30 # you can set cell attributes for the whole row (or column)
31 self.SetRowAttr(5, attr)
32
33
34 # test all the events
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)
39
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)
44
45 EVT_GRID_ROW_SIZE(self, self.OnRowSize)
46 EVT_GRID_COL_SIZE(self, self.OnColSize)
47
48 EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)
49 EVT_GRID_CELL_CHANGE(self, self.OnCellChange)
50 EVT_GRID_SELECT_CELL(self, self.OnSelectCell)
51
52 EVT_GRID_EDITOR_SHOWN(self, self.OnEditorShown)
53 EVT_GRID_EDITOR_HIDDEN(self, self.OnEditorHidden)
54
55
56 def OnCellLeftClick(self, evt):
57 self.log.write("OnCellLeftClick: (%d,%d) %s\n" %
58 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
59 evt.Skip()
60
61 def OnCellRightClick(self, evt):
62 self.log.write("OnCellRightClick: (%d,%d) %s\n" %
63 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
64 evt.Skip()
65
66 def OnCellLeftDClick(self, evt):
67 self.log.write("OnCellLeftDClick: (%d,%d) %s\n" %
68 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
69 evt.Skip()
70
71 def OnCellRightDClick(self, evt):
72 self.log.write("OnCellRightDClick: (%d,%d) %s\n" %
73 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
74 evt.Skip()
75
76 def OnLabelLeftClick(self, evt):
77 self.log.write("OnLabelLeftClick: (%d,%d) %s\n" %
78 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
79 evt.Skip()
80
81 def OnLabelRightClick(self, evt):
82 self.log.write("OnLabelRightClick: (%d,%d) %s\n" %
83 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
84 evt.Skip()
85
86 def OnLabelLeftDClick(self, evt):
87 self.log.write("OnLabelLeftDClick: (%d,%d) %s\n" %
88 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
89 evt.Skip()
90
91 def OnLabelRightDClick(self, evt):
92 self.log.write("OnLabelRightDClick: (%d,%d) %s\n" %
93 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
94 evt.Skip()
95
96
97 def OnRowSize(self, evt):
98 self.log.write("OnRowSize: row %d, %s\n" %
99 (evt.GetRowOrCol(), evt.GetPosition()))
100 evt.Skip()
101
102 def OnColSize(self, evt):
103 self.log.write("OnColSize: col %d, %s\n" %
104 (evt.GetRowOrCol(), evt.GetPosition()))
105 evt.Skip()
106
107 def OnRangeSelect(self, evt):
108 if evt.Selecting():
109 self.log.write("OnRangeSelect: top-left %s, bottom-right %s\n" %
110 (evt.GetTopLeftCoords(), evt.GetBottomRightCoords()))
111 evt.Skip()
112
113 def OnCellChange(self, evt):
114 self.log.write("OnCellChange: (%d,%d) %s\n" %
115 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
116 evt.Skip()
117
118 def OnSelectCell(self, evt):
119 self.log.write("OnSelectCell: (%d,%d) %s\n" %
120 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
121 evt.Skip()
122
123 def OnEditorShown(self, evt):
124 self.log.write("OnEditorShown: (%d,%d) %s\n" %
125 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
126 evt.Skip()
127
128 def OnEditorHidden(self, evt):
129 self.log.write("OnEditorHidden: (%d,%d) %s\n" %
130 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
131 evt.Skip()
132
133
134#---------------------------------------------------------------------------
135
136class 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)
140
141
142
143#---------------------------------------------------------------------------
144
145if __name__ == '__main__':
146 import sys
147 app = wxPySimpleApp()
148 frame = TestFrame(None, sys.stdout)
149 frame.Show(true)
150 app.MainLoop()
151
152
153#---------------------------------------------------------------------------