wxGrid, PyGridTableBase, strange SWIG error message!

L

Laszlo Nagy

I'm trying to create a special widget that is a wx.Grid and also a
PyGridTableBase. In my special case of application, I really need to
have a grid that uses itself for getting cell data and cell attributes.

Here is a test program, demonstrating my problem:

import wx
from wx.grid import Grid,PyGridTableBase

class SpecialGrid(Grid,PyGridTableBase):
def __init__(self,*args,**kwargs):
PyGridTableBase.__init__(self)
Grid.__init__(self,*args,**kwargs)
self.SetTable(self)

def SetTable(self,table):
if table is not self:
raise Exception("Grid must be its own table!")
else:
PyGridTableBase.SetTable(self,self,takeOwnership=False)

app=wx.App(redirect=None)
frame=wx.Frame(None)
g = SpecialGrid(parent=frame)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(g,1,wx.EXPAND)
frame.SetSizer(sizer)
frame.Show()
frame.Maximize()
app.MainLoop()


This program throws:

Traceback (most recent call last):
File "test.py", line 18, in <module>
g = SpecialGrid(parent=frame)
File "test.py", line 6, in __init__
PyGridTableBase.__init__(self)
File
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/grid.py", line
910, in __init__
self._setOORInfo(self);PyGridTableBase._setCallbackInfo(self, self,
PyGridTableBase)
File
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line
3886, in _setOORInfo
val = _core_.EvtHandler__setOORInfo(*args, **kwargs)
TypeError: in method 'EvtHandler__setOORInfo', expected argument 1 of
type 'wxEvtHandler *'

This makes no sense to me. If I swap the constructor calls:

def __init__(self,*args,**kwargs):
Grid.__init__(self,*args,**kwargs)
PyGridTableBase.__init__(self)
self.SetTable(self)

Then I get this:

Traceback (most recent call last):
File "test.py", line 18, in <module>
g = SpecialGrid(parent=frame)
File "test.py", line 7, in __init__
PyGridTableBase.__init__(self)
File
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/grid.py", line
910, in __init__
self._setOORInfo(self);PyGridTableBase._setCallbackInfo(self, self,
PyGridTableBase)
File
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line
3887, in _setOORInfo
args[0].this.own(False)
File
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line
14586, in __getattr__
raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the SpecialGrid object has
been deleted, attribute access no longer allowed.

What the heck?

Thanks,

Laszlo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top