1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
import wx
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class TestLayoutConstraints(wx.Panel):
|
1999-04-30 03:29:54 +00:00
|
|
|
def __init__(self, parent):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2003-03-25 06:35:27 +00:00
|
|
|
self.SetAutoLayout(True)
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnButton, id=100)
|
|
|
|
|
|
|
|
self.SetBackgroundColour(wx.NamedColour("MEDIUM ORCHID"))
|
|
|
|
|
|
|
|
self.panelA = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
|
|
|
|
self.panelA.SetBackgroundColour(wx.BLUE)
|
|
|
|
|
|
|
|
txt = wx.StaticText(
|
|
|
|
self.panelA, -1,
|
|
|
|
"Resize the window and see\n"
|
|
|
|
"what happens... Notice that\n"
|
|
|
|
"there is no OnSize handler.",
|
|
|
|
(5,5), (-1, 50)
|
|
|
|
)
|
|
|
|
|
|
|
|
txt.SetBackgroundColour(wx.BLUE)
|
|
|
|
txt.SetForegroundColour(wx.WHITE)
|
|
|
|
|
|
|
|
lc = wx.LayoutConstraints()
|
|
|
|
lc.top.SameAs(self, wx.Top, 10)
|
|
|
|
lc.left.SameAs(self, wx.Left, 10)
|
|
|
|
lc.bottom.SameAs(self, wx.Bottom, 10)
|
|
|
|
lc.right.PercentOf(self, wx.Right, 50)
|
1999-04-30 03:29:54 +00:00
|
|
|
self.panelA.SetConstraints(lc)
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
self.panelB = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
|
|
|
|
self.panelB.SetBackgroundColour(wx.RED)
|
|
|
|
lc = wx.LayoutConstraints()
|
|
|
|
lc.top.SameAs(self, wx.Top, 10)
|
|
|
|
lc.right.SameAs(self, wx.Right, 10)
|
|
|
|
lc.bottom.PercentOf(self, wx.Bottom, 30)
|
1999-04-30 03:29:54 +00:00
|
|
|
lc.left.RightOf(self.panelA, 10)
|
|
|
|
self.panelB.SetConstraints(lc)
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
self.panelC = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
|
|
|
|
self.panelC.SetBackgroundColour(wx.WHITE)
|
|
|
|
lc = wx.LayoutConstraints()
|
1999-04-30 03:29:54 +00:00
|
|
|
lc.top.Below(self.panelB, 10)
|
2003-12-09 01:23:28 +00:00
|
|
|
lc.right.SameAs(self, wx.Right, 10)
|
|
|
|
lc.bottom.SameAs(self, wx.Bottom, 10)
|
1999-04-30 03:29:54 +00:00
|
|
|
lc.left.RightOf(self.panelA, 10)
|
|
|
|
self.panelC.SetConstraints(lc)
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
b = wx.Button(self.panelA, 100, ' Panel A ')
|
|
|
|
lc = wx.LayoutConstraints()
|
|
|
|
lc.centreX.SameAs (self.panelA, wx.CentreX)
|
|
|
|
lc.centreY.SameAs (self.panelA, wx.CentreY)
|
1999-04-30 03:29:54 +00:00
|
|
|
lc.height.AsIs ()
|
2003-12-09 01:23:28 +00:00
|
|
|
lc.width.PercentOf (self.panelA, wx.Width, 50)
|
2005-12-30 23:02:03 +00:00
|
|
|
b.SetConstraints(lc)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
b = wx.Button(self.panelB, 100, ' Panel B ')
|
|
|
|
lc = wx.LayoutConstraints()
|
|
|
|
lc.top.SameAs (self.panelB, wx.Top, 2)
|
|
|
|
lc.right.SameAs (self.panelB, wx.Right, 4)
|
1999-04-30 03:29:54 +00:00
|
|
|
lc.height.AsIs ()
|
|
|
|
lc.width.AsIs ()
|
2005-12-30 23:02:03 +00:00
|
|
|
b.SetConstraints(lc)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
self.panelD = wx.Window(self.panelC, -1, style=wx.SIMPLE_BORDER)
|
|
|
|
self.panelD.SetBackgroundColour(wx.GREEN)
|
|
|
|
wx.StaticText(
|
|
|
|
self.panelD, -1, "Panel D", (4, 4)
|
|
|
|
).SetBackgroundColour(wx.GREEN)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
b = wx.Button(self.panelC, 100, ' Panel C ')
|
|
|
|
lc = wx.LayoutConstraints()
|
1999-04-30 03:29:54 +00:00
|
|
|
lc.top.Below (self.panelD)
|
|
|
|
lc.left.RightOf (self.panelD)
|
|
|
|
lc.height.AsIs ()
|
|
|
|
lc.width.AsIs ()
|
2005-12-30 23:02:03 +00:00
|
|
|
b.SetConstraints(lc)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
lc = wx.LayoutConstraints()
|
|
|
|
lc.bottom.PercentOf (self.panelC, wx.Height, 50)
|
|
|
|
lc.right.PercentOf (self.panelC, wx.Width, 50)
|
|
|
|
lc.height.SameAs (b, wx.Height)
|
|
|
|
lc.width.SameAs (b, wx.Width)
|
2005-12-30 23:02:03 +00:00
|
|
|
self.panelD.SetConstraints(lc)
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def OnButton(self, event):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Bell()
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestLayoutConstraints(nb)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
overview = """\
|
|
|
|
<html><body>
|
2003-07-02 23:13:10 +00:00
|
|
|
Objects of this class can be associated with a window to define its
|
|
|
|
layout constraints, with respect to siblings or its parent.
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<p>The class consists of the following eight constraints of class
|
2003-07-02 23:13:10 +00:00
|
|
|
wxIndividualLayoutConstraint, some or all of which should be accessed
|
|
|
|
directly to set the appropriate constraints.
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<p><ul>
|
|
|
|
<li>left: represents the left hand edge of the window
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<li>right: represents the right hand edge of the window
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<li>top: represents the top edge of the window
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<li>bottom: represents the bottom edge of the window
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<li>width: represents the width of the window
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<li>height: represents the height of the window
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<li>centreX: represents the horizontal centre point of the window
|
1999-04-30 03:29:54 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<li>centreY: represents the vertical centre point of the window
|
|
|
|
</ul>
|
|
|
|
<p>Most constraints are initially set to have the relationship
|
2003-07-02 23:13:10 +00:00
|
|
|
wxUnconstrained, which means that their values should be calculated by
|
|
|
|
looking at known constraints. The exceptions are width and height,
|
|
|
|
which are set to wxAsIs to ensure that if the user does not specify a
|
|
|
|
constraint, the existing width and height will be used, to be
|
|
|
|
compatible with panel items which often have take a default size. If
|
|
|
|
the constraint is wxAsIs, the dimension will not be changed.
|
1999-04-30 03:29:54 +00:00
|
|
|
|
|
|
|
"""
|
2003-07-02 23:13:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-05 00:06:33 +00:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-07-02 23:13:10 +00:00
|
|
|
|