]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/LayoutConstraints.py
4 #---------------------------------------------------------------------------
6 class TestLayoutConstraints(wx
.Panel
):
7 def __init__(self
, parent
):
8 wx
.Panel
.__init
__(self
, parent
, -1)
9 self
.SetAutoLayout(True)
10 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id=100)
12 self
.SetBackgroundColour(wx
.NamedColour("MEDIUM ORCHID"))
14 self
.panelA
= wx
.Window(self
, -1, style
=wx
.SIMPLE_BORDER
)
15 self
.panelA
.SetBackgroundColour(wx
.BLUE
)
19 "Resize the window and see\n"
20 "what happens... Notice that\n"
21 "there is no OnSize handler.",
25 txt
.SetBackgroundColour(wx
.BLUE
)
26 txt
.SetForegroundColour(wx
.WHITE
)
28 lc
= wx
.LayoutConstraints()
29 lc
.top
.SameAs(self
, wx
.Top
, 10)
30 lc
.left
.SameAs(self
, wx
.Left
, 10)
31 lc
.bottom
.SameAs(self
, wx
.Bottom
, 10)
32 lc
.right
.PercentOf(self
, wx
.Right
, 50)
33 self
.panelA
.SetConstraints(lc
)
35 self
.panelB
= wx
.Window(self
, -1, style
=wx
.SIMPLE_BORDER
)
36 self
.panelB
.SetBackgroundColour(wx
.RED
)
37 lc
= wx
.LayoutConstraints()
38 lc
.top
.SameAs(self
, wx
.Top
, 10)
39 lc
.right
.SameAs(self
, wx
.Right
, 10)
40 lc
.bottom
.PercentOf(self
, wx
.Bottom
, 30)
41 lc
.left
.RightOf(self
.panelA
, 10)
42 self
.panelB
.SetConstraints(lc
)
44 self
.panelC
= wx
.Window(self
, -1, style
=wx
.SIMPLE_BORDER
)
45 self
.panelC
.SetBackgroundColour(wx
.WHITE
)
46 lc
= wx
.LayoutConstraints()
47 lc
.top
.Below(self
.panelB
, 10)
48 lc
.right
.SameAs(self
, wx
.Right
, 10)
49 lc
.bottom
.SameAs(self
, wx
.Bottom
, 10)
50 lc
.left
.RightOf(self
.panelA
, 10)
51 self
.panelC
.SetConstraints(lc
)
53 b
= wx
.Button(self
.panelA
, 100, ' Panel A ')
54 lc
= wx
.LayoutConstraints()
55 lc
.centreX
.SameAs (self
.panelA
, wx
.CentreX
)
56 lc
.centreY
.SameAs (self
.panelA
, wx
.CentreY
)
58 lc
.width
.PercentOf (self
.panelA
, wx
.Width
, 50)
61 b
= wx
.Button(self
.panelB
, 100, ' Panel B ')
62 lc
= wx
.LayoutConstraints()
63 lc
.top
.SameAs (self
.panelB
, wx
.Top
, 2)
64 lc
.right
.SameAs (self
.panelB
, wx
.Right
, 4)
69 self
.panelD
= wx
.Window(self
.panelC
, -1, style
=wx
.SIMPLE_BORDER
)
70 self
.panelD
.SetBackgroundColour(wx
.GREEN
)
72 self
.panelD
, -1, "Panel D", (4, 4)
73 ).SetBackgroundColour(wx
.GREEN
)
75 b
= wx
.Button(self
.panelC
, 100, ' Panel C ')
76 lc
= wx
.LayoutConstraints()
77 lc
.top
.Below (self
.panelD
)
78 lc
.left
.RightOf (self
.panelD
)
83 lc
= wx
.LayoutConstraints()
84 lc
.bottom
.PercentOf (self
.panelC
, wx
.Height
, 50)
85 lc
.right
.PercentOf (self
.panelC
, wx
.Width
, 50)
86 lc
.height
.SameAs (b
, wx
.Height
)
87 lc
.width
.SameAs (b
, wx
.Width
)
88 self
.panelD
.SetConstraints(lc
);
91 def OnButton(self
, event
):
95 #---------------------------------------------------------------------------
97 def runTest(frame
, nb
, log
):
98 win
= TestLayoutConstraints(nb
)
101 #---------------------------------------------------------------------------
107 Objects of this class can be associated with a window to define its
108 layout constraints, with respect to siblings or its parent.
110 <p>The class consists of the following eight constraints of class
111 wxIndividualLayoutConstraint, some or all of which should be accessed
112 directly to set the appropriate constraints.
115 <li>left: represents the left hand edge of the window
117 <li>right: represents the right hand edge of the window
119 <li>top: represents the top edge of the window
121 <li>bottom: represents the bottom edge of the window
123 <li>width: represents the width of the window
125 <li>height: represents the height of the window
127 <li>centreX: represents the horizontal centre point of the window
129 <li>centreY: represents the vertical centre point of the window
131 <p>Most constraints are initially set to have the relationship
132 wxUnconstrained, which means that their values should be calculated by
133 looking at known constraints. The exceptions are width and height,
134 which are set to wxAsIs to ensure that if the user does not specify a
135 constraint, the existing width and height will be used, to be
136 compatible with panel items which often have take a default size. If
137 the constraint is wxAsIs, the dimension will not be changed.
144 if __name__
== '__main__':
147 run
.main(['', os
.path
.basename(sys
.argv
[0])])