]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxLayoutConstraints.py
A little tweak to the usage text
[wxWidgets.git] / wxPython / demo / wxLayoutConstraints.py
1 # 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2 #
3 # o Updated for wx namespace
4 #
5
6 import wx
7
8 #---------------------------------------------------------------------------
9
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)
15
16 self.SetBackgroundColour(wx.NamedColour("MEDIUM ORCHID"))
17
18 self.panelA = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
19 self.panelA.SetBackgroundColour(wx.BLUE)
20
21 txt = wx.StaticText(
22 self.panelA, -1,
23 "Resize the window and see\n"
24 "what happens... Notice that\n"
25 "there is no OnSize handler.",
26 (5,5), (-1, 50)
27 )
28
29 txt.SetBackgroundColour(wx.BLUE)
30 txt.SetForegroundColour(wx.WHITE)
31
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)
38
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)
47
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)
56
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)
61 lc.height.AsIs ()
62 lc.width.PercentOf (self.panelA, wx.Width, 50)
63 b.SetConstraints(lc);
64
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)
69 lc.height.AsIs ()
70 lc.width.AsIs ()
71 b.SetConstraints(lc);
72
73 self.panelD = wx.Window(self.panelC, -1, style=wx.SIMPLE_BORDER)
74 self.panelD.SetBackgroundColour(wx.GREEN)
75 wx.StaticText(
76 self.panelD, -1, "Panel D", (4, 4)
77 ).SetBackgroundColour(wx.GREEN)
78
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)
83 lc.height.AsIs ()
84 lc.width.AsIs ()
85 b.SetConstraints(lc);
86
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);
93
94
95 def OnButton(self, event):
96 wx.Bell()
97
98
99 #---------------------------------------------------------------------------
100
101 def runTest(frame, nb, log):
102 win = TestLayoutConstraints(nb)
103 return win
104
105 #---------------------------------------------------------------------------
106
107
108
109 overview = """\
110 <html><body>
111 Objects of this class can be associated with a window to define its
112 layout constraints, with respect to siblings or its parent.
113
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.
117
118 <p><ul>
119 <li>left: represents the left hand edge of the window
120
121 <li>right: represents the right hand edge of the window
122
123 <li>top: represents the top edge of the window
124
125 <li>bottom: represents the bottom edge of the window
126
127 <li>width: represents the width of the window
128
129 <li>height: represents the height of the window
130
131 <li>centreX: represents the horizontal centre point of the window
132
133 <li>centreY: represents the vertical centre point of the window
134 </ul>
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.
142
143 """
144
145
146
147
148 if __name__ == '__main__':
149 import sys,os
150 import run
151 run.main(['', os.path.basename(sys.argv[0])])
152