]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxLayoutConstraints.py
2 from wxPython
. wx
import *
4 #---------------------------------------------------------------------------
6 class TestLayoutConstraints ( wxWindow
):
7 def __init__ ( self
, parent
):
8 wxWindow
.__ init
__ ( self
, parent
, - 1 )
9 self
. SetBackgroundColour ( wxNamedColour ( "MEDIUM ORCHID" ))
11 self
. SetAutoLayout ( true
)
12 EVT_BUTTON ( self
, 100 , self
. OnButton
)
14 self
. panelA
= wxWindow ( self
, - 1 , wxDefaultPosition
, wxDefaultSize
,
16 self
. panelA
. SetBackgroundColour ( wxBLUE
)
17 txt
= wxStaticText ( self
. panelA
, - 1 ,
18 "Resize the window and see \n "
19 "what happens... Notice that \n "
20 "there is no OnSize handler." ,
21 wxPoint ( 5 , 5 ), wxSize (- 1 , 50 ))
22 txt
. SetBackgroundColour ( wxBLUE
)
23 txt
. SetForegroundColour ( wxWHITE
)
25 lc
= wxLayoutConstraints ()
26 lc
. top
. SameAs ( self
, wxTop
, 10 )
27 lc
. left
. SameAs ( self
, wxLeft
, 10 )
28 lc
. bottom
. SameAs ( self
, wxBottom
, 10 )
29 lc
. right
. PercentOf ( self
, wxRight
, 50 )
30 self
. panelA
. SetConstraints ( lc
)
32 self
. panelB
= wxWindow ( self
, - 1 , wxDefaultPosition
, wxDefaultSize
,
34 self
. panelB
. SetBackgroundColour ( wxRED
)
35 lc
= wxLayoutConstraints ()
36 lc
. top
. SameAs ( self
, wxTop
, 10 )
37 lc
. right
. SameAs ( self
, wxRight
, 10 )
38 lc
. bottom
. PercentOf ( self
, wxBottom
, 30 )
39 lc
. left
. RightOf ( self
. panelA
, 10 )
40 self
. panelB
. SetConstraints ( lc
)
42 self
. panelC
= wxWindow ( self
, - 1 , wxDefaultPosition
, wxDefaultSize
,
44 self
. panelC
. SetBackgroundColour ( wxWHITE
)
45 lc
= wxLayoutConstraints ()
46 lc
. top
. Below ( self
. panelB
, 10 )
47 lc
. right
. SameAs ( self
, wxRight
, 10 )
48 lc
. bottom
. SameAs ( self
, wxBottom
, 10 )
49 lc
. left
. RightOf ( self
. panelA
, 10 )
50 self
. panelC
. SetConstraints ( lc
)
52 b
= wxButton ( self
. panelA
, 100 , ' Panel A ' )
53 lc
= wxLayoutConstraints ()
54 lc
. centreX
. SameAs ( self
. panelA
, wxCentreX
)
55 lc
. centreY
. SameAs ( self
. panelA
, wxCentreY
)
57 lc
. width
. PercentOf ( self
. panelA
, wxWidth
, 50 )
60 b
= wxButton ( self
. panelB
, 100 , ' Panel B ' )
61 lc
= wxLayoutConstraints ()
62 lc
. top
. SameAs ( self
. panelB
, wxTop
, 2 )
63 lc
. right
. SameAs ( self
. panelB
, wxRight
, 4 )
68 self
. panelD
= wxWindow ( self
. panelC
, - 1 , wxDefaultPosition
, wxDefaultSize
,
70 self
. panelD
. SetBackgroundColour ( wxGREEN
)
71 wxStaticText ( self
. panelD
, - 1 , "Panel D" , wxPoint ( 4 , 4 )). SetBackgroundColour ( wxGREEN
)
73 b
= wxButton ( self
. panelC
, 100 , ' Panel C ' )
74 lc
= wxLayoutConstraints ()
75 lc
. top
. Below ( self
. panelD
)
76 lc
. left
. RightOf ( self
. panelD
)
81 lc
= wxLayoutConstraints ()
82 lc
. bottom
. PercentOf ( self
. panelC
, wxHeight
, 50 )
83 lc
. right
. PercentOf ( self
. panelC
, wxWidth
, 50 )
84 lc
. height
. SameAs ( b
, wxHeight
)
85 lc
. width
. SameAs ( b
, wxWidth
)
86 self
. panelD
. SetConstraints ( lc
);
89 def OnButton ( self
, event
):
93 #---------------------------------------------------------------------------
95 def runTest ( frame
, nb
, log
):
96 win
= TestLayoutConstraints ( nb
)
99 #---------------------------------------------------------------------------
116 Objects of this class can be associated with a window to define its layout constraints, with respect to siblings or its parent.
118 The class consists of the following eight constraints of class wxIndividualLayoutConstraint, some or all of which should be accessed directly to set the appropriate constraints.
120 left: represents the left hand edge of the window
122 right: represents the right hand edge of the window
124 top: represents the top edge of the window
126 bottom: represents the bottom edge of the window
128 width: represents the width of the window
130 height: represents the height of the window
132 centreX: represents the horizontal centre point of the window
134 centreY: represents the vertical centre point of the window
136 Most constraints are initially set to have the relationship 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.
138 wxLayoutConstraints()
139 -------------------------------------------