~toolpart/+junk/pythoncard

« back to all changes in this revision

Viewing changes to simpleSizer.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-03-04 23:55:10 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100304235510-3v6lbhzwrgm0pcca
Tags: 0.8.2-1
* QA upload.
* New upstream release
* debian/control
  - set maintainer to QA group
  - set Homepage field, removing the URL from packages description
  - bump versioned b-d-i on python-support, to properly support Python module
  - replace b-d on python-all-dev with python-all, since building only
    arch:all packages
  - replace Source-Version substvar with source:Version
  - add ${misc:Depends} to binary packages Depends
* debian/watch
  - updated to use the SourceForge redirector; thanks to Raphael Geissert for
    the report and to Dario Minnucci for the patch; Closes: #449904
* debian/{pythoncard-doc, python-pythoncard}.install
  - use wildcards instead of site-packages to fix build with python 2.6;
    thanks to Ilya Barygin for the report and patch; Closes: #572332
* debian/pythoncard-doc.doc-base
  - set section to Programmin/Python
* debian/pythoncard-tools.menu
  - set menu main section to Applications
* debian/pythoncard-tools.postinst
  - removed, needed only to update the menu, but it's now created by debhelper

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
__version__ = "$Revision: 1.2 $"
 
3
__date__ = "$Date: 2005/10/12 22:27:39 $"
 
4
"""
 
5
 
 
6
"""
 
7
Simple sizer for PythonCard
 
8
 
 
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"
 
14
    
 
15
This will adjust component sizes for differences between OS's, but will
 
16
not move components to make space.
 
17
"""
 
18
 
 
19
import wx
 
20
 
 
21
DEBUG = False
 
22
DEBUG1 = False
 
23
 
 
24
#----------------------------------------------------------------------
 
25
 
 
26
class simpleSizer(wx.PySizer):
 
27
    def __init__(self, minsize, border=0):
 
28
        wx.PySizer.__init__(self)
 
29
        self.minsize = minsize
 
30
        self.border = border
 
31
        
 
32
    #--------------------------------------------------
 
33
    def Add(self, item, option=0, flag=0, border=0,
 
34
            pos=None, size=None,  
 
35
            growX = False, growY = False
 
36
            ):
 
37
 
 
38
        if DEBUG: print "adding", item.name, pos, size, growX, growY
 
39
 
 
40
        wx.PySizer.Add(self, item, option, flag, border,
 
41
                       userData=(pos, size, growX, growY))
 
42
 
 
43
    #--------------------------------------------------
 
44
    def CalcMin( self ):
 
45
        x,y = self.minsize
 
46
        return wx.Size(x, y)
 
47
        
 
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
 
55
 
 
56
        if minWidth == 0 or minHeight == 0: return
 
57
        
 
58
        scaleX = 100 * curWidth / minWidth
 
59
        scaleY = 100 * curHeight / minHeight
 
60
            
 
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
 
65
            cx,cy = pos
 
66
            sx,sy = size
 
67
            cx = (cx * scaleX + sx*scaleX/2) / 100
 
68
            cy = (cy * scaleY + sy*scaleY/2) / 100
 
69
            
 
70
            if growX: 
 
71
                sx = sx * scaleX / 100
 
72
            if growY: 
 
73
                sy = sy * scaleY / 100
 
74
                
 
75
            self.SetItemBounds( item, cx-sx/2, cy-sy/2, sx, sy )
 
76
 
 
77
    #--------------------------------------------------
 
78
    def SetItemBounds(self, item, x, y, w, h):
 
79
        # calculate the item's actual size and position within
 
80
        # its grid cell
 
81
        ipt = wx.Point(x, y)
 
82
        isz = wx.Size(w,h)
 
83
        if DEBUG: print "in itembounds", x,y,w,h
 
84
            
 
85
        item.SetDimension(ipt, isz)
 
86
#--------------------------------------------------
 
87
 
 
88
 
 
89
 
 
90
# AGT fill this list
 
91
heightGrowableTypes = ["BitmapCanvas", "CodeEditor", "HtmlWindow", \
 
92
                       "Image", "List", "MultiColumnList", 
 
93
                       "Notebook", \
 
94
                       "RadioGroup", "StaticBox", "TextArea", \
 
95
                       "Tree"]
 
96
widthGrowableTypes = ["BitmapCanvas", "CheckBox", "Choice", \
 
97
                      "CodeEditor", "ComboBox", "HtmlWindow", \
 
98
                      "Image", "List", "MultiColumnList", \
 
99
                      "Notebook", \
 
100
                      "PasswordField", "RadioGroup", "Spinner", \
 
101
                      "StaticBox", "StaticText", "TextArea", \
 
102
                      "TextField", "Tree"]
 
103
growableTypes = ["Gauge", "Slider", "StaticLine"]  
 
104
 
 
105
def autoSizer(aBg):
 
106
    winX, winY = aBg.size
 
107
    # make list of all components, make a simpleSizer to hold them
 
108
    complist = []
 
109
    for compName in aBg.components.iterkeys():
 
110
        comp = aBg.components[compName]
 
111
        complist.append( comp )
 
112
 
 
113
    sizer = simpleSizer(aBg.panel.size)
 
114
    
 
115
    # add the components to the grid
 
116
    for comp in complist:
 
117
        tx, ty = comp.position
 
118
        dx, dy = comp.size
 
119
        
 
120
        # AGT Must be an easier way to get a component's type ??
 
121
        compType = comp._resource.__dict__['type']
 
122
 
 
123
        dx1, dy1 = comp.GetBestSize()
 
124
        if dx1 > dx: dx = dx1
 
125
        if dy1 > dy: 
 
126
            # hack to deal with the fact that GetBestSize() comes up with too 
 
127
            #  large heights for textareas.
 
128
            if compType <> "TextArea": dy = dy1
 
129
 
 
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"):
 
135
                compGrowableY = True
 
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"):
 
140
                compGrowableX = True
 
141
        else: compGrowableX = False
 
142
 
 
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
 
145
            
 
146
    sizer.SetSizeHints(aBg)
 
147
    aBg.panel.SetSizer(sizer)
 
148
    aBg.panel.SetAutoLayout(1)
 
149
    aBg.panel.Layout()
 
150
#--------------------------------------------------