I have created a set of visual proxies that know how to attach themselves to data elements. The code required in the __init__ (constructor) is the same for all of these proxies. It seemed like a good idea, therefore, to factor out this code and put it into a mix-in class that could be added to each control.
When I use multiple inheritance, however, it seems that wxPython classes do not like the new (Python 2.2) classes. For example, the following code will run just fine:
···
#=====================================================
from wxPython.wx import *
class A:
def __init__(self, element):
self.var = element
class MyTextCtrl(wxTextCtrl, A):
def __init__(self, element, *args, **kwargs):
wxTextCtrl.__init__(self, *args, **kwargs)
A.__init__(self, element)
class TopWin(wxFrame):
def __init__(self, parent=None, id=-1,
title='multiple inheritance'):
wxFrame.__init__(self, parent, id, title)
panel = wxPanel(self, -1)
t1 = MyTextCtrl('hi', panel, -1)
class App(wxApp):
def OnInit(self):
top = TopWin()
top.Show(true)
self.SetTopWindow(top)
return true
if __name__ == '__main__':
app = App(0)
app.MainLoop()
#====================================================
But when I change class A to a "new class" by deriving from object:
class A(object):
def __init__(self, element):
self.var = element
the following error shows up on the traceback:
File "C:\Python22\lib\site-packages\wxPython\windows.py", line 58, in _setOORInfo
val = apply(windowsc.wxEvtHandler__setOORInfo,(self,) + _args, _kwargs)
TypeError: Type error in argument 1 of wxEvtHandler__setOORInfo. Expected _wxEvtHandler_p.
Is there any way to mix-in "new classes" with wxPython classes? Thanks.
Donnal Walter
Arkansas Children's Hospital