]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxLayoutConstraints.py
compilation fix (for !PCH)
[wxWidgets.git] / wxPython / demo / wxLayoutConstraints.py
CommitLineData
cf694132
RD
1
2from wxPython.wx import *
3
4#---------------------------------------------------------------------------
5
9d8bd15f 6class TestLayoutConstraints(wxPanel):
cf694132 7 def __init__(self, parent):
9d8bd15f 8 wxPanel.__init__(self, parent, -1)
cf694132
RD
9 self.SetAutoLayout(true)
10 EVT_BUTTON(self, 100, self.OnButton)
11
f0261a72
RD
12 self.SetBackgroundColour(wxNamedColour("MEDIUM ORCHID"))
13
cf694132
RD
14 self.panelA = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
15 wxSIMPLE_BORDER)
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)
24
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)
31
32 self.panelB = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
33 wxSIMPLE_BORDER)
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)
41
42 self.panelC = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
43 wxSIMPLE_BORDER)
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)
51
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)
56 lc.height.AsIs ()
57 lc.width.PercentOf (self.panelA, wxWidth, 50)
58 b.SetConstraints(lc);
59
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)
64 lc.height.AsIs ()
65 lc.width.AsIs ()
66 b.SetConstraints(lc);
67
68 self.panelD = wxWindow(self.panelC, -1, wxDefaultPosition, wxDefaultSize,
69 wxSIMPLE_BORDER)
70 self.panelD.SetBackgroundColour(wxGREEN)
71 wxStaticText(self.panelD, -1, "Panel D", wxPoint(4, 4)).SetBackgroundColour(wxGREEN)
72
73 b = wxButton(self.panelC, 100, ' Panel C ')
74 lc = wxLayoutConstraints()
75 lc.top.Below (self.panelD)
76 lc.left.RightOf (self.panelD)
77 lc.height.AsIs ()
78 lc.width.AsIs ()
79 b.SetConstraints(lc);
80
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);
87
88
f0261a72
RD
89
90
cf694132
RD
91 def OnButton(self, event):
92 wxBell()
93
94
95#---------------------------------------------------------------------------
96
97def runTest(frame, nb, log):
98 win = TestLayoutConstraints(nb)
99 return win
100
101#---------------------------------------------------------------------------
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117overview = """\
118Objects of this class can be associated with a window to define its layout constraints, with respect to siblings or its parent.
119
120The class consists of the following eight constraints of class wxIndividualLayoutConstraint, some or all of which should be accessed directly to set the appropriate constraints.
121
122left: represents the left hand edge of the window
123
124right: represents the right hand edge of the window
125
126top: represents the top edge of the window
127
128bottom: represents the bottom edge of the window
129
130width: represents the width of the window
131
132height: represents the height of the window
133
134centreX: represents the horizontal centre point of the window
135
136centreY: represents the vertical centre point of the window
137
138Most constraints are initially set to have the relationship wxUnconstrained, which means that their values should be calculated by looking at known constraints. The exceptions are width and height, which are set to wxAsIs to ensure that if the user does not specify a constraint, the existing width and height will be used, to be compatible with panel items which often have take a default size. If the constraint is wxAsIs, the dimension will not be changed.
139
140wxLayoutConstraints()
141-------------------------------------------
142
143Constructor.
144"""