]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxLayoutConstraints.py
Applied patch [ 827011 ] Event-based processing of item tooltips in wxTreeCtrl
[wxWidgets.git] / wxPython / demo / wxLayoutConstraints.py
CommitLineData
8fa876ca
RD
1# 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
cf694132 5
8fa876ca 6import wx
cf694132
RD
7
8#---------------------------------------------------------------------------
9
8fa876ca 10class TestLayoutConstraints(wx.Panel):
cf694132 11 def __init__(self, parent):
8fa876ca 12 wx.Panel.__init__(self, parent, -1)
1e4a197e 13 self.SetAutoLayout(True)
8fa876ca
RD
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)
cf694132
RD
37 self.panelA.SetConstraints(lc)
38
8fa876ca
RD
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)
cf694132
RD
45 lc.left.RightOf(self.panelA, 10)
46 self.panelB.SetConstraints(lc)
47
8fa876ca
RD
48 self.panelC = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
49 self.panelC.SetBackgroundColour(wx.WHITE)
50 lc = wx.LayoutConstraints()
cf694132 51 lc.top.Below(self.panelB, 10)
8fa876ca
RD
52 lc.right.SameAs(self, wx.Right, 10)
53 lc.bottom.SameAs(self, wx.Bottom, 10)
cf694132
RD
54 lc.left.RightOf(self.panelA, 10)
55 self.panelC.SetConstraints(lc)
56
8fa876ca
RD
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)
cf694132 61 lc.height.AsIs ()
8fa876ca 62 lc.width.PercentOf (self.panelA, wx.Width, 50)
cf694132
RD
63 b.SetConstraints(lc);
64
8fa876ca
RD
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)
cf694132
RD
69 lc.height.AsIs ()
70 lc.width.AsIs ()
71 b.SetConstraints(lc);
72
8fa876ca
RD
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)
cf694132 78
8fa876ca
RD
79 b = wx.Button(self.panelC, 100, ' Panel C ')
80 lc = wx.LayoutConstraints()
cf694132
RD
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
8fa876ca
RD
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)
cf694132
RD
92 self.panelD.SetConstraints(lc);
93
94
95 def OnButton(self, event):
8fa876ca 96 wx.Bell()
cf694132
RD
97
98
99#---------------------------------------------------------------------------
100
101def runTest(frame, nb, log):
102 win = TestLayoutConstraints(nb)
103 return win
104
105#---------------------------------------------------------------------------
106
107
108
8fa876ca
RD
109overview = """\
110<html><body>
1fded56b
RD
111Objects of this class can be associated with a window to define its
112layout constraints, with respect to siblings or its parent.
cf694132 113
8fa876ca 114<p>The class consists of the following eight constraints of class
1fded56b
RD
115wxIndividualLayoutConstraint, some or all of which should be accessed
116directly to set the appropriate constraints.
cf694132 117
8fa876ca
RD
118<p><ul>
119<li>left: represents the left hand edge of the window
cf694132 120
8fa876ca 121<li>right: represents the right hand edge of the window
cf694132 122
8fa876ca 123<li>top: represents the top edge of the window
cf694132 124
8fa876ca 125<li>bottom: represents the bottom edge of the window
cf694132 126
8fa876ca 127<li>width: represents the width of the window
cf694132 128
8fa876ca 129<li>height: represents the height of the window
cf694132 130
8fa876ca 131<li>centreX: represents the horizontal centre point of the window
cf694132 132
8fa876ca
RD
133<li>centreY: represents the vertical centre point of the window
134</ul>
135<p>Most constraints are initially set to have the relationship
1fded56b
RD
136wxUnconstrained, which means that their values should be calculated by
137looking at known constraints. The exceptions are width and height,
138which are set to wxAsIs to ensure that if the user does not specify a
139constraint, the existing width and height will be used, to be
140compatible with panel items which often have take a default size. If
141the constraint is wxAsIs, the dimension will not be changed.
cf694132 142
cf694132 143"""
1fded56b
RD
144
145
146
147
148if __name__ == '__main__':
149 import sys,os
150 import run
151 run.main(['', os.path.basename(sys.argv[0])])
152