Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#31 Event binding (with notebooks)


Is it possible to have the Python code generation bind the event to the control, rather than the form?

When I have a notebook with several pages, all the buttons become bound to the same event handler, even though more than one event handler is specified
for the buttons.

I have to use objectIDs as I have a large number of buttons calling each handler. The current arrangement makes it tricky to maintain.


The following code is generated.

    self.Bind(wx.EVT_TOGGLEBUTTON, self.OnPulEnableToggle, id=1)
    self.Bind(wx.EVT_TOGGLEBUTTON, self.OnPulEnableToggle, id=2)
    self.Bind(wx.EVT_TOGGLEBUTTON, self.OnPulEnableToggle, id=3)

    self.Bind(wx.EVT_TOGGLEBUTTON, self.OnRecEnableToggle, id=1)
    self.Bind(wx.EVT_TOGGLEBUTTON, self.OnRecEnableToggle, id=2)
    self.Bind(wx.EVT_TOGGLEBUTTON, self.OnRecEnableToggle, id=3)

meaning only OnRecEnableToggle() is called.

Now, of course I can specify different IDs for each page, but that seems
silly when it could just bind the event to the button, thus:

    self.pul_enable_1 = wx.ToggleButton(self.PulserPane, 1, "Disabled")
    self.pul_enable_2 = wx.ToggleButton(self.PulserPane, 2, "Disabled")
    self.pul_enable_3 = wx.ToggleButton(self.PulserPane, 3, "Disabled")

    self.rec_enable_1 = wx.ToggleButton(self.ReceiverPane, 1, "ENABLED")
    self.rec_enable_2 = wx.ToggleButton(self.ReceiverPane, 2, "ENABLED")
    self.rec_enable_3 = wx.ToggleButton(self.ReceiverPane, 3, "ENABLED")

    self.pul_enable_1.Bind(wx.EVT_TOGGLEBUTTON, self.OnPulEnableToggle)
    self.pul_enable_2.Bind(wx.EVT_TOGGLEBUTTON, self.OnPulEnableToggle)
    self.pul_enable_3.Bind(wx.EVT_TOGGLEBUTTON, self.OnPulEnableToggle)

    self.rec_enable_1.Bind(wx.EVT_TOGGLEBUTTON, self.OnRecEnableToggle)
    self.rec_enable_2.Bind(wx.EVT_TOGGLEBUTTON, self.OnRecEnableToggle)
    self.rec_enable_3.Bind(wx.EVT_TOGGLEBUTTON, self.OnRecEnableToggle)

After all, it is still possible to pass the event on downto the form if
requred using Skip()


  • Logged In: YES
    Originator: NO

    First of all, sorry for the very long delay of my reply.
    Anyway, I see the problem and I'll put it on my TODO list. I will do it for python output, and it's likely to be done for perl as well, but not for C++ (as the event-binding code for C++ is based on event tables, so it would be much a bigger change...)