]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/LayoutConstraints.py
Allow clearing the history, and saving the history on demand
[wxWidgets.git] / wxPython / demo / LayoutConstraints.py
... / ...
CommitLineData
1
2import wx
3
4#---------------------------------------------------------------------------
5
6class TestLayoutConstraints(wx.Panel):
7 def __init__(self, parent):
8 wx.Panel.__init__(self, parent, -1)
9 self.SetAutoLayout(True)
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)
33 self.panelA.SetConstraints(lc)
34
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)
41 lc.left.RightOf(self.panelA, 10)
42 self.panelB.SetConstraints(lc)
43
44 self.panelC = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
45 self.panelC.SetBackgroundColour(wx.WHITE)
46 lc = wx.LayoutConstraints()
47 lc.top.Below(self.panelB, 10)
48 lc.right.SameAs(self, wx.Right, 10)
49 lc.bottom.SameAs(self, wx.Bottom, 10)
50 lc.left.RightOf(self.panelA, 10)
51 self.panelC.SetConstraints(lc)
52
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)
57 lc.height.AsIs ()
58 lc.width.PercentOf (self.panelA, wx.Width, 50)
59 b.SetConstraints(lc)
60
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)
65 lc.height.AsIs ()
66 lc.width.AsIs ()
67 b.SetConstraints(lc)
68
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)
74
75 b = wx.Button(self.panelC, 100, ' Panel C ')
76 lc = wx.LayoutConstraints()
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
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)
88 self.panelD.SetConstraints(lc)
89
90
91 def OnButton(self, event):
92 wx.Bell()
93
94
95#---------------------------------------------------------------------------
96
97def runTest(frame, nb, log):
98 win = TestLayoutConstraints(nb)
99 return win
100
101#---------------------------------------------------------------------------
102
103
104
105overview = """\
106<html><body>
107Objects of this class can be associated with a window to define its
108layout constraints, with respect to siblings or its parent.
109
110<p>The class consists of the following eight constraints of class
111wxIndividualLayoutConstraint, some or all of which should be accessed
112directly to set the appropriate constraints.
113
114<p><ul>
115<li>left: represents the left hand edge of the window
116
117<li>right: represents the right hand edge of the window
118
119<li>top: represents the top edge of the window
120
121<li>bottom: represents the bottom edge of the window
122
123<li>width: represents the width of the window
124
125<li>height: represents the height of the window
126
127<li>centreX: represents the horizontal centre point of the window
128
129<li>centreY: represents the vertical centre point of the window
130</ul>
131<p>Most constraints are initially set to have the relationship
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.
138
139"""
140
141
142
143
144if __name__ == '__main__':
145 import sys,os
146 import run
147 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
148