]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/lib/sizers/sizer.py
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 if type(childinfo
) != type(()):
59 childinfo
= (childinfo
, )
60 apply(self
.Add
, childinfo
)
63 def SetDimensions(self
, x
, y
, width
, height
):
64 self
.origin
= wxPoint(x
, y
)
65 self
.size
= wxSize(width
, height
)
71 def GetPosition(self
):
75 raise NotImplementedError("Derived class should implement CalcMin")
77 def RecalcSizes(self
):
78 raise NotImplementedError("Derived class should implement RecalcSizes")
82 def __getMinWindowSize(self
, win
):
84 Calculate the best size window to hold this sizer, taking into
85 account the difference between client size and window size.
87 min = self
.GetMinSize()
88 a1
,a2
= win
.GetSizeTuple()
89 b1
,b2
= win
.GetClientSizeTuple()
90 w
= min.width
+ (a1
- b1
)
91 h
= min.height
+ (a2
- b2
)
96 minWidth
, minHeight
= self
.CalcMin()
97 return wxSize(minWidth
, minHeight
)
99 def SetWindowSizeHints(self
, win
):
100 w
, h
= self
.__getMinWindowSize
(win
)
101 win
.SetSizeHints(w
,h
)
103 def FitWindow(self
, win
):
104 w
, h
= self
.__getMinWindowSize
(win
)
105 win
.SetSize(wxSize(w
,h
))
107 def Layout(self
, size
):
109 self
.SetDimensions(self
.origin
.x
, self
.origin
.y
,
110 size
.width
, size
.height
)
112 #----------------------------------------------------------------------