]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/LayoutConstraints.py
fixes for unicode build, return values from event handlers (via
[wxWidgets.git] / wxPython / demo / LayoutConstraints.py
CommitLineData
cf694132 1
8fa876ca 2import wx
cf694132
RD
3
4#---------------------------------------------------------------------------
5
8fa876ca 6class TestLayoutConstraints(wx.Panel):
cf694132 7 def __init__(self, parent):
8fa876ca 8 wx.Panel.__init__(self, parent, -1)
1e4a197e 9 self.SetAutoLayout(True)
8fa876ca
RD
10 self.Bind(wx.EVT_BUTTON, self.OnButton, id=100)
11
12 self.SetBackgroundColour(wx.NamedColour("MEDIUM ORCHID"))
13
14 self.panelA = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
15 self.panelA.SetBackgroundColour(wx.BLUE)
16
17 txt = wx.StaticText(
18 self.panelA, -1,
19 "Resize the window and see\n"
20 "what happens... Notice that\n"
21 "there is no OnSize handler.",
22 (5,5), (-1, 50)
23 )
24
25 txt.SetBackgroundColour(wx.BLUE)
26 txt.SetForegroundColour(wx.WHITE)
27
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)
cf694132
RD
33 self.panelA.SetConstraints(lc)
34
8fa876ca
RD
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)
cf694132
RD
41 lc.left.RightOf(self.panelA, 10)
42 self.panelB.SetConstraints(lc)
43
8fa876ca
RD
44 self.panelC = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
45 self.panelC.SetBackgroundColour(wx.WHITE)
46 lc = wx.LayoutConstraints()
cf694132 47 lc.top.Below(self.panelB, 10)
8fa876ca
RD
48 lc.right.SameAs(self, wx.Right, 10)
49 lc.bottom.SameAs(self, wx.Bottom, 10)
cf694132
RD
50 lc.left.RightOf(self.panelA, 10)
51 self.panelC.SetConstraints(lc)
52
8fa876ca
RD
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)
cf694132 57 lc.height.AsIs ()
8fa876ca 58 lc.width.PercentOf (self.panelA, wx.Width, 50)
cf694132
RD
59 b.SetConstraints(lc);
60
8fa876ca
RD
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)
cf694132
RD
65 lc.height.AsIs ()
66 lc.width.AsIs ()
67 b.SetConstraints(lc);
68
8fa876ca
RD
69 self.panelD = wx.Window(self.panelC, -1, style=wx.SIMPLE_BORDER)
70 self.panelD.SetBackgroundColour(wx.GREEN)
71 wx.StaticText(
72 self.panelD, -1, "Panel D", (4, 4)
73 ).SetBackgroundColour(wx.GREEN)
cf694132 74
8fa876ca
RD
75 b = wx.Button(self.panelC, 100, ' Panel C ')
76 lc = wx.LayoutConstraints()
cf694132
RD
77 lc.top.Below (self.panelD)
78 lc.left.RightOf (self.panelD)
79 lc.height.AsIs ()
80 lc.width.AsIs ()
81 b.SetConstraints(lc);
82
8fa876ca
RD
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)
cf694132
RD
88 self.panelD.SetConstraints(lc);
89
90
91 def OnButton(self, event):
8fa876ca 92 wx.Bell()
cf694132
RD
93
94
95#---------------------------------------------------------------------------
96
97def runTest(frame, nb, log):
98 win = TestLayoutConstraints(nb)
99 return win
100
101#---------------------------------------------------------------------------
102
103
104
8fa876ca
RD
105overview = """\
106<html><body>
1fded56b
RD
107Objects of this class can be associated with a window to define its
108layout constraints, with respect to siblings or its parent.
cf694132 109
8fa876ca 110<p>The class consists of the following eight constraints of class
1fded56b
RD
111wxIndividualLayoutConstraint, some or all of which should be accessed
112directly to set the appropriate constraints.
cf694132 113
8fa876ca
RD
114<p><ul>
115<li>left: represents the left hand edge of the window
cf694132 116
8fa876ca 117<li>right: represents the right hand edge of the window
cf694132 118
8fa876ca 119<li>top: represents the top edge of the window
cf694132 120
8fa876ca 121<li>bottom: represents the bottom edge of the window
cf694132 122
8fa876ca 123<li>width: represents the width of the window
cf694132 124
8fa876ca 125<li>height: represents the height of the window
cf694132 126
8fa876ca 127<li>centreX: represents the horizontal centre point of the window
cf694132 128
8fa876ca
RD
129<li>centreY: represents the vertical centre point of the window
130</ul>
131<p>Most constraints are initially set to have the relationship
1fded56b
RD
132wxUnconstrained, which means that their values should be calculated by
133looking at known constraints. The exceptions are width and height,
134which are set to wxAsIs to ensure that if the user does not specify a
135constraint, the existing width and height will be used, to be
136compatible with panel items which often have take a default size. If
137the constraint is wxAsIs, the dimension will not be changed.
cf694132 138
cf694132 139"""
1fded56b
RD
140
141
142
143
144if __name__ == '__main__':
145 import sys,os
146 import run
8eca4fef 147 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b 148