/usr/lib/python2.7/dist-packages/PythonCard/simpleSizer.py is in python-pythoncard 0.8.2-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | """
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2005/10/12 22:27:39 $"
"""
"""
Simple sizer for PythonCard
Uses a simple method for sizing:
- each component type is defined to be fixed or stretchable
- uses GetBestSize() to get a min size for each component
- each component is placed by its centre point as laid out
- centre locations are scaled by "current window size / min size"
This will adjust component sizes for differences between OS's, but will
not move components to make space.
"""
import wx
DEBUG = False
DEBUG1 = False
#----------------------------------------------------------------------
class simpleSizer(wx.PySizer):
def __init__(self, minsize, border=0):
wx.PySizer.__init__(self)
self.minsize = minsize
self.border = border
#--------------------------------------------------
def Add(self, item, option=0, flag=0, border=0,
pos=None, size=None,
growX = False, growY = False
):
if DEBUG: print "adding", item.name, pos, size, growX, growY
wx.PySizer.Add(self, item, option, flag, border,
userData=(pos, size, growX, growY))
#--------------------------------------------------
def CalcMin( self ):
x,y = self.minsize
return wx.Size(x, y)
#--------------------------------------------------
def RecalcSizes( self ):
# save current dimensions, etc.
curWidth, curHeight = self.GetSize()
px, py = self.GetPosition()
minWidth, minHeight = self.CalcMin()
if DEBUG: print minWidth, minHeight, curWidth, curHeight
if minWidth == 0 or minHeight == 0: return
scaleX = 100 * curWidth / minWidth
scaleY = 100 * curHeight / minHeight
# iterate children and set dimensions...
for item in self.GetChildren():
pos, size, growX, growY = item.GetUserData()
if DEBUG: print "in recalc", pos, size, growX, growY
cx,cy = pos
sx,sy = size
cx = (cx * scaleX + sx*scaleX/2) / 100
cy = (cy * scaleY + sy*scaleY/2) / 100
if growX:
sx = sx * scaleX / 100
if growY:
sy = sy * scaleY / 100
self.SetItemBounds( item, cx-sx/2, cy-sy/2, sx, sy )
#--------------------------------------------------
def SetItemBounds(self, item, x, y, w, h):
# calculate the item's actual size and position within
# its grid cell
ipt = wx.Point(x, y)
isz = wx.Size(w,h)
if DEBUG: print "in itembounds", x,y,w,h
item.SetDimension(ipt, isz)
#--------------------------------------------------
# AGT fill this list
heightGrowableTypes = ["BitmapCanvas", "CodeEditor", "HtmlWindow", \
"Image", "List", "MultiColumnList",
"Notebook", \
"RadioGroup", "StaticBox", "TextArea", \
"Tree"]
widthGrowableTypes = ["BitmapCanvas", "CheckBox", "Choice", \
"CodeEditor", "ComboBox", "HtmlWindow", \
"Image", "List", "MultiColumnList", \
"Notebook", \
"PasswordField", "RadioGroup", "Spinner", \
"StaticBox", "StaticText", "TextArea", \
"TextField", "Tree"]
growableTypes = ["Gauge", "Slider", "StaticLine"]
def autoSizer(aBg):
winX, winY = aBg.size
# make list of all components, make a simpleSizer to hold them
complist = []
for compName in aBg.components.iterkeys():
comp = aBg.components[compName]
complist.append( comp )
sizer = simpleSizer(aBg.panel.size)
# add the components to the grid
for comp in complist:
tx, ty = comp.position
dx, dy = comp.size
# AGT Must be an easier way to get a component's type ??
compType = comp._resource.__dict__['type']
dx1, dy1 = comp.GetBestSize()
if dx1 > dx: dx = dx1
if dy1 > dy:
# hack to deal with the fact that GetBestSize() comes up with too
# large heights for textareas.
if compType <> "TextArea": dy = dy1
# AGT FUTURE this checks contents of the component's userdata
# extend resourceEditor to allow a way to set this
if "HEIGHT_GROWABLE" in comp.userdata or \
compType in heightGrowableTypes or \
(compType in growableTypes and comp.layout == "vertical"):
compGrowableY = True
else: compGrowableY = False
if "WIDTH_GROWABLE" in comp.userdata or \
compType in widthGrowableTypes or \
(compType in growableTypes and comp.layout == "horizontal"):
compGrowableX = True
else: compGrowableX = False
sizer.Add(comp, pos=(tx,ty), size=(dx,dy), growX = compGrowableX, growY = compGrowableY )
if DEBUG1: print "adding ", comp.name, (tx, ty), (dx, dy), compGrowableX, compGrowableY
sizer.SetSizeHints(aBg)
aBg.panel.SetSizer(sizer)
aBg.panel.SetAutoLayout(1)
aBg.panel.Layout()
#--------------------------------------------------
|