]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GridSimple.py
f816e7a3f4c0b5abee65f12e685bc1ee2985fed5
[wxWidgets.git] / wxPython / demo / GridSimple.py
1 from wxPython.wx import *
2 from wxPython.grid import *
3
4 #---------------------------------------------------------------------------
5
6 class 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 self.SetColLabelValue(0, "Custom")
34 self.SetColLabelValue(1, "column")
35 self.SetColLabelValue(2, "labels")
36
37 # test all the events
38 EVT_GRID_CELL_LEFT_CLICK(self, self.OnCellLeftClick)
39 EVT_GRID_CELL_RIGHT_CLICK(self, self.OnCellRightClick)
40 EVT_GRID_CELL_LEFT_DCLICK(self, self.OnCellLeftDClick)
41 EVT_GRID_CELL_RIGHT_DCLICK(self, self.OnCellRightDClick)
42
43 EVT_GRID_LABEL_LEFT_CLICK(self, self.OnLabelLeftClick)
44 EVT_GRID_LABEL_RIGHT_CLICK(self, self.OnLabelRightClick)
45 EVT_GRID_LABEL_LEFT_DCLICK(self, self.OnLabelLeftDClick)
46 EVT_GRID_LABEL_RIGHT_DCLICK(self, self.OnLabelRightDClick)
47
48 EVT_GRID_ROW_SIZE(self, self.OnRowSize)
49 EVT_GRID_COL_SIZE(self, self.OnColSize)
50
51 EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)
52 EVT_GRID_CELL_CHANGE(self, self.OnCellChange)
53 EVT_GRID_SELECT_CELL(self, self.OnSelectCell)
54
55 EVT_GRID_EDITOR_SHOWN(self, self.OnEditorShown)
56 EVT_GRID_EDITOR_HIDDEN(self, self.OnEditorHidden)
57
58
59 def OnCellLeftClick(self, evt):
60 self.log.write("OnCellLeftClick: (%d,%d) %s\n" %
61 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
62 evt.Skip()
63
64 def OnCellRightClick(self, evt):
65 self.log.write("OnCellRightClick: (%d,%d) %s\n" %
66 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
67 evt.Skip()
68
69 def OnCellLeftDClick(self, evt):
70 self.log.write("OnCellLeftDClick: (%d,%d) %s\n" %
71 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
72 evt.Skip()
73
74 def OnCellRightDClick(self, evt):
75 self.log.write("OnCellRightDClick: (%d,%d) %s\n" %
76 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
77 evt.Skip()
78
79 def OnLabelLeftClick(self, evt):
80 self.log.write("OnLabelLeftClick: (%d,%d) %s\n" %
81 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
82 evt.Skip()
83
84 def OnLabelRightClick(self, evt):
85 self.log.write("OnLabelRightClick: (%d,%d) %s\n" %
86 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
87 evt.Skip()
88
89 def OnLabelLeftDClick(self, evt):
90 self.log.write("OnLabelLeftDClick: (%d,%d) %s\n" %
91 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
92 evt.Skip()
93
94 def OnLabelRightDClick(self, evt):
95 self.log.write("OnLabelRightDClick: (%d,%d) %s\n" %
96 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
97 evt.Skip()
98
99
100 def OnRowSize(self, evt):
101 self.log.write("OnRowSize: row %d, %s\n" %
102 (evt.GetRowOrCol(), evt.GetPosition()))
103 evt.Skip()
104
105 def OnColSize(self, evt):
106 self.log.write("OnColSize: col %d, %s\n" %
107 (evt.GetRowOrCol(), evt.GetPosition()))
108 evt.Skip()
109
110 def OnRangeSelect(self, evt):
111 if evt.Selecting():
112 self.log.write("OnRangeSelect: top-left %s, bottom-right %s\n" %
113 (evt.GetTopLeftCoords(), evt.GetBottomRightCoords()))
114 evt.Skip()
115
116 def OnCellChange(self, evt):
117 self.log.write("OnCellChange: (%d,%d) %s\n" %
118 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
119 evt.Skip()
120
121 def OnSelectCell(self, evt):
122 self.log.write("OnSelectCell: (%d,%d) %s\n" %
123 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
124 evt.Skip()
125
126 def OnEditorShown(self, evt):
127 self.log.write("OnEditorShown: (%d,%d) %s\n" %
128 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
129 evt.Skip()
130
131 def OnEditorHidden(self, evt):
132 self.log.write("OnEditorHidden: (%d,%d) %s\n" %
133 (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
134 evt.Skip()
135
136
137 #---------------------------------------------------------------------------
138
139 class TestFrame(wxFrame):
140 def __init__(self, parent, log):
141 wxFrame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
142 grid = SimpleGrid(self, log)
143
144
145
146 #---------------------------------------------------------------------------
147
148 if __name__ == '__main__':
149 import sys
150 app = wxPySimpleApp()
151 frame = TestFrame(None, sys.stdout)
152 frame.Show(true)
153 app.MainLoop()
154
155
156 #---------------------------------------------------------------------------