Robin Dunn writes:
2. Use a Mix-in class that does not derive from wxWindow (or
perhaps not from anything at all) but just expects that it
will be combined with a class that does derive from wxWindow.
That way it can do everything it needs to with self as if it
was a Window (EVT binders, call methods, etc.) Then just
derive a new class that mutiply inherits from wxWhatever and
your mix-in, and the __init__ will just call the
wxWhatever.__init__ and theen Mixin.__init__ as normal.
Hmm. I had actually tried this, but with Python's new-style
classes. It appears to only work with old-style classes.
# -- begin sample - this example works
import wx
class TestMixin:
def __init__(self):
print self.GetClassName()
class TestTextCtrl(wx.TextCtrl, TestMixin):
def __init__(self, fraime):
wx.TextCtrl.__init__(self, frame, wx.NewId())
TestMixin.__init__(self)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, '')
object = TestTextCtrl(frame)
frame.Show(1)
app.MainLoop()
# -- end sample
If I change line 3 to:
class TestMixin(object):
I get the following:
[pmcnett@sol classes]$ python testmixin.py
Traceback (most recent call last):
File "testmixin.py", line 16, in ?
object = TestTextCtrl(frame)
File "testmixin.py", line 9, in __init__
wx.TextCtrl.__init__(self, frame, wx.NewId())
File "/usr/lib/python2.3/site-packages/wxPython/controls.py", line 805, in __init__
self._setOORInfo(self)
File "/usr/lib/python2.3/site-packages/wxPython/windows.py", line 60, in _setOORInfo
val = windowsc.wxEvtHandler__setOORInfo(self, *_args, **_kwargs)
TypeError: Type error in argument 1 of wxEvtHandler__setOORInfo. Expected _wxEvtHandler_p.
[pmcnett@sol classes]$
Anyway, thanks Robin! I'll just use the old-style classes, and
I have everything I desired. Now, I finally understand the term
"mixin". <g>
···
--
Paul