Skip to content

Reversing unbind order breaks the event chain link and makes the program crash. #2027

@komoto48g

Description

@komoto48g

Operating system: Windows 10 64bit ver 20H2
wxPython version & source: 4.1.1 (pypi)
Python version & source: 3.8.6

Description of the problem:
In the sample code, the button object only binds and unbinds the two handlers. If the unbinding order is reversed, the program will crash. I also checked it with wx.version 4.0.7, and there was no problem.

Code Example (click to expand)
import wx

class TestPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        
        self.btn = wx.Button(self, label="Hello, wxPython!")
        
        self.btn.Bind(wx.EVT_BUTTON, self.onButton1)
        self.btn.Bind(wx.EVT_BUTTON, self.onButton2)
        
        if 0:
            ## no problem
            self.btn.Unbind(wx.EVT_BUTTON, handler=self.onButton2)
            self.btn.Unbind(wx.EVT_BUTTON, handler=self.onButton1)
        else:
            ## eversing the unbind order will break the linkage of the event chain
            self.btn.Unbind(wx.EVT_BUTTON, handler=self.onButton1)
            self.btn.Unbind(wx.EVT_BUTTON, handler=self.onButton2)
    
    def onButton1(self, evt):
        print(1)
        evt.Skip()
    
    def onButton2(self, evt):
        print(2)
        evt.Skip()

app = wx.App()
frm = wx.Frame(None)
frm.panel = TestPanel(frm)
frm.Show()
app.MainLoop()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions