]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxGridBagSizer.py
2 import wx
# This module uses the new wx namespace
4 #----------------------------------------------------------------------
6 The wxGridBagSizer is similar to the wxFlexGridSizer except the items are explicitly positioned
7 in a virtual cell of the layout grid, and column or row spanning is allowed. For example, this
8 static text is positioned at (0,0) and it spans 7 columns.
12 class TestFrame(wx
.Frame
):
14 wx
.Frame
.__init
__(self
, None, -1, "wxGridBagSizer")
15 p
= wx
.Panel(self
, -1)
16 gbs
= self
.gbs
= wx
.GridBagSizer()
18 gbs
.Add( wx
.StaticText(p
, -1, gbsDescription
),
19 (0,0), (1,7), wx
.ALIGN_CENTER | wx
.ALL
, 5)
22 gbs
.Add( wx
.TextCtrl(p
, -1, "pos(1,0)"), (1,0) )
23 gbs
.Add( wx
.TextCtrl(p
, -1, "pos(1,1)"), (1,1) )
24 gbs
.Add( wx
.TextCtrl(p
, -1, "pos(2,0)"), (2,0) )
25 gbs
.Add( wx
.TextCtrl(p
, -1, "pos(2,1)"), (2,1) )
27 gbs
.Add( wx
.TextCtrl(p
, -1, "pos(3,2), span(1,2)\nthis row and col are growable", style
=wx
.TE_MULTILINE
),
28 (3,2), (1,2), flag
=wx
.EXPAND
)
30 gbs
.Add( wx
.TextCtrl(p
, -1, "pos(4,3), span(3,1)", style
=wx
.TE_MULTILINE
),
31 (4,3), (3,1), wx
.EXPAND
)
33 gbs
.Add( wx
.TextCtrl(p
, -1, "pos(5,4)"), (5,4), flag
=wx
.EXPAND
)
34 gbs
.Add( wx
.TextCtrl(p
, -1, "pos(6,5)"), (6,5), flag
=wx
.EXPAND
)
35 gbs
.Add( wx
.TextCtrl(p
, -1, "pos(7,6)"), (7,6) )
37 moveBtn1
= wx
.Button(p
, -1, "Move this to (3,6)")
38 moveBtn2
= wx
.Button(p
, -1, "Move this to (3,6)");
39 gbs
.Add( moveBtn1
, (10,2) )
40 gbs
.Add( moveBtn2
, (10,3) )
42 hideBtn
= wx
.Button(p
, -1, "Hide this item -->")
43 gbs
.Add(hideBtn
, (12, 3))
45 hideTxt
= wx
.TextCtrl(p
, -1, "pos(12,4), size(150, -1)", size
= (150,-1))
46 gbs
.Add( hideTxt
, (12,4) )
48 showBtn
= wx
.Button(p
, -1, "<-- Show it again")
49 gbs
.Add(showBtn
, (12, 5))
51 self
.hideBtn
= hideBtn
52 self
.showBtn
= showBtn
53 self
.hideTxt
= hideTxt
55 self
.Bind(wx
.EVT_BUTTON
, self
.OnHideButton
, hideBtn
)
56 self
.Bind(wx
.EVT_BUTTON
, self
.OnShowButton
, showBtn
)
57 self
.Bind(wx
.EVT_BUTTON
, self
.OnMoveButton
, moveBtn1
)
58 self
.Bind(wx
.EVT_BUTTON
, self
.OnMoveButton
, moveBtn2
)
60 # Add a spacer at the end to ensure some extra space at the bottom
61 gbs
.Add((10,10), (14,0))
67 self
.SetClientSize(p
.GetSize())
70 def OnHideButton(self
, evt
):
71 self
.gbs
.Hide(self
.hideTxt
)
72 self
.hideBtn
.Disable()
77 def OnShowButton(self
, evt
):
78 self
.gbs
.Show(self
.hideTxt
)
80 self
.showBtn
.Disable()
84 def OnMoveButton(self
, evt
):
85 btn
= evt
.GetEventObject()
86 curPos
= self
.gbs
.GetItemPosition(btn
)
88 # if it's already at the "other" spot then move it back
90 self
.gbs
.SetItemPosition(btn
, self
.lastPos
)
91 btn
.SetLabel("Move this to (3,6)")
93 if self
.gbs
.CheckForIntersection( (3,6), (1,1) ):
95 wxGridBagSizer will not allow items to be in the same cell as
96 another item, so this operation will fail. You will also get an assert
97 when compiled in debug mode.""",
98 "Warning", wx
.OK | wx
.ICON_INFORMATION
)
101 if self
.gbs
.SetItemPosition(btn
, (3,6)):
102 self
.lastPos
= curPos
103 btn
.SetLabel("Move it back")
104 except wx
.PyAssertionError
:
110 #----------------------------------------------------------------------
112 def runTest(frame
, nb
, log
):
118 #----------------------------------------------------------------------
122 overview
= """<html><body>
123 <h2><center>wxGridBagSizer</center></h2>
125 The wxGridBagSizer is more or less a port of the the RowColSizer (that
126 has been in the wxPython.lib package for quite some time) to C++. It
127 allows items to be placed at specific layout grid cells, and items can
128 span across more than one row or column.
134 if __name__
== '__main__':
137 run
.main(['', os
.path
.basename(sys
.argv
[0])])