Skip to content

wxPython 4.1 does not propagate MouseWheel event with WxAgg #17513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
michaelmarty opened this issue May 26, 2020 · 5 comments
Closed

wxPython 4.1 does not propagate MouseWheel event with WxAgg #17513

michaelmarty opened this issue May 26, 2020 · 5 comments
Labels

Comments

@michaelmarty
Copy link

Bug report

Bug summary

wxPython 4.1 is not propagating MouseWheel events with the WxAgg backend. The events seem to stop within the matplotlib canvas. Other wxPython controls are propagating it correctly with version wxPython 4.1, and everything works fine with wxPython 4.0.7.

Code for reproduction

import wx
import wx.lib.scrolledpanel as scrolled
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure

class PlottingWindow2(wx.Window):
    def __init__(self, *args, **kwargs):
        wx.Window.__init__(self, *args, **kwargs)
        self.figure = Figure(figsize=(6, 5))
        self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
        self.Bind(wx.EVT_SIZE, self.size_handler)
        self.Bind(wx.EVT_MOUSEWHEEL, self.on_wheel)
        self.canvas.mpl_connect('scroll_event', self.on_scroll)

    def size_handler(self, *args, **kwargs):
        self.canvas.SetSize(self.GetSize())

    def on_scroll(self, event):
        print("MPL Scroll")

    def on_wheel(self, event):
        print("Canvas Scroll")
        event.Skip()

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(400, 400))
        plotwindow = scrolled.ScrolledPanel(self, -1)
        sizerplot = wx.BoxSizer(wx.VERTICAL)
        self.plot1 = PlottingWindow2(plotwindow)
        sizerplot.Add(self.plot1, 0, flag=wx.EXPAND)
        plotwindow.SetSizer(sizerplot)
        plotwindow.SetupScrolling()
        plotwindow.Bind(wx.EVT_MOUSEWHEEL, self.onWheel)
        self.Show(True)

    def onWheel(self, event):
        print("WX Scroll")
        event.Skip()

app = wx.App(False)
frame = MyFrame(None, "Test")
app.MainLoop()

Actual outcome

With wxPython 4.1.0, the scrolling does not work, and the console output is:

MPL Scroll

Note: the event does not propagate up. Other wxPython items like text controls propagate correctly.

Expected outcome

With wxPython 4.0.7, the scrolling works, and the console output is:

MPL Scroll
Canvas Scroll
WX Scroll

Note: the event propagates up correctly.

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.2.1
  • Matplotlib backend (print(matplotlib.get_backend())): WxAgg
  • Python version: 3.7.7
  • Other libraries: wxPython 4.1.0 msw (phoenix) wxWidgets 3.1.4

Installed from pip

@tacaswell
Copy link
Member

What changed between wxPython 4.0 and 4.1? Was there an intentional change on the wxPython side that we need to accommodate or is this a bug in wxPython?

@tacaswell tacaswell added this to the unassigned milestone May 26, 2020
@QuLogic
Copy link
Member

QuLogic commented May 26, 2020

We call event.Skip() in all handlers, so it seems like this would be a bug in wxPython.

@michaelmarty
Copy link
Author

Thanks for your quick responses. I am not sure what changed on the wxPython side to cause this. Here are the release notes if that is helpful: https://wxpython.org/news/2020-04-24-wxpython-410-release/index.html. The most significant change seems to be tracking a different wxWidgets branch.

The event.Skip() works correctly with wxPython objects like text controls, but it doesn't seem to be working properly with matplotlib objects. I tried to add in event.guiEvent.Skip() in the on_scroll function in the example, and it didn't seem to make a difference.

@DietmarSchwertberger
Copy link
Contributor

See #22211
Adding del event.guiEvent should fix this issue, in order not to keep a reference to the GUI event object.

@michaelmarty
Copy link
Author

I can confirm that this fixes it. Recommend that we make this change on the matplotlib permanent. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants