grid causing assertion errors.

Jack Andrews effbiae at gmail.com
Thu Dec 21 03:06:36 PST 2006


the appended script produces c++ assertion errors when the button is
pressed once or twice:

C:\>python
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.__version__
'2.7.2.0'
>>>


C:\>python gridtest.py
[2004, 3, -1] True
[2007, 2, -2] True
[2000] True
[2004, 4, -1] True
[2007, 4, -1]
Traceback (most recent call last):
  File "gridtest.py", line 55, in OnClick
    t.ResetView([range(z) for x in range(z)])
  File "gridtest.py", line 31, in ResetView
    if x:print x,self.g.ProcessTableMessage(wg.GridTableMessage(self,*x))
  File "C:\Python25\Lib\site-packages\wx-2.7.2-msw-ansi\wx\grid.py", line 1200,
in ProcessTableMessage
    return _grid.Grid_ProcessTableMessage(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "uiIndex < m_nCount" failed at ..\..\in
clude\wx/dynarray.h(810) in wxBaseArrayInt::Item()


import wx,wx.grid,wx.html,sys
import odbc as mhodbc
wg=wx.grid
ga=getattr;sa=setattr
class Tgrid(wg.Grid):pass
class HugeTable(wg.PyGridTableBase):
    def rc(self):return len(self.t),len(self.t[0])
    def __init__(self,g,t):
        wg.PyGridTableBase.__init__(self);self.t=t;self.g=g;rc=self.rc()
        cs='#EEEEEE #FFFFFF'.split()
        self.gcas=[wg.GridCellAttr()  for c in cs]
        for a,c in zip(self.gcas,cs):a.SetBackgroundColour(c)
    def GetAttr(self,r,c,kind):
        gca=self.gcas[r%2];gca.IncRef();return gca
    def GetNumberRows(self): return self.rc()[0]
    def GetNumberCols(self): return self.rc()[1]
    def IsEmptyCell(self,r,c): return False
    def GetValue(self,r,c):return self.t[r][c]
    def SetValue(self,r,c,x):print 'setvalue ignored.\n'
    def ResetView(self,t):
            self.g.BeginBatch()
            rc0=self.rc();self.t=t;rc1=self.rc();msgs=[]
            for i,rc in enumerate('Rows Cols'.split()):
                e=dict(zip('aA',[rc,rc.upper()]))
                n0=ga(self,'GetNumber%(a)s'%e)()
                d=rc1[i]-rc0[i]
                msgs+=[[[ga(wg,'GRIDTABLE_NOTIFY_%(A)s_DELETED'%e),
rc0[i],-d],[],

[ga(wg,'GRIDTABLE_NOTIFY_%(A)s_APPENDED'%e),d]][cmp(0,d)+1]]
            if msgs:msgs+=[[wg.GRIDTABLE_REQUEST_VIEW_GET_VALUES]]
	    for x in msgs:
		if x:print x,self.g.ProcessTableMessage(wg.GridTableMessage(self,*x))
            h,w=self.g.GetSize()
            self.g.SetSize((h+1, w))
            self.g.SetSize((h, w))
            self.g.ForceRefresh()
            self.g.AutoSizeColumns()
            self.g.EndBatch()
class P(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1,style=wx.NO_FULL_REPAINT_ON_RESIZE)
	g=self.g=Tgrid(self,-1,(0,0),(150,250),wx.NO_BORDER|wx.WANTS_CHARS)
        ht=HugeTable(g,[range(2) for x in range(3)])
        g.SetTable(ht, True)
	b=wx.Button(self,-1,'ReGrid')
	box = wx.BoxSizer(wx.VERTICAL)
	box.Add(b,0,wx.EXPAND)
        b.SetDefault()
        b.SetSize(b.GetBestSize())
	box.Add(g,0,wx.EXPAND)
        self.SetSizerAndFit(box)	
        self.Bind(wx.EVT_BUTTON, self.OnClick, b)
    def OnClick(self, event):
	t=self.g.GetTable()
	z=t.rc()[0]+1
        t.ResetView([range(z) for x in range(z)])
class F(wx.Frame):
    def __init__(self, parent, id=-1, title="", pos=wx.DefaultPosition,
                 size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE |
wx.SUNKEN_BORDER | wx.CLIP_CHILDREN):
        wx.Frame.__init__(self, parent, id, title, pos, size, style)
	self.panel = P(self)
class App(wx.App):
    def OnInit(self):
        self.RestoreStdio()
        frame = F(None, wx.ID_ANY, "wx.aui wxPython Demo")
        frame.Show(1)
        self.SetTopWindow(frame)
        return 1
if __name__ == '__main__':
    app=App()
    app.MainLoop()




More information about the wxpython-users mailing list