dabo Commit
Revision 5669
Date: 2010-02-08 17:53:10 -0800 (Mon, 08 Feb 2010)
Author: Ed
Trac: http://trac.dabodev.com/changeset/5669
Changed:
U trunk/dabo/ui/uiwx/dGrid.py
Log:
Improved the behavior of the Expand property to take into account the presence
of scrollbars. However, detecting scrollbar visibility is not straightforward.
I'm sure that this will need more platform-specific tweaking.
Diff:
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2010-02-08 22:31:03 UTC (rev 5668)
+++ trunk/dabo/ui/uiwx/dGrid.py 2010-02-09 01:53:10 UTC (rev 5669)
@@ -2286,24 +2286,57 @@
def _onGridResize(self, evt):
- dabo.ui.callAfterInterval(50, self._updateColumnWidths)
+ dabo.ui.callAfter(self._updateColumnWidths)
+ def _totalContentWidth(self):
+ ret = sum([col.Width for col in self.Columns])
+ if self.ShowRowLabels:
+ ret += self.RowLabelWidth
+ return ret
+
+
+ def _totalContentHeight(self):
+ if self.SameSizeRows:
+ ret = self.RowHeight * self.RowCount
+ else:
+ ret = sum([self.GetRowSize(r) for r in
xrange(self.RowCount)])
+ if self.ShowHeaders:
+ ret += self.HeaderHeight
+ return ret
+
+
+ def isScrollBarVisible(self, which):
+ whichSide = {"h": wx.HORIZONTAL, "v":
wx.VERTICAL}[which[0].lower()]
+ sr = self.GetScrollRange(whichSide)
+ if self.Application.Platform == "Win":
+ # For some reason, GetScrollRange() returns either 1 or
101 when the scrollbar
+ # is not visible under Windows. Under OS X, it returns
0 as expected.
+ return sr not in (1, 101)
+ return bool(sr)
+
+
@dabo.ui.deadCheck
def _updateColumnWidths(self):
"""See if there are any dynamically-sized columns, and resize
them
accordingly.
"""
+ if not [col for col in self.Columns if col.Expand]:
+ return
+ dabo.ui.callAfterInterval(10, self._delayedUpdateColumnWidths)
+ def _delayedUpdateColumnWidths(self):
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)
- # Subtract one extra pixel to avoid triggering the scroll bar.
- diff = self.Width - wd - 1
+ colWd = self._totalContentWidth()
+ rowHt = self._totalContentHeight()
+ if self.isScrollBarVisible("v"):
+ # This will probably be OS-dependent. This works on OS
X.
+ colWd += 17
+ wd, ht = self.Size
+ # Subtract extra pixels to avoid triggering the scroll bar.
Again, this
+ # will probably be OS-dependent
+ diff = self.Width - colWd - 10
if not diff:
return
adj = diff/ dynColCnt
@@ -4801,7 +4834,7 @@
col = dColumn(self, Name="Person", Order=20, DataField="name",
DataType="string", Width=200,
Caption="Celebrity Name",
- Sortable=True, Searchable=True, Editable=True,
Expand=False)
+ Sortable=True, Searchable=True, Editable=True,
Expand=True)
self.addColumn(col)
col.HeaderFontItalic = True
@@ -4837,7 +4870,8 @@
col.HeaderHorizontalAlignment = "Right"
col.HeaderForeColor = "brown"
- for i in range(20):
+ for i in range(1):
+ # Can't test Expand with so many columns! Just add one.
self.addColumn(DataField="i_%s" % i, Caption="i_%s" % i)
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]