]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxLayoutConstraints.py
2 from wxPython
.wx
import *
4 #---------------------------------------------------------------------------
6 class TestLayoutConstraints(wxPanel
):
7 def __init__(self
, parent
):
8 wxPanel
.__init
__(self
, parent
, -1)
9 self
.SetAutoLayout(True)
10 EVT_BUTTON(self
, 100, self
.OnButton
)
12 self
.SetBackgroundColour(wxNamedColour("MEDIUM ORCHID"))
14 self
.panelA
= wxWindow(self
, -1, wxDefaultPosition
, wxDefaultSize
,
16 self
.panelA
.SetBackgroundColour(wxBLUE
)
17 txt
= wxStaticText(self
.panelA
, -1,
18 "Resize the window and see\n"
19 "what happens... Notice that\n"
20 "there is no OnSize handler.",
21 wxPoint(5,5), wxSize(-1, 50))
22 txt
.SetBackgroundColour(wxBLUE
)
23 txt
.SetForegroundColour(wxWHITE
)
25 lc
= wxLayoutConstraints()
26 lc
.top
.SameAs(self
, wxTop
, 10)
27 lc
.left
.SameAs(self
, wxLeft
, 10)
28 lc
.bottom
.SameAs(self
, wxBottom
, 10)
29 lc
.right
.PercentOf(self
, wxRight
, 50)
30 self
.panelA
.SetConstraints(lc
)
32 self
.panelB
= wxWindow(self
, -1, wxDefaultPosition
, wxDefaultSize
,
34 self
.panelB
.SetBackgroundColour(wxRED
)
35 lc
= wxLayoutConstraints()
36 lc
.top
.SameAs(self
, wxTop
, 10)
37 lc
.right
.SameAs(self
, wxRight
, 10)
38 lc
.bottom
.PercentOf(self
, wxBottom
, 30)
39 lc
.left
.RightOf(self
.panelA
, 10)
40 self
.panelB
.SetConstraints(lc
)
42 self
.panelC
= wxWindow(self
, -1, wxDefaultPosition
, wxDefaultSize
,
44 self
.panelC
.SetBackgroundColour(wxWHITE
)
45 lc
= wxLayoutConstraints()
46 lc
.top
.Below(self
.panelB
, 10)
47 lc
.right
.SameAs(self
, wxRight
, 10)
48 lc
.bottom
.SameAs(self
, wxBottom
, 10)
49 lc
.left
.RightOf(self
.panelA
, 10)
50 self
.panelC
.SetConstraints(lc
)
52 b
= wxButton(self
.panelA
, 100, ' Panel A ')
53 lc
= wxLayoutConstraints()
54 lc
.centreX
.SameAs (self
.panelA
, wxCentreX
)
55 lc
.centreY
.SameAs (self
.panelA
, wxCentreY
)
57 lc
.width
.PercentOf (self
.panelA
, wxWidth
, 50)
60 b
= wxButton(self
.panelB
, 100, ' Panel B ')
61 lc
= wxLayoutConstraints()
62 lc
.top
.SameAs (self
.panelB
, wxTop
, 2)
63 lc
.right
.SameAs (self
.panelB
, wxRight
, 4)
68 self
.panelD
= wxWindow(self
.panelC
, -1, wxDefaultPosition
, wxDefaultSize
,
70 self
.panelD
.SetBackgroundColour(wxGREEN
)
71 wxStaticText(self
.panelD
, -1, "Panel D", wxPoint(4, 4)).SetBackgroundColour(wxGREEN
)
73 b
= wxButton(self
.panelC
, 100, ' Panel C ')
74 lc
= wxLayoutConstraints()
75 lc
.top
.Below (self
.panelD
)
76 lc
.left
.RightOf (self
.panelD
)
81 lc
= wxLayoutConstraints()
82 lc
.bottom
.PercentOf (self
.panelC
, wxHeight
, 50)
83 lc
.right
.PercentOf (self
.panelC
, wxWidth
, 50)
84 lc
.height
.SameAs (b
, wxHeight
)
85 lc
.width
.SameAs (b
, wxWidth
)
86 self
.panelD
.SetConstraints(lc
);
91 def OnButton(self
, event
):
95 #---------------------------------------------------------------------------
97 def runTest(frame
, nb
, log
):
98 win
= TestLayoutConstraints(nb
)
101 #---------------------------------------------------------------------------
117 overview
= """\<html><body>
118 Objects of this class can be associated with a window to define its
119 layout constraints, with respect to siblings or its parent.
121 The class consists of the following eight constraints of class
122 wxIndividualLayoutConstraint, some or all of which should be accessed
123 directly to set the appropriate constraints.
125 left: represents the left hand edge of the window
127 right: represents the right hand edge of the window
129 top: represents the top edge of the window
131 bottom: represents the bottom edge of the window
133 width: represents the width of the window
135 height: represents the height of the window
137 centreX: represents the horizontal centre point of the window
139 centreY: represents the vertical centre point of the window
141 Most constraints are initially set to have the relationship
142 wxUnconstrained, which means that their values should be calculated by
143 looking at known constraints. The exceptions are width and height,
144 which are set to wxAsIs to ensure that if the user does not specify a
145 constraint, the existing width and height will be used, to be
146 compatible with panel items which often have take a default size. If
147 the constraint is wxAsIs, the dimension will not be changed.
154 if __name__
== '__main__':
157 run
.main(['', os
.path
.basename(sys
.argv
[0])])