]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/lib/sizers/sizer.py
88814262acc59299c7e0be5b621a0f3437114b89
1 #----------------------------------------------------------------------
2 # Name: wxPython.lib.sizers.sizer
3 # Purpose: General purpose sizer/layout managers for wxPython
5 # Author: Robin Dunn and Dirk Holtwick
9 # Copyright: (c) 1998 by Total Control Software
10 # Licence: wxWindows license
11 #----------------------------------------------------------------------
13 from wxPython
.wx
import wxPoint
, wxSize
15 #----------------------------------------------------------------------
21 An abstract base sizer class. A sizer is able to manage the size and
22 layout of windows and/or child sizers.
24 Derived classes should implement CalcMin, and RecalcSizes.
26 A window or sizer is added to this sizer with the Add method:
28 def Add(self, widget, opt=0)
30 The meaning of the opt parameter is different for each type of
31 sizer. It may be a single value or a collection of values.
33 def __init__(self
, size
= None):
35 self
.origin
= wxPoint(0, 0)
40 def Add(self
, widget
, opt
=0):
42 Add a window or a sizer to this sizer. The meaning of the opt
43 parameter is different for each type of sizer. It may be a single
44 value or a collection of values.
46 size
= widget
.GetSize()
47 isSizer
= isinstance(widget
, wxSizer
)
48 self
.children
.append( (isSizer
, widget
, size
.width
, size
.height
, opt
) )
51 def AddMany(self
, widgets
):
53 Add a sequence (list, tuple, etc.) of widgets to this sizer. The
54 items in the sequence should be tuples containing valid args for
57 for childinfo
in widgets
:
58 apply(self
.Add
, childinfo
)
61 def SetDimensions(self
, x
, y
, width
, height
):
62 self
.origin
= wxPoint(x
, y
)
63 self
.size
= wxSize(width
, height
)
69 def GetPosition(self
):
73 raise NotImplementedError("Derived class should implement CalcMin")
75 def RecalcSizes(self
):
76 raise NotImplementedError("Derived class should implement RecalcSizes")
80 def __getMinWindowSize(self
, win
):
82 Calculate the best size window to hold this sizer, taking into
83 account the difference between client size and window size.
85 min = self
.GetMinSize()
86 a1
,a2
= win
.GetSizeTuple()
87 b1
,b2
= win
.GetClientSizeTuple()
88 w
= min.width
+ (a1
- b1
)
89 h
= min.height
+ (a2
- b2
)
94 minWidth
, minHeight
= self
.CalcMin()
95 return wxSize(minWidth
, minHeight
)
97 def SetWindowSizeHints(self
, win
):
98 w
, h
= self
.__getMinWindowSize
(win
)
101 def FitWindow(self
, win
):
102 w
, h
= self
.__getMinWindowSize
(win
)
103 win
.SetSize(wxSize(w
,h
))
105 def Layout(self
, size
):
107 self
.SetDimensions(self
.origin
.x
, self
.origin
.y
,
108 size
.width
, size
.height
)
110 #----------------------------------------------------------------------