[wxPython] Connecting Buttons with xrc resourcefiles

Hi,

I've just started with wxPython and had some success in making my
application work by manually building dialogs and frames in my code.
However I wish to use the new xrc files in a vain attempt to improve the
managability of my code.

I have managed to make my dialog open by using the following snippet of
code. You can also see my bindings to two buttons. However at the moment
these do nothing. (IE the event isn't recieved)

   res = wxXmlResource("Resources/dialogs.xrc")
  res.InitAllHandlers()
  self.logindialog = res.LoadDialog(self,'LoginDialog')
        # Button Events
        EVT_BUTTON(self, XMLID('cancelbutton'),self.cancel)
        EVT_BUTTON(self, XMLID('connectbutton'),self.jabconnect)
        
        # Dialog generation stuff
        self.logindialog.SetAutoLayout(true)
        self.logindialog.ShowModal()
       
Have I done something completely stupid? If so please point it out.

Many Thanks

Mike Albon

I have managed to make my dialog open by using the following snippet of
code. You can also see my bindings to two buttons. However at the moment
these do nothing. (IE the event isn't recieved)

  res = wxXmlResource("Resources/dialogs.xrc")
res.InitAllHandlers()
self.logindialog = res.LoadDialog(self,'LoginDialog')
        # Button Events
        EVT_BUTTON(self, XMLID('cancelbutton'),self.cancel)
        EVT_BUTTON(self, XMLID('connectbutton'),self.jabconnect)

        # Dialog generation stuff
        self.logindialog.SetAutoLayout(true)
        self.logindialog.ShowModal()

Have I done something completely stupid? If so please point it out.

Since you are creating a dialog, you should hook the events to the dialog
instead of self. This is because command events will only go up to the
nearest top-level window and then stop.

···

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