dabo Commit
Revision 4572
Date: 2008-10-21 16:46:10 -0700 (Tue, 21 Oct 2008)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/4572

Changed:
U   trunk/dabo/ui/uiwx/dGrid.py

Log:
Rewrote the grid header painting routines, and now at least it is consistent
between Mac and Linux (previously, Mac performed horribly). There are visual
problems on Windows which I'll try to fix right now.



Diff:
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2008-10-20 14:02:32 UTC (rev 4571)
+++ trunk/dabo/ui/uiwx/dGrid.py 2008-10-21 23:46:10 UTC (rev 4572)
@@ -103,19 +103,6 @@
 
 
        def GetColLabelValue(self, col):
-               if sys.platform[:3] != "win":
-                       # Windows performs better drawing the header in 
response to EVT_PAINT,
-                       # while Mac and Linux perform better doing it the old 
way, in response
-                       # to table.getColLabelValue().
-                       colObj = self.grid._columns[col]
-                       # Linux performs horribly with the callAfter(); Mac 
doesn't draw
-                       # correctly without it!
-                       if sys.platform[:6] == "darwin":
-                               #self.grid._paintHeader(colObj)             ## 
Doesn't paint all columns; misplaces the horizontal location.
-                               #dabo.ui.callAfter(self.grid._paintHeader)  ## 
Draws same headers multiple times, overlapping a little.
-                               dabo.ui.callAfterInterval(1, 
self.grid._paintHeader, colObj)  ## Still leaves artifacts around the grid, but 
the best I can do right now.
-                       else:
-                               self.grid._paintHeader(colObj)
                return ""
 
 
@@ -668,7 +655,6 @@
 
                # Thanks Roger Binns:
                left = -grid.GetViewStart()[0] * 
grid.GetScrollPixelsPerUnit()[0]
-
                for col in range(self.Parent.ColumnCount):
                        colObj = self.Parent.Columns[col]
                        if colObj == self:
@@ -689,7 +675,6 @@
                        #               
self.Parent._paintHeader(self._GridColumnIndex)
                        self.Parent.SetColLabelValue(self._GridColumnIndex, "")
 
-
        def _refreshGrid(self):
                """Refresh the grid region, not the header region."""
                if self.Parent:
@@ -1893,6 +1878,10 @@
                self._syncCurrentRow()
 
 
+       def _refreshHeader(self):
+               self._getWxHeader().Refresh()
+
+
        def GetCellValue(self, row, col, useCache=True):
                try:
                        ret = self._Table.GetValue(row, col, useCache=useCache)
@@ -2291,30 +2280,24 @@
 
        
 
-       def _paintHeader(self, colObj=None):
+       def _paintHeader(self):
                w = self._getWxHeader()
-               dc = wx.ClientDC(w)
-               
-               if colObj is None:
-                       # Normal case: from EVT_PAINT
-                       updateBox = w._updateBox
-               else:
-                       # Special case: redraw the header for a specific column
-                       updateBox = colObj._getHeaderRect()
+               dc = wx.PaintDC(w)
+               updateBox = w.GetUpdateRegion().GetBox()
 
-               x1 = updateBox[0]
-               x2 = x1 + updateBox[2]
+               for col in self._columns:
+                       headerRect = col._getHeaderRect()
+                       intersect = wx.IntersectRect(updateBox, headerRect)
+                       if intersect is None:
+                               # column isn't visible
+                               continue
 
-               while x2 > x1:
                        sortIndicator = False
-                       left = x1
-                       colObj = self.getColByX(left+1)
+                       colObj = self.getColByX(intersect[0])
                        if not colObj:
                                # Grid is probably being created or destroyed, 
so just return
                                return
-                       x1 += colObj.Width
-                       rect = colObj._getHeaderRect()
-                       dc.SetClippingRegion(rect.x, rect.y, rect.width, 
rect.height)
+                       dc.SetClippingRegion(*headerRect)
        
                        holdBrush = dc.GetBrush()
                        holdPen = dc.GetPen()
@@ -2335,11 +2318,8 @@
 
                        if bcolor is not None:
                                dc.SetBrush(wx.Brush(bcolor, wx.SOLID))
-                               dc.SetPen(wx.Pen(None, width=0))
-                               dc.DrawRectangle(rect[0],
-                                       rect[1],
-                                       rect[2],
-                                       rect[3])
+                               dc.SetPen(wx.Pen(fcolor, width=0))
+                               dc.DrawRectangle(*headerRect)
                        dc.SetPen(holdPen)
                        dc.SetBrush(holdBrush)
 
@@ -2347,8 +2327,8 @@
                                sortIndicator = True
                                # draw a triangle, pointed up or down, at the 
top left
                                # of the column. TODO: Perhaps replace with 
prettier icons
-                               left = rect[0] + self.sortIndicatorBuffer
-                               top = rect[1] + self.sortIndicatorBuffer
+                               left = headerRect[0] + self.sortIndicatorBuffer
+                               top = headerRect[1] + self.sortIndicatorBuffer
 
                                brushColor = 
dColors.colorTupleFromName(self.sortIndicatorColor)
                                dc.SetBrush(wx.Brush(brushColor, wx.SOLID))
@@ -2394,7 +2374,7 @@
                        if sortIndicator:
                                # If there's a sort indicator, we'll nudge the 
caption over
                                sortBuffer += (self.sortIndicatorBuffer + 
self.sortIndicatorSize)
-                       trect = list(rect)
+                       trect = list(headerRect)
                        trect[0] = trect[0] + sortBuffer
                        trect[1] = trect[1] + vertBuffer
                        if ah == "Center":
@@ -3150,7 +3130,6 @@
                colNum = evt.EventData["col"]
                col = self.Columns[colNum]
                colName = "Column_%s" % col.DataField
-
                # Sync our column object up with what the grid is reporting, 
and because
                # the user made this change, save to the userSettings:
                width = col.Width = self.GetColSize(colNum)
@@ -3470,11 +3449,14 @@
 
 
        def __onWxGridColSize(self, evt):
-               if self.ResizableColumns and 
self.Columns[evt.GetRowOrCol()].Resizable:
+               col = evt.GetRowOrCol()
+               if self.ResizableColumns and self.Columns[col].Resizable:
                        self.raiseEvent(dEvents.GridColSize, evt)
                else:
+                       # need to reference the Width property for some reason:
+                       self.Columns[col].Width
                        evt.Veto()
-                       
self._paintHeader(colObj=self.Columns[evt.GetRowOrCol()])
+                       self._refreshHeader()
 
 
        def __onWxGridSelectCell(self, evt):
@@ -3733,14 +3715,8 @@
 
        def __onWxHeaderPaint(self, evt):
                self.raiseEvent(dEvents.GridHeaderPaint, evt)
-               evt.Skip()
-               if sys.platform[:3] == "win":
-                       # Windows performs better drawing the header in 
response to EVT_PAINT,
-                       # while Mac and Linux perform better doing it the old 
way, in response
-                       # to table.getColLabelValue().
-                       w = self._getWxHeader()
-                       w._updateBox = w.GetUpdateRegion().GetBox()
-                       dabo.ui.callAfter(self._paintHeader)
+               #evt.Skip()
+               self._paintHeader()
 
 
        def _getColRowForPosition(self, pos):




_______________________________________________
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]

Reply via email to