why is OnCreate not called?

Hi, all

I found that wx.EVT_WINDOW_CREATE of wx.Dialog can not be handled. You can try my code here. And I use python2.4, wxpython2.6.3.2. Is this a bug?

···

#========================================
import wx

class MyDialog(wx.Dialog):
    def __init__(self, *args, **kwds):
        wx.Dialog.__init__(self, *args, **kwds)
        self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)
        print '__init__'
    def OnCreate(self, evt):
        #why is OnCreate not called?
        print 'OnCreate'

def main():
    app = wx.PySimpleApp(0)
    dlg = MyDialog(None, -1, title = '')
    dlg.ShowModal()
    app.SetTopWindow(dlg)
    app.MainLoop()

if __name__ == "__main__":main()
#========================================

bruce.who.hk
2006-09-11

bruce.who.hk wrote:

Hi, all

I found that wx.EVT_WINDOW_CREATE of wx.Dialog can not be handled.
You can try my code here. And I use python2.4, wxpython2.6.3.2. Is
this a bug?

No, it is just dependent on platform. On MSW and Mac the creation of
the UI object happens inside the __init__, so the event can only be
caught via static event tables, which can not be used from Python. By
the time you are able to call Bind the event has already happened.

On GTK the creation of the UI object doesn't happen until the next time
commands are flushed out to the X-Server and so it will happen sometime
after the __init__.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!