]>
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 #---------------------------------------------------------------------- 
  13 # 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net) 
  15 # o Updated for wx namespace 
  16 # o Tested with updated demo 
  21 class LayoutAnchors(wx
.LayoutConstraints
): 
  22     """ A class that implements Delphi's Anchors with wx.LayoutConstraints. 
  24         Anchored sides maintain the distance from the edge of the 
  25         control to the same edge of the parent. 
  26         When neither side is selected, the control keeps the same 
  27         relative position to both sides. 
  29         The current position and size of the control and it's parent 
  30         is used when setting up the constraints. To change the size or 
  31         position of an already anchored control, set the constraints to 
  32         None, reposition or resize and reapply the anchors. 
  36         Let's anchor the right and bottom edge of a control and 
  39         ctrl.SetConstraints(LayoutAnchors(ctrl, left=0, top=0, right=1, bottom=1)) 
  41         +=========+         +===================+ 
  44         | +--*--+ |         |           +-----+ | 
  50         When anchored on both sides the control will stretch horizontally. 
  52         ctrl.SetConstraints(LayoutAnchors(ctrl, 1, 0, 1, 1)) 
  54         +=========+         +===================+ 
  57         | +--*--+ |         | +---------------+ | 
  58         +---------+         | *     ctrl      * | 
  63     def __init__(self
, control
, left
=1, top
=1, right
=0, bottom
=0): 
  64         wx
.LayoutConstraints
.__init
__(self
) 
  65         parent 
= control
.GetParent() 
  68         pPos
, pSize 
= parent
.GetPosition(), parent
.GetClientSize() 
  69         cPos
, cSize 
= control
.GetPosition(), control
.GetSize() 
  71         self
.setConstraintSides(self
.left
, wx
.Left
, left
, 
  72                                 self
.right
, wx
.Right
, right
, 
  73                                 self
.width
, wx
.Width
, self
.centreX
, 
  74                                 cPos
.x
, cSize
.width
, pSize
.width
, parent
) 
  76         self
.setConstraintSides(self
.top
, wx
.Top
, top
, 
  77                                 self
.bottom
, wx
.Bottom
, bottom
, 
  78                                 self
.height
, wx
.Height
, self
.centreY
, 
  79                                 cPos
.y
, cSize
.height
, pSize
.height
, parent
) 
  81     def setConstraintSides(self
, side1
, side1Edge
, side1Anchor
, 
  82                                  side2
, side2Edge
, side2Anchor
, 
  83                                  size
, sizeEdge
, centre
, 
  84                                  cPos
, cSize
, pSize
, parent
): 
  86             side2
.SameAs(parent
, side2Edge
, pSize 
- (cPos 
+ cSize
)) 
  89             side1
.SameAs(parent
, side1Edge
, cPos
) 
  97                 centre
.PercentOf(parent
, sizeEdge
, 
  98                                  int(((cPos 
+ cSize 
/ 2.0) / pSize
)*100))