]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxLayoutConstraints.py
1 # 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
8 #---------------------------------------------------------------------------
10 class TestLayoutConstraints(wx
.Panel
):
11 def __init__(self
, parent
):
12 wx
.Panel
.__init
__(self
, parent
, -1)
13 self
.SetAutoLayout(True)
14 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id=100)
16 self
.SetBackgroundColour(wx
.NamedColour("MEDIUM ORCHID"))
18 self
.panelA
= wx
.Window(self
, -1, style
=wx
.SIMPLE_BORDER
)
19 self
.panelA
.SetBackgroundColour(wx
.BLUE
)
23 "Resize the window and see\n"
24 "what happens... Notice that\n"
25 "there is no OnSize handler.",
29 txt
.SetBackgroundColour(wx
.BLUE
)
30 txt
.SetForegroundColour(wx
.WHITE
)
32 lc
= wx
.LayoutConstraints()
33 lc
.top
.SameAs(self
, wx
.Top
, 10)
34 lc
.left
.SameAs(self
, wx
.Left
, 10)
35 lc
.bottom
.SameAs(self
, wx
.Bottom
, 10)
36 lc
.right
.PercentOf(self
, wx
.Right
, 50)
37 self
.panelA
.SetConstraints(lc
)
39 self
.panelB
= wx
.Window(self
, -1, style
=wx
.SIMPLE_BORDER
)
40 self
.panelB
.SetBackgroundColour(wx
.RED
)
41 lc
= wx
.LayoutConstraints()
42 lc
.top
.SameAs(self
, wx
.Top
, 10)
43 lc
.right
.SameAs(self
, wx
.Right
, 10)
44 lc
.bottom
.PercentOf(self
, wx
.Bottom
, 30)
45 lc
.left
.RightOf(self
.panelA
, 10)
46 self
.panelB
.SetConstraints(lc
)
48 self
.panelC
= wx
.Window(self
, -1, style
=wx
.SIMPLE_BORDER
)
49 self
.panelC
.SetBackgroundColour(wx
.WHITE
)
50 lc
= wx
.LayoutConstraints()
51 lc
.top
.Below(self
.panelB
, 10)
52 lc
.right
.SameAs(self
, wx
.Right
, 10)
53 lc
.bottom
.SameAs(self
, wx
.Bottom
, 10)
54 lc
.left
.RightOf(self
.panelA
, 10)
55 self
.panelC
.SetConstraints(lc
)
57 b
= wx
.Button(self
.panelA
, 100, ' Panel A ')
58 lc
= wx
.LayoutConstraints()
59 lc
.centreX
.SameAs (self
.panelA
, wx
.CentreX
)
60 lc
.centreY
.SameAs (self
.panelA
, wx
.CentreY
)
62 lc
.width
.PercentOf (self
.panelA
, wx
.Width
, 50)
65 b
= wx
.Button(self
.panelB
, 100, ' Panel B ')
66 lc
= wx
.LayoutConstraints()
67 lc
.top
.SameAs (self
.panelB
, wx
.Top
, 2)
68 lc
.right
.SameAs (self
.panelB
, wx
.Right
, 4)
73 self
.panelD
= wx
.Window(self
.panelC
, -1, style
=wx
.SIMPLE_BORDER
)
74 self
.panelD
.SetBackgroundColour(wx
.GREEN
)
76 self
.panelD
, -1, "Panel D", (4, 4)
77 ).SetBackgroundColour(wx
.GREEN
)
79 b
= wx
.Button(self
.panelC
, 100, ' Panel C ')
80 lc
= wx
.LayoutConstraints()
81 lc
.top
.Below (self
.panelD
)
82 lc
.left
.RightOf (self
.panelD
)
87 lc
= wx
.LayoutConstraints()
88 lc
.bottom
.PercentOf (self
.panelC
, wx
.Height
, 50)
89 lc
.right
.PercentOf (self
.panelC
, wx
.Width
, 50)
90 lc
.height
.SameAs (b
, wx
.Height
)
91 lc
.width
.SameAs (b
, wx
.Width
)
92 self
.panelD
.SetConstraints(lc
);
95 def OnButton(self
, event
):
99 #---------------------------------------------------------------------------
101 def runTest(frame
, nb
, log
):
102 win
= TestLayoutConstraints(nb
)
105 #---------------------------------------------------------------------------
111 Objects of this class can be associated with a window to define its
112 layout constraints, with respect to siblings or its parent.
114 <p>The class consists of the following eight constraints of class
115 wxIndividualLayoutConstraint, some or all of which should be accessed
116 directly to set the appropriate constraints.
119 <li>left: represents the left hand edge of the window
121 <li>right: represents the right hand edge of the window
123 <li>top: represents the top edge of the window
125 <li>bottom: represents the bottom edge of the window
127 <li>width: represents the width of the window
129 <li>height: represents the height of the window
131 <li>centreX: represents the horizontal centre point of the window
133 <li>centreY: represents the vertical centre point of the window
135 <p>Most constraints are initially set to have the relationship
136 wxUnconstrained, which means that their values should be calculated by
137 looking at known constraints. The exceptions are width and height,
138 which are set to wxAsIs to ensure that if the user does not specify a
139 constraint, the existing width and height will be used, to be
140 compatible with panel items which often have take a default size. If
141 the constraint is wxAsIs, the dimension will not be changed.
148 if __name__
== '__main__':
151 run
.main(['', os
.path
.basename(sys
.argv
[0])])