Assertion failure in grid with custom cell renderer

Hi,

Windows XP Professional, Version 2002, Service Pack 1
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
wx.__version__ = '2.8.0.1' (ansi)

I'm hitting this assertion error in the cut-down code below (reformatted
slightly):

Traceback (most recent call last):
  File "capture-test.py", line 9, in Draw
    dc.SetBackgroundMode(wx.SOLID)
  File "C:\Python25\Lib\site-packages\wx-2.8-msw-ansi\wx\_gdi.py", line 3697, in SetBackgroundMode
    return _gdi_.DC_SetBackgroundMode(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure"
                           failed at ..\..\src\common\wincmn.cpp(2490)
                           in DoNotifyWindowAboutCaptureLost():
                           window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST

The steps I can take to reliably trigger it are as follows:

Launch from a CMD window: python capture-test.py

Drag the "Test" window which appears until it overlaps the CMD window.
(The "Test" window is also therefore in front of the CMD window now.)

Press-and-hold the left mouse button in the middle of cell A1.

Drag (still holding the left mouse button down) down to the middle of
cell A3, thereby highlighting cells A1--A3.

Still holding the left mouse button down, alt-tab to the CMD window.

Still holding the left mouse button down, alt-tab back to the "Test"
window.

Assertion failure is produced. (Program continues executing, but
painting is broken until alt-tab back and forth again.)

The failure does not occur without a custom renderer.

I hit the failure in slightly less contrived circumstances but this was
the first way I found to reliably reproduce it. As mentioned, it
doesn't cause the program to completely fail, but thought I'd bring it
to the list's attention anyway.

Thanks,

Ben.

- - - - 8< - - - - #### File capture-test.py ####

import wx
import wx.grid

class TestRenderer(wx.grid.PyGridCellRenderer):
    def __init__(self):
        wx.grid.PyGridCellRenderer.__init__(self)

    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        dc.SetBackgroundMode(wx.SOLID)
        dc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangleRect(rect)

    def Clone(self):
        return TestRenderer()

class TestGrid(wx.grid.Grid):
    def __init__(self, parent):
        wx.grid.Grid.__init__(self, parent, -1)
        self.CreateGrid(5, 5)
        self.SetCellRenderer(1, 1, TestRenderer())

class TestFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "Test", size = (800, 480))

        p = wx.Panel(self, -1, style=0)
        grid = TestGrid(p)
        bs = wx.BoxSizer(wx.VERTICAL)
        bs.Add(grid, 1, wx.GROW|wx.ALL, 5)
        p.SetSizer(bs)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = TestFrame(None)
    frame.Show(True)
    app.MainLoop()

Ben North wrote:

Hi,

Windows XP Professional, Version 2002, Service Pack 1
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
wx.__version__ = '2.8.0.1' (ansi)

I'm hitting this assertion error in the cut-down code below (reformatted
slightly):

Traceback (most recent call last):
  File "capture-test.py", line 9, in Draw
    dc.SetBackgroundMode(wx.SOLID)
  File "C:\Python25\Lib\site-packages\wx-2.8-msw-ansi\wx\_gdi.py", line 3697, in SetBackgroundMode
    return _gdi_.DC_SetBackgroundMode(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure"
                           failed at ..\..\src\common\wincmn.cpp(2490)
                           in DoNotifyWindowAboutCaptureLost():
                           window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST

I've never understood why the assertion is there. (It seems to me that it is ok for a window to ignore this event.) I'll ask about it again on wx-dev.

In the meantime you can just catch the EVT_MOUSE_CAPTURE_LOST event yourself and do nothing in the handler. For grids you'll need to bind it to self.GetGridWindow()

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Ben North wrote:

Robin Dunn wrote:
> Ben North wrote:
> > Hi,
> > I'm hitting this assertion error [...]
> > window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST
>
> I've never understood why the assertion is there. (It seems to me
> that it is ok for a window to ignore this event.)

OK; good to know that it's harmless.

Not quite. In your case the raising of the exception is causing the rest of your renderer's Draw method to not be executed.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!