]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GridSimple.py
f816e7a3f4c0b5abee65f12e685bc1ee2985fed5
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
)
33 self
.SetColLabelValue(0, "Custom")
34 self
.SetColLabelValue(1, "column")
35 self
.SetColLabelValue(2, "labels")
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
)
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
)
48 EVT_GRID_ROW_SIZE(self
, self
.OnRowSize
)
49 EVT_GRID_COL_SIZE(self
, self
.OnColSize
)
51 EVT_GRID_RANGE_SELECT(self
, self
.OnRangeSelect
)
52 EVT_GRID_CELL_CHANGE(self
, self
.OnCellChange
)
53 EVT_GRID_SELECT_CELL(self
, self
.OnSelectCell
)
55 EVT_GRID_EDITOR_SHOWN(self
, self
.OnEditorShown
)
56 EVT_GRID_EDITOR_HIDDEN(self
, self
.OnEditorHidden
)
59 def OnCellLeftClick(self
, evt
):
60 self
.log
.write("OnCellLeftClick: (%d,%d) %s\n" %
61 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
64 def OnCellRightClick(self
, evt
):
65 self
.log
.write("OnCellRightClick: (%d,%d) %s\n" %
66 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
69 def OnCellLeftDClick(self
, evt
):
70 self
.log
.write("OnCellLeftDClick: (%d,%d) %s\n" %
71 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
74 def OnCellRightDClick(self
, evt
):
75 self
.log
.write("OnCellRightDClick: (%d,%d) %s\n" %
76 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
79 def OnLabelLeftClick(self
, evt
):
80 self
.log
.write("OnLabelLeftClick: (%d,%d) %s\n" %
81 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
84 def OnLabelRightClick(self
, evt
):
85 self
.log
.write("OnLabelRightClick: (%d,%d) %s\n" %
86 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
89 def OnLabelLeftDClick(self
, evt
):
90 self
.log
.write("OnLabelLeftDClick: (%d,%d) %s\n" %
91 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
94 def OnLabelRightDClick(self
, evt
):
95 self
.log
.write("OnLabelRightDClick: (%d,%d) %s\n" %
96 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
100 def OnRowSize(self
, evt
):
101 self
.log
.write("OnRowSize: row %d, %s\n" %
102 (evt
.GetRowOrCol(), evt
.GetPosition()))
105 def OnColSize(self
, evt
):
106 self
.log
.write("OnColSize: col %d, %s\n" %
107 (evt
.GetRowOrCol(), evt
.GetPosition()))
110 def OnRangeSelect(self
, evt
):
112 self
.log
.write("OnRangeSelect: top-left %s, bottom-right %s\n" %
113 (evt
.GetTopLeftCoords(), evt
.GetBottomRightCoords()))
116 def OnCellChange(self
, evt
):
117 self
.log
.write("OnCellChange: (%d,%d) %s\n" %
118 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
121 def OnSelectCell(self
, evt
):
122 self
.log
.write("OnSelectCell: (%d,%d) %s\n" %
123 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
126 def OnEditorShown(self
, evt
):
127 self
.log
.write("OnEditorShown: (%d,%d) %s\n" %
128 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
131 def OnEditorHidden(self
, evt
):
132 self
.log
.write("OnEditorHidden: (%d,%d) %s\n" %
133 (evt
.GetRow(), evt
.GetCol(), evt
.GetPosition()))
137 #---------------------------------------------------------------------------
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
)
146 #---------------------------------------------------------------------------
148 if __name__
== '__main__':
150 app
= wxPySimpleApp()
151 frame
= TestFrame(None, sys
.stdout
)
156 #---------------------------------------------------------------------------