- Revision
- 16074
- Author
- grant
- Date
- 2007-12-06 15:45:35 -0800 (Thu, 06 Dec 2007)
Log Message
[APP] Actually include the test module I mean to add in r16061.
Modified Paths
Added Paths
Diff
Modified: branches/rearchitecture/Chandler-Platform/ocap/wxui/table.py (16073 => 16074)
--- branches/rearchitecture/Chandler-Platform/ocap/wxui/table.py 2007-12-06 22:48:19 UTC (rev 16073) +++ branches/rearchitecture/Chandler-Platform/ocap/wxui/table.py 2007-12-06 23:45:35 UTC (rev 16074) @@ -162,10 +162,12 @@ view.EndBatch() for row in view.GetSelectedRows(): - if not self.listModel[row] in self.listModel.selected: + index = self.RowToIndex(row) + if not self.listModel[index] in self.listModel.selected: trellis.on_commit(view.DeselectRow, row) - for row, item in enumerate(self.listModel): + for index, item in enumerate(self.listModel): + row = self.IndexToRow(index) if item in self.listModel.selected: trellis.on_commit(view.SelectRow, row, True) @@ -429,14 +431,11 @@ self.SetSelectionBackground(background) def InvalidateSelection(self): - lastRow = self.GetNumberCols() - 1 + numColumns = self.GetNumberCols() for rowStart, rowEnd in self.Table.SelectedRowRanges(): - dirtyRect = wx.Rect() - dirtyRect.SetTopLeft(self.GetCellRect(rowStart, 0).GetTopLeft()) - dirtyRect.SetBottomRight(self.GetCellRect(rowEnd, - lastRow).GetBottomRight()) - dirtyRect.OffsetXY(self.GetRowLabelSize(), self.GetColLabelSize()) + dirtyRect = self.GetRectForCellRange(rowStart, 0, + rowEnd - rowStart + 1, numColumns) self.RefreshRect(dirtyRect) def OnInit(self): @@ -454,13 +453,20 @@ self.EnableGridLines(self.hasGridLines) - def GetCellRect(self, row, col): - cellRect = self.CellToRect(row, col) - cellRect.OffsetXY(self.GetRowLabelSize(), self.GetColLabelSize()) - left, top = self.CalcScrolledPosition(cellRect.GetLeft(), cellRect.GetTop()) - cellRect.SetLeft(left) - cellRect.SetTop(top) - return cellRect + def GetRectForCellRange(self, startRow, startCol, numRows=1, numCols=1): + resultRect = self.CellToRect(startRow, startCol) + + if numRows > 1 or numCols > 1: + endRect = self.CellToRect(startRow + numRows - 1, + startCol + numCols - 1) + resultRect.SetTopRight(endRect.GetTopRight()) + + + resultRect.OffsetXY(self.GetRowLabelSize(), self.GetColLabelSize()) + left, top = self.CalcScrolledPosition(resultRect.GetLeft(), resultRect.GetTop()) + resultRect.SetLeft(left) + resultRect.SetTop(top) + return resultRect def __eventToRowCol(self, event): """ return the cell coordinates for the X & Y in this event """ @@ -499,7 +505,7 @@ if self.Table.CanClick(row, col): self.clickRowCol = self.overRowCol = row, col event.Skip(False) # Gobble the event - self.RefreshRect(self.GetCellRect(*self.clickRowCol)) + self.RefreshRect(self.GetRectForCellRange(*self.clickRowCol)) self.SetFocus() else: self.overRowCol = None @@ -508,7 +514,7 @@ if self.clickRowCol == (row, col): self.Table.OnClick(row, col) if self.clickRowCol is not None: - self.RefreshRect(self.GetCellRect(*self.clickRowCol)) + self.RefreshRect(self.GetRectForCellRange(*self.clickRowCol)) self.overRowCol = None elif event.LeftDClick(): @@ -544,7 +550,7 @@ if self.overRowCol != oldOverRowCol: if oldOverRowCol is not None: - self.RefreshRect(self.GetCellRect(*oldOverRowCol)) + self.RefreshRect(self.GetRectForCellRange(*oldOverRowCol)) if self.overRowCol is None: if (gridWindow.HasCapture()): @@ -552,9 +558,9 @@ if self.clickRowCol is not None: clickRowCol = self.clickRowCol self.clickRowCol = None - self.RefreshRect(self.GetCellRect(*clickRowCol)) + self.RefreshRect(self.GetRectForCellRange(*clickRowCol)) else: - self.RefreshRect(self.GetCellRect(*self.overRowCol)) + self.RefreshRect(self.GetRectForCellRange(*self.overRowCol)) def OnMouseCaptureLost(self, event): @@ -597,8 +603,14 @@ bitmapCache = None bitmapProvider = staticmethod(get_image) - def __init__(self): + def __init__(self, **kw): super(IconRenderer, self).__init__() + + bitmapCache = kw.pop('bitmapCache', None) + + if bitmapCache is not None: + self.bitmapCache = bitmapCache + if self.bitmapCache is None: cls = type(self) cls.bitmapCache = multi_state.MultiStateBitmapCache() @@ -670,18 +682,18 @@ value = self.advanceValue(value) state = self.mapValueToIconState(value) - + mouseOver = mouseDown or (row, col) == grid.overRowCol variation = self.getVariation(False, isSelected, mouseDown, mouseOver) imageSet = self.bitmapCache[state] - + image = getattr(imageSet, variation, None) assert image is not None, "Bogus image for state %s variation %s" % ( - taskness, variation) + state, variation) x, y, w, h = rect.Get() x += (w - image.GetWidth()) / 2
Added: branches/rearchitecture/Chandler-Platform/test_table.py (16073 => 16074)
--- branches/rearchitecture/Chandler-Platform/test_table.py 2007-12-06 22:48:19 UTC (rev 16073) +++ branches/rearchitecture/Chandler-Platform/test_table.py 2007-12-06 23:45:35 UTC (rev 16074) @@ -0,0 +1,157 @@ +import mocker +import ocap.wxui.multi_state as multi_state +import ocap.wxui.table as table +import wx.grid as grid +import wx + +class IconRendererDrawTestCase(mocker.MockerTestCase): + + def setUp(self): + super(IconRendererDrawTestCase, self).setUp() + + # Set up mocks for the objects we need + self.grid = self.mocker.mock(table.Table) + self.table = self.mocker.mock(table.TablePresentation) + self.attr = self.mocker.mock(grid.GridCellAttr) + self.dc = self.mocker.mock(wx.PaintDC) + self.bitmapCache = self.mocker.mock(multi_state.MultiStateBitmapCache) + self.renderer = table.IconRenderer(bitmapCache=self.bitmapCache) + + mocker.expect(self.grid.Table).result(self.table).count(0, None) + mocker.expect(self.grid.GetTable()).result(self.table).count(0, None) + mocker.expect(self.table.View).result(self.grid).count(0, None) + mocker.expect(self.table.GetView()).result(self.grid).count(0, None) + + mocker.expect(self.grid.IsEnabled()).result(True).count(0, None) + + mocker.expect(self.renderer.bitmapCache).result(self.bitmapCache).count(0, None) + + + def testDrawBogusImage(self): + + row = 0 + col = 2 + isSelected = False + + rect = wx.Rect(0, 100, 300, 240) + + mocker.expect(self.table.GetValue(row, col)).result("Woo!") + mocker.expect(self.bitmapCache["Woo!"]).result(None) + + mocker.expect(self.grid.clickRowCol).result((12, 11)) + mocker.expect(self.grid.overRowCol).result((4, 3)) + + self.mocker.before( + mocker.expect(self.mocker.replace("ocap.wxui.drawing").SetTextColorsAndFont(self.grid, self.attr, self.dc, isSelected)).result(None), + mocker.expect(self.dc.SetBackgroundMode(wx.SOLID)).result(None), + mocker.expect(self.dc.SetPen(mocker.IS(wx.TRANSPARENT_PEN))).result(None), + mocker.expect(self.dc.DrawRectangleRect(rect)).result(None), + mocker.expect(self.dc.SetBackgroundMode(wx.TRANSPARENT)).result(None), + ) + + + self.mocker.replay() + self.failUnlessRaises( + AssertionError, + self.renderer.Draw, + self.grid, self.attr, self.dc, rect, row, col, isSelected + ) + + def doDrawingTest(self, (row, col), clickRowCol, overRowCol, selected, + variant): + """ + Used to test various rollover/mousedown icon states in IconRenderer.Draw + + @param (row, col): The row/column passed into Draw (i.e. which cell + we're drawing). + + @param clickRowCol: What grid.clickRowCol should return for this test + @param overRowCol: What grid.overRowCol should return for this test + + @param selected: Passed into ImageRenderer.Draw + @param variant: The expected variant ("normal"/"mousedown"/etc) for + this combination of mouse/click/selected state. + + """ + + rect = wx.Rect(0, 100, 300, 240) + + #mocker.expect(self.renderer.bitmapCache).result(self.bitmapCache).count(0, None) + mocker.expect(self.grid.clickRowCol).result(clickRowCol).count(0, None) + mocker.expect(self.grid.overRowCol).result(overRowCol).count(0, None) + + imageSet = self.mocker.mock(multi_state.BitmapInfo) + + # For testing, let's say we have a 40x80 image ... + # ... in which case, we will want Draw to be at 130, 180, since: + # (130,170) is centered in (0, 300)), + # (180,260) is centered in (100, 340)) + + image = self.mocker.mock(wx.Image) + mocker.expect(image.GetWidth()).result(40).count(0, None) + mocker.expect(image.GetHeight()).result(80).count(0, None) + + mocker.expect(self.table.GetValue(row, col)).result("Woo!") + mocker.expect(self.bitmapCache["Woo!"]).result(imageSet) + + # Make sure we get the right imageSet name + mocker.expect(getattr(imageSet, variant)).result(image) + + self.mocker.before( + mocker.expect( + self.mocker.replace("ocap.wxui.drawing").SetTextColorsAndFont( + self.grid, self.attr, self.dc, selected) + ).result(None), + mocker.expect(self.dc.SetBackgroundMode(wx.SOLID)).result(None), + mocker.expect(self.dc.SetPen(mocker.IS(wx.TRANSPARENT_PEN))).result(None), + mocker.expect(self.dc.DrawRectangleRect(rect)).result(None), + mocker.expect(self.dc.SetBackgroundMode(wx.TRANSPARENT)).result(None), + mocker.expect(self.dc.DrawBitmap(image, 130, 180, True)) + ) + + # OK, now for the real tests ... + self.mocker.replay() + self.renderer.Draw(self.grid, self.attr, self.dc, rect, row, col, selected) + + def testDrawNormal(self): + self.doDrawingTest((0, 2), (12, 11), (4, 3), False, "normal") + + def testDrawNormalNoMouse(self): + self.doDrawingTest((0, 2), None, None, False, "normal") + + def testDrawSelected(self): + self.doDrawingTest((0, 2), (12, 11), (4, 3), True, "selected") + + def testDrawMousedown(self): + self.doDrawingTest((0, 2), (0, 2), (0, 2), False, "mousedown") + + def testDrawMouseover(self): + self.doDrawingTest((0, 2), None, (0, 2), False, "rollover") + + def testDrawSelectedMousedown(self): + self.doDrawingTest((5, 5), (5, 5), (5, 5), True, "mousedownselected") + + def testDrawSelectedMouseover(self): + self.doDrawingTest((5, 5), None, (5, 5), True, "rolloverselected") + + def testDrawSelectedMousedownOther(self): + self.doDrawingTest((4, 3), (4, 3), (5, 5), True, "mousedownselected") + + def testDrawSelectedMousedownOther(self): + self.doDrawingTest((4, 3), (1, 2), (4, 3), True, "rolloverselected") + + def testAdvanceValue(self): + """Check that drawing an icon in mouse-down mode advances value""" + mock = self.mocker.patch(self.renderer, table.IconRenderer) + mocker.expect(mock.advanceValue("Woo!")).result("Woo!").count(1) + self.doDrawingTest((3, 1), (3, 1), (4, 0), False, "mousedown") + + def testNoAdvanceValue(self): + """ + Check that drawing an icon in non mouse-down mode doesn't advance + value. + """ + """Check that drawing an icon in mouse-down mode advances value""" + mock = self.mocker.patch(self.renderer, table.IconRenderer) + mocker.expect(mock.advanceValue("Woo!")).result("Woo!").count(0) + self.doDrawingTest((3, 1), None, (3, 1), True, "rolloverselected") Property changes on: branches/rearchitecture/Chandler-Platform/test_table.py ___________________________________________________________________ Name: svn:eol-style + native
_______________________________________________ Commits mailing list [email protected] http://lists.osafoundation.org/mailman/listinfo/commits
