]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/anchors.py
1 #----------------------------------------------------------------------
2 # Name: wxPython.lib.anchors
3 # Purpose: A class that provides an easy to use interface over layout
4 # constraints for anchored layout.
6 # Author: Riaan Booysen
10 # Copyright: (c) 2000 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------
14 from wxPython
.wx
import wxLayoutConstraints
, wxTop
, wxLeft
, wxBottom
, wxRight
, \
17 class LayoutAnchors(wxLayoutConstraints
):
18 """ A class that implements Delphi's Anchors with wxLayoutConstraints.
20 Anchored sides maintain the distance from the edge of the
21 control to the same edge of the parent.
22 When neither side is selected, the control keeps the same
23 relative position to both sides.
25 The current position and size of the control and it's parent
26 is used when setting up the constraints. To change the size or
27 position of an already anchored control, set the constraints to
28 None, reposition or resize and reapply the anchors.
32 Let's anchor the right and bottom edge of a control and
35 ctrl.SetConstraints(LayoutAnchors(ctrl, left=0, top=0, right=1, bottom=1))
37 +=========+ +===================+
40 | +--*--+ | | +-----+ |
46 When anchored on both sides the control will stretch horizontally.
48 ctrl.SetConstraints(LayoutAnchors(ctrl, 1, 0, 1, 1))
50 +=========+ +===================+
53 | +--*--+ | | +---------------+ |
54 +---------+ | * ctrl * |
59 def __init__(self
, control
, left
= 1, top
= 1, right
= 0, bottom
= 0):
60 wxLayoutConstraints
.__init
__(self
)
61 parent
= control
.GetParent()
64 pPos
, pSize
= parent
.GetPosition(), parent
.GetClientSize()
65 cPos
, cSize
= control
.GetPosition(), control
.GetSize()
67 self
.setConstraintSides(self
.left
, wxLeft
, left
,
68 self
.right
, wxRight
, right
,
69 self
.width
, wxWidth
, self
.centreX
,
70 cPos
.x
, cSize
.width
, pSize
.width
, parent
)
72 self
.setConstraintSides(self
.top
, wxTop
, top
,
73 self
.bottom
, wxBottom
, bottom
,
74 self
.height
, wxHeight
, self
.centreY
,
75 cPos
.y
, cSize
.height
, pSize
.height
, parent
)
77 def setConstraintSides(self
, side1
, side1Edge
, side1Anchor
,
78 side2
, side2Edge
, side2Anchor
,
79 size
, sizeEdge
, centre
,
80 cPos
, cSize
, pSize
, parent
):
82 side2
.SameAs(parent
, side2Edge
, pSize
- (cPos
+ cSize
))
84 side1
.SameAs(parent
, side1Edge
, cPos
)
90 centre
.PercentOf(parent
, sizeEdge
,
91 int(((cPos
+ cSize
/ 2.0) / pSize
)*100))