vlachoudis / bCNC

GRBL CNC command sender, autoleveler and g-code editor
GNU General Public License v2.0
1.54k stars 528 forks source link

Fix mouse wheel zooming in both directions on Mac #1678

Open fedulvtubudul opened 2 years ago

fedulvtubudul commented 2 years ago

This PR fixes https://github.com/vlachoudis/bCNC/issues/804

Here is original zoom wheel handler code:

def wheel(self, event):
    self.zoomCanvas(event.x, event.y, pow(ZOOM,(event.delta//120)))

event.delta equals -1 (scroll up) or 1 (scroll down) on my setup (MacOS 12.2.1, Logitech MX 3 mouse, medium scrolling speed in system settings, "natural" scroll direction). In Python 2 rounding goes away from zero, so event.delta//120 gives either 1 or -1, which is OK. But running in Python 3.9, event.delta//120 results -1 or 0. That why only one zooming direction works.

I propose a fix that seems compatible both with Python 2 and 3 and should not break or change scrolling behavior.

Harvie commented 2 years ago

Thank you for this fix. I hope few other users can test this and share their experience with fix as well. If i remember correctly, i've merged similar thing some time ago and it ended up breaking zoom for some of the users (while fixing it for others). So i will test it myself on ArchLinux/X11 and hopefully we can get feedback from users on other platforms as well.

Harvie commented 1 year ago

Ok thanks, can you please resolve the conflicts, so we can merge?