| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
from RBFoundation.Utilities import flatten |
|---|
| 27 |
from wxPython.lib.rcsizer import RowColSizer |
|---|
| 28 |
|
|---|
| 29 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 30 |
#~ Definitions |
|---|
| 31 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 32 |
|
|---|
| 33 |
class wxRBRowColSizer(RowColSizer): |
|---|
| 34 |
def __init__(self, defaultcellsize=None): |
|---|
| 35 |
RowColSizer.__init__(self) |
|---|
| 36 |
self._calcRowsDirty = True |
|---|
| 37 |
self._growableRows = [] |
|---|
| 38 |
self._growableRowsRange = None |
|---|
| 39 |
self._calcColsDirty = True |
|---|
| 40 |
self._growableCols = [] |
|---|
| 41 |
self._growableColsRange = None |
|---|
| 42 |
if defaultcellsize is not None: |
|---|
| 43 |
self.SetDefaultCellSize() |
|---|
| 44 |
|
|---|
| 45 |
def SetDefaultCellSize(self, defaultcellsize=(RowColSizer.col_w, RowColSizer.row_h)): |
|---|
| 46 |
self.col_w, self.row_h = defaultcellsize |
|---|
| 47 |
|
|---|
| 48 |
def AddGrowableRow(self, *indicies): |
|---|
| 49 |
self._calcRowsDirty = True |
|---|
| 50 |
indicies = flatten(indicies) |
|---|
| 51 |
self._growableRows.extend(indicies) |
|---|
| 52 |
|
|---|
| 53 |
def SetGrowableRowRange(self, start=None, end=None): |
|---|
| 54 |
self._calcRowsDirty = True |
|---|
| 55 |
self._growableRowsRange = slice(start, end) |
|---|
| 56 |
|
|---|
| 57 |
def AddGrowableCol(self, *indicies): |
|---|
| 58 |
self._calcColsDirty = True |
|---|
| 59 |
indicies = flatten(indicies) |
|---|
| 60 |
self._growableCols.extend(indicies) |
|---|
| 61 |
|
|---|
| 62 |
def SetGrowableColRange(self, start=None, end=None): |
|---|
| 63 |
self._calcColsDirty = True |
|---|
| 64 |
self._growableColsRange = slice(start, end) |
|---|
| 65 |
|
|---|
| 66 |
def RecalcSizes(self): |
|---|
| 67 |
if self._calcRowsDirty: |
|---|
| 68 |
self.growableRows = self._CalculateGrowableRows() |
|---|
| 69 |
self._calcRowsDirty = False |
|---|
| 70 |
|
|---|
| 71 |
if self._calcColsDirty: |
|---|
| 72 |
self.growableCols = self._CalculateGrowableCols() |
|---|
| 73 |
self._calcColsDirty = False |
|---|
| 74 |
return RowColSizer.RecalcSizes(self) |
|---|
| 75 |
|
|---|
| 76 |
def _CalculateGrowableRows(self): |
|---|
| 77 |
try: |
|---|
| 78 |
indexmap = range(len(self.rowHeights)) |
|---|
| 79 |
except AttributeError: |
|---|
| 80 |
return [] |
|---|
| 81 |
|
|---|
| 82 |
result = {} |
|---|
| 83 |
rowsslice = self._growableRowsRange |
|---|
| 84 |
if rowsslice is not None: |
|---|
| 85 |
if rowsslice.start is not None: |
|---|
| 86 |
start = rowsslice.start |
|---|
| 87 |
else: start = 0 |
|---|
| 88 |
if rowsslice.stop is not None: |
|---|
| 89 |
stop = rowsslice.stop |
|---|
| 90 |
else: stop = len(indexmap) |
|---|
| 91 |
for idx in indexmap[start:stop]: |
|---|
| 92 |
result[indexmap[idx]] = None |
|---|
| 93 |
|
|---|
| 94 |
for idx in self._growableRows: |
|---|
| 95 |
result[indexmap[idx]] = None |
|---|
| 96 |
result = result.keys() |
|---|
| 97 |
result.sort() |
|---|
| 98 |
return result |
|---|
| 99 |
|
|---|
| 100 |
def _CalculateGrowableCols(self): |
|---|
| 101 |
try: indexmap = range(len(self.colWidths)) |
|---|
| 102 |
except AttributeError: return [] |
|---|
| 103 |
result = {} |
|---|
| 104 |
|
|---|
| 105 |
colsslice = self._growableColsRange |
|---|
| 106 |
if colsslice is not None: |
|---|
| 107 |
if colsslice.start is not None: |
|---|
| 108 |
start = colsslice.start |
|---|
| 109 |
else: start = 0 |
|---|
| 110 |
if colsslice.stop is not None: |
|---|
| 111 |
stop = colsslice.stop |
|---|
| 112 |
else: stop = len(indexmap) |
|---|
| 113 |
for idx in indexmap[start:stop]: |
|---|
| 114 |
result[indexmap[idx]] = None |
|---|
| 115 |
for idx in self._growableCols: |
|---|
| 116 |
result[indexmap[idx]] = None |
|---|
| 117 |
result = result.keys() |
|---|
| 118 |
result.sort() |
|---|
| 119 |
return result |
|---|
| 120 |
|
|---|