2 from wxPython
.wx
import *
3 from wxPython
.lib
.anchors
import LayoutAnchors
5 #----------------------------------------------------------------------
8 [wxID_ANCHORSDEMOFRAMEANCHOREDPANEL
, wxID_ANCHORSDEMOFRAMEHELPSTATICTEXT
,
9 wxID_ANCHORSDEMOFRAMEMAINPANEL
, wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL
,
10 wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX
, wxID_ANCHORSDEMOFRAMEOKBUTTON
,
11 wxID_ANCHORSDEMOFRAMETOPCHECKBOX
, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX
,
12 wxID_ANCHORSDEMOFRAME
, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX
,
13 ] = map(lambda _init_ctrls
: wxNewId(), range(10))
15 class AnchorsDemoFrame(wxFrame
):
16 def _init_utils(self
):
19 def _init_ctrls(self
, prnt
):
20 wxFrame
.__init
__(self
, size
= wxSize(328, 187), id = wxID_ANCHORSDEMOFRAME
, title
= 'LayoutAnchors Demonstration', parent
= prnt
, name
= 'AnchorsDemoFrame', style
= wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN
, pos
= wxPoint(261, 123))
23 self
.mainPanel
= wxPanel(size
= wxSize(320, 160), parent
= self
, id = wxID_ANCHORSDEMOFRAMEMAINPANEL
, name
= 'panel1', style
= wxTAB_TRAVERSAL | wxCLIP_CHILDREN
, pos
= wxPoint(0, 0))
24 self
.mainPanel
.SetAutoLayout(true
)
26 self
.okButton
= wxButton(label
= 'OK', id = wxID_ANCHORSDEMOFRAMEOKBUTTON
, parent
= self
.mainPanel
, name
= 'okButton', size
= wxSize(72, 24), style
= 0, pos
= wxPoint(240, 128))
27 self
.okButton
.SetConstraints(LayoutAnchors(self
.okButton
, false
, false
, true
, true
))
28 EVT_BUTTON(self
.okButton
, wxID_ANCHORSDEMOFRAMEOKBUTTON
, self
.OnOkButtonButton
)
30 self
.backgroundPanel
= wxPanel(size
= wxSize(304, 80), parent
= self
.mainPanel
, id = wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL
, name
= 'backgroundPanel', style
= wxSIMPLE_BORDER | wxCLIP_CHILDREN
, pos
= wxPoint(8, 40))
31 self
.backgroundPanel
.SetBackgroundColour(wxColour(255, 255, 255))
32 self
.backgroundPanel
.SetConstraints(LayoutAnchors(self
.backgroundPanel
, true
, true
, true
, true
))
34 self
.anchoredPanel
= wxPanel(size
= wxSize(88, 48), id = wxID_ANCHORSDEMOFRAMEANCHOREDPANEL
, parent
= self
.backgroundPanel
, name
= 'anchoredPanel', style
= wxSIMPLE_BORDER
, pos
= wxPoint(104, 16))
35 self
.anchoredPanel
.SetBackgroundColour(wxColour(0, 0, 222))
36 self
.anchoredPanel
.SetConstraints(LayoutAnchors(self
.anchoredPanel
, false
, false
, false
, false
))
38 self
.leftCheckBox
= wxCheckBox(label
= 'Left', id = wxID_ANCHORSDEMOFRAMELEFTCHECKBOX
, parent
= self
.mainPanel
, name
= 'leftCheckBox', size
= wxSize(40, 16), style
= 0, pos
= wxPoint(8, 8))
39 self
.leftCheckBox
.SetConstraints(LayoutAnchors(self
.leftCheckBox
, false
, true
, false
, false
))
40 EVT_CHECKBOX(self
.leftCheckBox
, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX
, self
.OnCheckboxCheckbox
)
42 self
.topCheckBox
= wxCheckBox(label
= 'Top', id = wxID_ANCHORSDEMOFRAMETOPCHECKBOX
, parent
= self
.mainPanel
, name
= 'topCheckBox', size
= wxSize(40, 16), style
= 0, pos
= wxPoint(88, 8))
43 self
.topCheckBox
.SetConstraints(LayoutAnchors(self
.topCheckBox
, false
, true
, false
, false
))
44 EVT_CHECKBOX(self
.topCheckBox
, wxID_ANCHORSDEMOFRAMETOPCHECKBOX
, self
.OnCheckboxCheckbox
)
46 self
.rightCheckBox
= wxCheckBox(label
= 'Right', id = wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX
, parent
= self
.mainPanel
, name
= 'rightCheckBox', size
= wxSize(48, 16), style
= 0, pos
= wxPoint(168, 8))
47 self
.rightCheckBox
.SetConstraints(LayoutAnchors(self
.rightCheckBox
, false
, true
, false
, false
))
48 EVT_CHECKBOX(self
.rightCheckBox
, wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX
, self
.OnCheckboxCheckbox
)
50 self
.bottomCheckBox
= wxCheckBox(label
= 'Bottom', id = wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX
, parent
= self
.mainPanel
, name
= 'bottomCheckBox', size
= wxSize(56, 16), style
= 0, pos
= wxPoint(248, 8))
51 self
.bottomCheckBox
.SetConstraints(LayoutAnchors(self
.bottomCheckBox
, false
, true
, false
, false
))
52 EVT_CHECKBOX(self
.bottomCheckBox
, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX
, self
.OnCheckboxCheckbox
)
54 self
.helpStaticText
= wxStaticText(label
= 'Select anchor options above, then resize window to see the effect', id = wxID_ANCHORSDEMOFRAMEHELPSTATICTEXT
, parent
= self
.mainPanel
, name
= 'helpStaticText', size
= wxSize(224, 24), style
= wxST_NO_AUTORESIZE
, pos
= wxPoint(8, 128))
55 self
.helpStaticText
.SetConstraints(LayoutAnchors(self
.helpStaticText
, true
, false
, true
, true
))
57 def __init__(self
, parent
):
58 self
._init
_ctrls
(parent
)
60 def OnCheckboxCheckbox(self
, event
):
61 self
.anchoredPanel
.SetConstraints(
62 LayoutAnchors(self
.anchoredPanel
,
63 self
.leftCheckBox
.GetValue(), self
.topCheckBox
.GetValue(),
64 self
.rightCheckBox
.GetValue(), self
.bottomCheckBox
.GetValue()) )
66 def OnOkButtonButton(self
, event
):
69 #----------------------------------------------------------------------
71 def runTest(frame
, nb
, log
):
72 win
= AnchorsDemoFrame(frame
)
79 #----------------------------------------------------------------------
84 overview
= """<html><body>
85 <h2>LayoutAnchors</h2>
86 A class that implements Delphi's Anchors with wxLayoutConstraints.
88 Anchored sides maintain the distance from the edge of the
89 control to the same edge of the parent.
90 When neither side is selected, the control keeps the same
91 relative position to both sides.
93 The current position and size of the control and it's parent
94 is used when setting up the constraints. To change the size or
95 position of an already anchored control, set the constraints to
96 None, reposition or resize and reapply the anchors.
100 Let's anchor the right and bottom edge of a control and
104 ctrl.SetConstraints(LayoutAnchors(ctrl, left=0, top=0, right=1, bottom=1))
106 +=========+ +===================+
109 | +--*--+ | | +-----+ |
112 +-------------------+
116 When anchored on both sides the control will stretch horizontally.
119 ctrl.SetConstraints(LayoutAnchors(ctrl, 1, 0, 1, 1))
121 +=========+ +===================+
124 | +--*--+ | | +---------------+ |
125 +---------+ | * ctrl * |
126 | +-------*-------+ |
127 +-------------------+