]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/lib/sizers/box.py
1 #----------------------------------------------------------------------
2 # Name: wxPython.lib.sizers.box
3 # Purpose: A sizer/layout managers for wxPython that places items in
6 # Author: Robin Dunn and Dirk Holtwick
10 # Copyright: (c) 1998 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------
14 from sizer
import wxSizer
15 from wxPython
.wx
import wxVERTICAL
, wxHORIZONTAL
17 #----------------------------------------------------------------------
20 class wxBoxSizer(wxSizer
):
24 A Sizer that lays components out in a box, in the order they are
25 added to the layout manager, with a given orientation. The
26 orientation is specified in the constructor with either wxVERTICAL
29 The optional parameter to the Add method (for this sizer it's
30 called the stretch flag) can be used to flag one or more components
31 as stretchable, meaning that they will expand to fill available
32 space in the given orientation. The default is zero, or not
35 If the stretch flag is non-zero then the widget will stretch. If
36 the sizer holds more than one item that is stretchable then they
37 share the available space.
39 If the strech flag is greater than 1 then it serves as a weighting
40 factor. Widgets with a flag of 2 will get twice as much space as
43 def __init__(self
, orientation
, size
= None):
44 wxSizer
.__init
__(self
, size
)
45 self
.orientation
= orientation
49 self
.stretchable
= 0 # number of stretchable items
50 self
.minWidth
= 0 # minimal size
52 self
.fixedWidth
= 0 # size without stretched widgets
55 # iterate through children
56 for (isSizer
, widget
, width
, height
, stretch
) in self
.children
:
62 # let sub-sizers recalc their required space
63 width
, height
= widget
.CalcMin()
66 if self
.orientation
== wxVERTICAL
:
67 self
.minHeight
= self
.minHeight
+ (height
* weight
)
68 self
.minWidth
= max(self
.minWidth
, width
)
70 self
.minWidth
= self
.minWidth
+ (width
* weight
)
71 self
.minHeight
= max(self
.minHeight
, height
)
75 self
.stretchable
= self
.stretchable
+ weight
77 if self
.orientation
== wxVERTICAL
:
78 self
.fixedHeight
= self
.fixedHeight
+ height
79 self
.fixedWidth
= max(self
.fixedWidth
, width
)
81 self
.fixedWidth
= self
.fixedWidth
+ width
82 self
.fixedHeight
= max(self
.fixedHeight
, height
)
84 return self
.minWidth
, self
.minHeight
88 def RecalcSizes(self
):
89 # get current dimensions, for performance
90 myWidth
= self
.size
.width
91 myHeight
= self
.size
.height
93 # relative recent positions & sizes
99 # calculate space for one stretched item
101 if self
.orientation
== wxHORIZONTAL
:
102 delta
= (myWidth
- self
.fixedWidth
) / self
.stretchable
103 extra
= (myWidth
- self
.fixedWidth
) % self
.stretchable
105 delta
= (myHeight
- self
.fixedHeight
) / self
.stretchable
106 extra
= (myHeight
- self
.fixedHeight
) % self
.stretchable
108 # iterate children ...
109 for (isSizer
, widget
, width
, height
, stretch
) in self
.children
:
115 width
, height
= widget
.CalcMin()
118 if self
.orientation
== wxVERTICAL
:
121 newHeight
= (delta
* weight
) + extra
# first stretchable gets extra pixels
123 widget
.SetDimensions(px
, py
, myWidth
, newHeight
)
126 elif self
.orientation
== wxHORIZONTAL
:
129 newWidth
= (delta
* weight
) + extra
# first stretchable gets extra pixels
131 widget
.SetDimensions(px
, py
, newWidth
, myHeight
)
137 #----------------------------------------------------------------------