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
--
http://mail.python.org/mailman/listinfo/python-list