button event handler not being called

I just can't figure it out why the event handler for either of these buttons are being called.

         self.close = wx.Button(id=wx.ID_OK, label=u'Close and continue',
               name=u'close', parent=self, pos=wx.Point(192, 155),
               size=wx.Size(100, 23), style=0)
         self.close.Bind(wx.EVT_BUTTON, self.OnCloseButton,
               id=wxID_DIALOGPURCHASESELCLOSE)

         self.button1 = wx.Button(id=wx.ID_OK, label=u'Close and continue',
               name='button1', parent=self, pos=wx.Point(0, 180),
               size=wx.Size(100, 23), style=0)
         self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
               id=wxID_DIALOGPURCHASESELBUTTON1)

     def OnCloseButton(self, event):
         print 'close'
         self.Close()

     def OnButton1Button(self, event):
         print 'button1'
         self.Close()
         event.Skip()

Using WIT I can see that the event fires but the handler is never called.

I have other dialogs very similar to this one which just work fine but can't figure out why this one does not work.

Appreciate any tips

Werner

Hi,

I just can't figure it out why the event handler for either of these buttons
are being called.

   self\.close = wx\.Button\(id=wx\.ID\_OK, label=u'Close and continue',
         name=u'close', parent=self, pos=wx\.Point\(192, 155\),
         size=wx\.Size\(100, 23\), style=0\)

Your Button has ID_OK

   self\.close\.Bind\(wx\.EVT\_BUTTON, self\.OnCloseButton,
         id=wxID\_DIALOGPURCHASESELCLOSE\)

Your binding to wxID_DIALOGPURCHASESELCLOSE

   self\.button1 = wx\.Button\(id=wx\.ID\_OK, label=u'Close and continue',
         name='button1', parent=self, pos=wx\.Point\(0, 180\),
         size=wx\.Size\(100, 23\), style=0\)
   self\.button1\.Bind\(wx\.EVT\_BUTTON, self\.OnButton1Button,
         id=wxID\_DIALOGPURCHASESELBUTTON1\)

Ditto

Cody

···

On Sun, Mar 20, 2011 at 10:48 AM, werner <wbruhin@free.fr> wrote:

Cody,

···

On 20/03/2011 17:16, Cody Precord wrote:

Hi,

On Sun, Mar 20, 2011 at 10:48 AM, werner<wbruhin@free.fr> wrote:

I just can't figure it out why the event handler for either of these buttons
are being called.

        self.close = wx.Button(id=wx.ID_OK, label=u'Close and continue',
              name=u'close', parent=self, pos=wx.Point(192, 155),
              size=wx.Size(100, 23), style=0)

Your Button has ID_OK

        self.close.Bind(wx.EVT_BUTTON, self.OnCloseButton,
              id=wxID_DIALOGPURCHASESELCLOSE)

Your binding to wxID_DIALOGPURCHASESELCLOSE

        self.button1 = wx.Button(id=wx.ID_OK, label=u'Close and continue',
              name='button1', parent=self, pos=wx.Point(0, 180),
              size=wx.Size(100, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_DIALOGPURCHASESELBUTTON1)

Ditto

Yeap, that is the it.

Thanks a lot, just didn't see this or make the connection.

Werner

When binding directly to the button I usually leave out the id or source parameters. The event delivered to the button can only be coming from that button so there is no need to identify it specifically. Saves a few keystrokes when typing the code, and incedentally would have avoided this eye-of-the-beholder bug as well.

···

On 3/20/11 9:23 AM, werner wrote:

Cody,

On 20/03/2011 17:16, Cody Precord wrote:

Hi,

On Sun, Mar 20, 2011 at 10:48 AM, werner<wbruhin@free.fr> wrote:

I just can't figure it out why the event handler for either of these
buttons
are being called.

self.close = wx.Button(id=wx.ID_OK, label=u'Close and continue',
name=u'close', parent=self, pos=wx.Point(192, 155),
size=wx.Size(100, 23), style=0)

Your Button has ID_OK

self.close.Bind(wx.EVT_BUTTON, self.OnCloseButton,
id=wxID_DIALOGPURCHASESELCLOSE)

Your binding to wxID_DIALOGPURCHASESELCLOSE

self.button1 = wx.Button(id=wx.ID_OK, label=u'Close and continue',
name='button1', parent=self, pos=wx.Point(0, 180),
size=wx.Size(100, 23), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=wxID_DIALOGPURCHASESELBUTTON1)

Ditto

Yeap, that is the it.

--
Robin Dunn
Software Craftsman