[wxPython-users] [wxpython-users]Question about
wx.EVT_WINDOW_CREATE and post-initializatons
Robin Dunn
robin at alldunn.com
Thu Sep 13 12:05:52 PDT 2007
甜瓜 wrote:
> I am using XRC to generate py GUI code. Simply a wxFrame.
>
> class MyFrame(xrcMAINFRAME):
> def __init__(self, parent):
> xrcMAINFRAME.__init__(self, parent)
> self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)
>
> I want to do some post-initializatons in self.OnCreate, but,
> strangely, it was never called. Why cannot the frame capture
> wx.EVT_WINDOW_CREATE?
Because by the time you do the binding the create event has already been
sent. It looks like you are using the code generated by XRCed/pywxrc,
so you can override the PreCreate method and put your binding there.
>
> 2. If I want to do some post-initializatons JUST AFTER all widgets are
> created and shown up?
> My work around now is bind EVT_SHOW of the mainframe and use a boolean
> flag to ensure post-initialization only once. Is there any better and
> standard method for my purpose?
That is as good as any other way to do it.
>
> 3. How to invoke a menu_item_click in program?
> eg: self.Bind(wx.EVT_MENU, self.OnInit, mainmenu.IDM_INIT)
> If the post-initialization is automatically call a menu handler
> self.OnInit, how to trigger it in program? In Win32 API, I can use:
> SendMessage(hwnd, ....) , how about wxPython?
Why not just call self.OnInit(None) ? Otherwise you have to create a
wx.CommandEvent with a type of wx.EVT_MENU.typeId, and an ID of
mainmenu.IDM_INIT.GetId() and send it to the frame with
frame.GetEventHandler().ProcessEvent(event). Personally I think just
calling the method is a tad bit easier. ;-)
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list