]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxLayoutConstraints.py
newevent helpers
[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)
1e4a197e 9 self.SetAutoLayout(True)
cf694132
RD
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
1fded56b
RD
117overview = """\<html><body>
118Objects of this class can be associated with a window to define its
119layout constraints, with respect to siblings or its parent.
cf694132 120
1fded56b
RD
121The class consists of the following eight constraints of class
122wxIndividualLayoutConstraint, some or all of which should be accessed
123directly to set the appropriate constraints.
cf694132
RD
124
125left: represents the left hand edge of the window
126
127right: represents the right hand edge of the window
128
129top: represents the top edge of the window
130
131bottom: represents the bottom edge of the window
132
133width: represents the width of the window
134
135height: represents the height of the window
136
137centreX: represents the horizontal centre point of the window
138
139centreY: represents the vertical centre point of the window
140
1fded56b
RD
141Most constraints are initially set to have the relationship
142wxUnconstrained, which means that their values should be calculated by
143looking at known constraints. The exceptions are width and height,
144which are set to wxAsIs to ensure that if the user does not specify a
145constraint, the existing width and height will be used, to be
146compatible with panel items which often have take a default size. If
147the constraint is wxAsIs, the dimension will not be changed.
cf694132 148
cf694132 149"""
1fded56b
RD
150
151
152
153
154if __name__ == '__main__':
155 import sys,os
156 import run
157 run.main(['', os.path.basename(sys.argv[0])])
158