home *** CD-ROM | disk | FTP | other *** search
/ LG Super CD / LG Super CD.iso / bitpim / bitpim-0.62-setup.exe / {app} / bitpim.exe / wxPython / lib / rcsizer.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2003-11-06  |  5.5 KB  |  145 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.3)
  3.  
  4. from wxPython.wx import *
  5. import operator
  6.  
  7. class RowColSizer(wxPySizer):
  8.     col_w = 10
  9.     row_h = 22
  10.     
  11.     def __init__(self):
  12.         wxPySizer.__init__(self)
  13.         self.growableRows = []
  14.         self.growableCols = []
  15.  
  16.     
  17.     def AddGrowableRow(self, idx):
  18.         self.growableRows.append(idx)
  19.  
  20.     
  21.     def AddGrowableCol(self, idx):
  22.         self.growableCols.append(idx)
  23.  
  24.     
  25.     def Add(self, item, option = 0, flag = 0, border = 0, row = -1, col = -1, rowspan = 1, colspan = 1, pos = None, size = None):
  26.         if pos is not None:
  27.             (row, col) = pos
  28.         
  29.         if size is not None:
  30.             (rowspan, colspan) = size
  31.         
  32.         wxPySizer.Add(self, item, option, flag, border, userData = (row, col, row + rowspan, col + colspan))
  33.  
  34.     
  35.     def AddSpacer(self, width, height, option = 0, flag = 0, border = 0, row = -1, col = -1, rowspan = 1, colspan = 1, pos = None, size = None):
  36.         if pos is not None:
  37.             (row, col) = pos
  38.         
  39.         if size is not None:
  40.             (rowspan, colspan) = size
  41.         
  42.         wxPySizer.AddSpacer(self, width, height, option, flag, border, userData = (row, col, row + rowspan, col + colspan))
  43.  
  44.     
  45.     def _add(self, size, dim):
  46.         (r, c, r2, c2) = dim
  47.         if r2 > len(self.rowHeights):
  48.             x = [
  49.                 self.row_h] * (r2 - len(self.rowHeights))
  50.             self.rowHeights.extend(x)
  51.         
  52.         if c2 > len(self.colWidths):
  53.             x = [
  54.                 self.col_w] * (c2 - len(self.colWidths))
  55.             self.colWidths.extend(x)
  56.         
  57.         scale = r2 - r
  58.         for i in range(r, r2):
  59.             self.rowHeights[i] = max(self.rowHeights[i], size.height / scale)
  60.         
  61.         scale = c2 - c
  62.         for i in range(c, c2):
  63.             self.colWidths[i] = max(self.colWidths[i], size.width / scale)
  64.         
  65.  
  66.     
  67.     def CalcMin(self):
  68.         self.rowHeights = []
  69.         self.colWidths = []
  70.         items = self.GetChildren()
  71.         if not items:
  72.             return wxSize(10, 10)
  73.         
  74.         for item in items:
  75.             self._add(item.CalcMin(), item.GetUserData())
  76.         
  77.         size = wxSize(reduce(operator.add, self.colWidths), reduce(operator.add, self.rowHeights))
  78.         return size
  79.  
  80.     
  81.     def RecalcSizes(self):
  82.         curWidth = self.GetSize().width
  83.         curHeight = self.GetSize().height
  84.         px = self.GetPosition().x
  85.         py = self.GetPosition().y
  86.         minWidth = self.CalcMin().width
  87.         minHeight = self.CalcMin().height
  88.         if self.growableRows and curHeight > minHeight:
  89.             delta = (curHeight - minHeight) / len(self.growableRows)
  90.             extra = (curHeight - minHeight) % len(self.growableRows)
  91.             for idx in self.growableRows:
  92.                 self.rowHeights[idx] += delta
  93.             
  94.             self.rowHeights[self.growableRows[0]] += extra
  95.         
  96.         if self.growableCols and curWidth > minWidth:
  97.             delta = (curWidth - minWidth) / len(self.growableCols)
  98.             extra = (curWidth - minWidth) % len(self.growableCols)
  99.             for idx in self.growableCols:
  100.                 self.colWidths[idx] += delta
  101.             
  102.             self.colWidths[self.growableCols[0]] += extra
  103.         
  104.         rpos = [
  105.             0] * len(self.rowHeights)
  106.         cpos = [
  107.             0] * len(self.colWidths)
  108.         for i in range(len(self.rowHeights)):
  109.             height = self.rowHeights[i]
  110.             rpos[i] = py
  111.             py += height
  112.         
  113.         for i in range(len(self.colWidths)):
  114.             width = self.colWidths[i]
  115.             cpos[i] = px
  116.             px += width
  117.         
  118.         for item in self.GetChildren():
  119.             (r, c, r2, c2) = item.GetUserData()
  120.             width = reduce(operator.add, self.colWidths[c:c2])
  121.             height = reduce(operator.add, self.rowHeights[r:r2])
  122.             self.SetItemBounds(item, cpos[c], rpos[r], width, height)
  123.         
  124.  
  125.     
  126.     def SetItemBounds(self, item, x, y, w, h):
  127.         ipt = wxPoint(x, y)
  128.         isz = item.CalcMin()
  129.         flag = item.GetFlag()
  130.         if flag & wxEXPAND or flag & wxSHAPED:
  131.             isz = wxSize(w, h)
  132.         elif flag & wxALIGN_CENTER_HORIZONTAL:
  133.             ipt.x = x + (w - isz.width) / 2
  134.         elif flag & wxALIGN_RIGHT:
  135.             ipt.x = x + (w - isz.width)
  136.         
  137.         if flag & wxALIGN_CENTER_VERTICAL:
  138.             ipt.y = y + (h - isz.height) / 2
  139.         elif flag & wxALIGN_BOTTOM:
  140.             ipt.y = y + (h - isz.height)
  141.         
  142.         item.SetDimension(ipt, isz)
  143.  
  144.  
  145.