开发者

wxPython GridSizer.Add() not working for custom control

I'm trying to create a custom control based on wx.richtext.RichTextCtrl and I'm running into a problem. Whenever I attempt to add the custom control to a sizer, wxPython chokes with the error

Traceback (most recent call last):
  File "pyebook.py", line 46, in <module>
    frame = MainFrame(None, 'pyebook')
  File "pyebook.py", line 14, in __init__
    self.mainPanel.GetSizer().Add(ReaderControl(self.mainPanel), 1, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  File "/usr/local/lib/wxPython-unicode-2.8.11.0/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 12685, in Add
    return _core_.Sizer_Add(*args, **kwargs)
TypeError: wx.Wind开发者_开发百科ow, wx.Sizer, wx.Size, or (w,h) expected for item

The custom control is at this time extremely simple and looks like this

class ReaderControl(wx.richtext.RichTextCtrl):
    def __init__(self, parent, id=-1, value=''):
        wx.richtext.RichTextCtrl(parent, id, value, style=wx.richtext.RE_READONLY, name='ReaderControl')

The code I'm using to add the control to the sizer is:

self.mainPanel.GetSizer().Add(ReaderControl(self.mainPanel), 1, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

Any ideas what I'm doing wrong here?


I think you need to call __ init __ explicitly, so you can pass in 'self'. Otherwise, you are just creating a new instance of RichTextCtrl, not initialising your subclass properly.

IOW:

class ReaderControl(wx.richtext.RichTextCtrl):
    def __init__(self, parent, id=-1, value=''):
        wx.richtext.RichTextCtrl.__init__(self, parent, id, value, style=wx.richtext.RE_READONLY, name='ReaderControl'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜