2
__version__ = "$Revision: 1.2 $"
3
__date__ = "$Date: 2005/10/12 22:27:39 $"
7
Simple sizer for PythonCard
9
Uses a simple method for sizing:
10
- each component type is defined to be fixed or stretchable
11
- uses GetBestSize() to get a min size for each component
12
- each component is placed by its centre point as laid out
13
- centre locations are scaled by "current window size / min size"
15
This will adjust component sizes for differences between OS's, but will
16
not move components to make space.
24
#----------------------------------------------------------------------
26
class simpleSizer(wx.PySizer):
27
def __init__(self, minsize, border=0):
28
wx.PySizer.__init__(self)
29
self.minsize = minsize
32
#--------------------------------------------------
33
def Add(self, item, option=0, flag=0, border=0,
35
growX = False, growY = False
38
if DEBUG: print "adding", item.name, pos, size, growX, growY
40
wx.PySizer.Add(self, item, option, flag, border,
41
userData=(pos, size, growX, growY))
43
#--------------------------------------------------
48
#--------------------------------------------------
49
def RecalcSizes( self ):
50
# save current dimensions, etc.
51
curWidth, curHeight = self.GetSize()
52
px, py = self.GetPosition()
53
minWidth, minHeight = self.CalcMin()
54
if DEBUG: print minWidth, minHeight, curWidth, curHeight
56
if minWidth == 0 or minHeight == 0: return
58
scaleX = 100 * curWidth / minWidth
59
scaleY = 100 * curHeight / minHeight
61
# iterate children and set dimensions...
62
for item in self.GetChildren():
63
pos, size, growX, growY = item.GetUserData()
64
if DEBUG: print "in recalc", pos, size, growX, growY
67
cx = (cx * scaleX + sx*scaleX/2) / 100
68
cy = (cy * scaleY + sy*scaleY/2) / 100
71
sx = sx * scaleX / 100
73
sy = sy * scaleY / 100
75
self.SetItemBounds( item, cx-sx/2, cy-sy/2, sx, sy )
77
#--------------------------------------------------
78
def SetItemBounds(self, item, x, y, w, h):
79
# calculate the item's actual size and position within
83
if DEBUG: print "in itembounds", x,y,w,h
85
item.SetDimension(ipt, isz)
86
#--------------------------------------------------
91
heightGrowableTypes = ["BitmapCanvas", "CodeEditor", "HtmlWindow", \
92
"Image", "List", "MultiColumnList",
94
"RadioGroup", "StaticBox", "TextArea", \
96
widthGrowableTypes = ["BitmapCanvas", "CheckBox", "Choice", \
97
"CodeEditor", "ComboBox", "HtmlWindow", \
98
"Image", "List", "MultiColumnList", \
100
"PasswordField", "RadioGroup", "Spinner", \
101
"StaticBox", "StaticText", "TextArea", \
103
growableTypes = ["Gauge", "Slider", "StaticLine"]
106
winX, winY = aBg.size
107
# make list of all components, make a simpleSizer to hold them
109
for compName in aBg.components.iterkeys():
110
comp = aBg.components[compName]
111
complist.append( comp )
113
sizer = simpleSizer(aBg.panel.size)
115
# add the components to the grid
116
for comp in complist:
117
tx, ty = comp.position
120
# AGT Must be an easier way to get a component's type ??
121
compType = comp._resource.__dict__['type']
123
dx1, dy1 = comp.GetBestSize()
124
if dx1 > dx: dx = dx1
126
# hack to deal with the fact that GetBestSize() comes up with too
127
# large heights for textareas.
128
if compType <> "TextArea": dy = dy1
130
# AGT FUTURE this checks contents of the component's userdata
131
# extend resourceEditor to allow a way to set this
132
if "HEIGHT_GROWABLE" in comp.userdata or \
133
compType in heightGrowableTypes or \
134
(compType in growableTypes and comp.layout == "vertical"):
136
else: compGrowableY = False
137
if "WIDTH_GROWABLE" in comp.userdata or \
138
compType in widthGrowableTypes or \
139
(compType in growableTypes and comp.layout == "horizontal"):
141
else: compGrowableX = False
143
sizer.Add(comp, pos=(tx,ty), size=(dx,dy), growX = compGrowableX, growY = compGrowableY )
144
if DEBUG1: print "adding ", comp.name, (tx, ty), (dx, dy), compGrowableX, compGrowableY
146
sizer.SetSizeHints(aBg)
147
aBg.panel.SetSizer(sizer)
148
aBg.panel.SetAutoLayout(1)
150
#--------------------------------------------------