EVT_BUTTON fires twice on frame

Christopher Barker escribió:

Oswaldo Hernández wrote:

Yes, if I quit Skip() or put StopPropagation() the example also works fine in my system, but I think that there is a problem. If the frame be a derivarion of anohter class that also bind the event, we lock the event for these class.

How often would you want to have the superclass binding for your button to also be used? Also, in this case, you've created that button that fires that event, there is no way for a superclass to have bound it.

I want use it, here an example:

import wx
class MasterFrame(wx.Frame):
     def __init__(self, *args, **kwds):
         wx.Frame.__init__(self, *args, **kwds)
         self.BtnOK = wx.Button(self, -1, "OK")
         self.Bind(wx.EVT_BUTTON, self.OnMasterOK, self.BtnOK)

     def OnMasterOK(self, event):
         # do generic operations
         print "Master OK, Commit database, save frame state, ..."
         event.Skip()

class LocalFrame(MasterFrame):
     def __init__(self, *args, **kwds):
         kwds["style"] = wx.DEFAULT_DIALOG_STYLE
         MasterFrame.__init__(self, *args, **kwds)
         self.SetTitle("Frame")
         self.Bind(wx.EVT_BUTTON, self.OnLocalOK, self.BtnOK)

     def OnLocalOK(self, event):
         # do local operatios
         print "Local OK"
         event.Skip()

if __name__ == "__main__":
     app = wx.PySimpleApp(0)
     wx.InitAllImageHandlers()
     mf = LocalFrame(None)
     mf.Show()
     app.MainLoop()

When run the example and click OK, the output in my system is:

Local OK
Master OK, Commit database, save frame state, ...
Local OK
Master OK, Commit database, save frame state, ...

The events are fired twice.

The real status of class are more complex and I don't want quit the calls to Skip().

You tell that in wxGTK works fine, perhaps the problem is Windows.

···

--
*****************************************
Oswaldo Hernández
oswaldo@soft-com.es
*****************************************