dabo Commit
Revision 2200
Date: 2006-06-05 05:53:45 -0700 (Mon, 05 Jun 2006)
Author: ed
Changed:
U trunk/dabo/ui/uiwx/dGrid.py
Log:
Added an 'Expand' property to columns. When True, resizing the grid will cause
all the columns where Expand=True to grow/shrink their widths to fit.
Diff:
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2006-06-05 00:50:42 UTC (rev 2199)
+++ trunk/dabo/ui/uiwx/dGrid.py 2006-06-05 12:53:45 UTC (rev 2200)
@@ -422,6 +422,7 @@
def __init__(self, parent, properties=None, attProperties=None,
*args, **kwargs):
self._isConstructed = False
+ self._expand = False
self._beforeInit()
kwargs["Parent"] = parent
# dColumn maintains one attr object that the grid table will
use:
@@ -790,6 +791,16 @@
return v
+ def _getExpand(self):
+ return self._expand
+
+ def _setExpand(self, val):
+ if self._constructed():
+ self._expand = val
+ else:
+ self._properties["Expand"] = val
+
+
def _getDataField(self):
try:
v = self._dataField
@@ -1254,6 +1265,10 @@
will be self.CustomEditorClass if set, or the
default editor for the
datatype of the field. (varies)"""))
+ Expand = property(_getExpand, _setExpand, None,
+ _("""Does this column expand/shrink as the grid width
changes?
+ Default=False (bool)"""))
+
DataField = property(_getDataField, _setDataField, None,
_("Field key in the data set to which this column is
bound. (str)") )
@@ -1498,6 +1513,8 @@
# Set the header props/events
self.initHeader()
+ # Make sure that the columns are sized properly
+ self._updateColumnWidths()
def initEvents(self):
@@ -1534,8 +1551,9 @@
## wx.EVT_CONTEXT_MENU doesn't appear to be working for dGrid
yet:
# self.bindEvent(dEvents.GridContextMenu, self._onContextMenu)
self.bindEvent(dEvents.GridMouseRightClick,
self._onGridMouseRightClick)
-
-
+ self.bindEvent(dEvents.Resize, self._onGridResize)
+
+
def initHeader(self):
""" Initialize behavior for the grid header region."""
header = self._getWxHeader()
@@ -1872,6 +1890,35 @@
return True
+ def _onGridResize(self, evt):
+ dabo.ui.callAfter(self._updateColumnWidths)
+
+
+ def _updateColumnWidths(self):
+ """See if there are any dynamically-sized columns, and resize
them
+ accordingly.
+ """
+ dynCols = [col for col in self.Columns
+ if col.Expand]
+ if not dynCols:
+ return
+ dynColCnt = len(dynCols)
+ # Add up the current widths
+ wds = [col.Width for col in self.Columns]
+ wd = reduce(lambda x, y: x+y, wds)
+ diff = self.Width - wd
+ if not diff:
+ return
+ adj = diff/ dynColCnt
+ mod = diff % dynColCnt
+ for col in dynCols:
+ if mod:
+ col.Width += (adj+1)
+ mod -= 1
+ else:
+ col.Width += adj
+
+
def autoSizeCol(self, colNum, persist=False):
"""Set the column to the minimum width necessary to display its
data.
@@ -3950,7 +3997,7 @@
col = dColumn(self, Name="Person", Order=20, DataField="name",
DataType="string", Width=200, Caption="Customer
Name",
- Sortable=True, Searchable=True, Editable=False)
+ Sortable=True, Searchable=True, Editable=False,
Expand=True)
self.addColumn(col)
col.HeaderFontItalic = True
@@ -3964,7 +4011,7 @@
col = dColumn(self, Name="Color", Order=40, DataField="color",
DataType="string", Width=40, Caption="Favorite
Color",
- Sortable=True, Searchable=False, Editable=True)
+ Sortable=True, Searchable=False, Editable=True,
Expand=True)
self.addColumn(col)
col.ListEditorChoices = ["green", "brown", "purple"]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev