napari: AttributeError: type object 'QEvent' has no attribute 'PinchGesture' on Apple laptop trackpad

šŸ› Bug

When I make the pinch gesture on my Apple laptop’s trackpad (usually on accident), I receive the type object 'QEvent' has no attribute 'PinchGesture error below

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/opt/miniconda3/envs/napari-test/lib/python3.8/site-packages/vispy/app/backends/_qt.py in event(self=, ev=)
    572             self._vispy_canvas.events.touch(type='end')
    573         if t == qt_event_types.Gesture:
--> 574             gesture = ev.gesture(qt_event_types.PinchGesture)
        gesture = undefined
        ev.gesture = 
        qt_event_types.PinchGesture = undefined
    575             if gesture:
    576                 (x, y) = _get_qpoint_pos(gesture.centerPoint())

AttributeError: type object 'QEvent' has no attribute 'PinchGesture'

To Reproduce

Steps to reproduce the behavior:

  1. Open napari on a Mac laptop
  2. Make a ā€œpinchā€ (bring two fingers together on the trackpad) in the canvas

Expected behavior

The gesture is silently ignored.

Environment

Instalation:

# fresh python 3.8 conda env
pip install --pre 'napari[all]'

napari: 0.4.11rc2 Platform: macOS-10.15.7-x86_64-i386-64bit System: MacOS 10.15.7 Python: 3.8.11 (default, Aug 6 2021, 08:56:27) [Clang 10.0.0 ] Qt: 5.15.2 PyQt5: 5.15.4 NumPy: 1.21.2 SciPy: 1.7.1 Dask: 2021.08.1 VisPy: 0.8.0

OpenGL:

  • GL version: 2.1 INTEL-14.7.17
  • MAX_TEXTURE_SIZE: 16384

Screens:

  • screen 1: resolution 1440x900, scale 2.0

Plugins:

  • console: 0.0.3
  • scikit-image: 0.4.11rc2
  • svg: 0.1.5

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

VisPy 0.8.1 is out on PyPI now. Conda-forge package should be out later today.

Amazing! Thank you for the quick fix, @djhoese !

VisPy 0.8.1 is out on PyPI now. Conda-forge package should be out later today.

Sorry, I think I wasn’t super clear about how this manifests in napari. It could be that I am super clumsy, but when I am interacting with a 3D image using my trackpad, I accidentally make the ā€œpinchā€ gesture fairly often. While we haven’t hooked anything up to this gesture in napari, this raises the AttributeError described above (I’m not sure if we could do something with our implementation to prevent this). In light of this, I’ve made a small PR to exclude 0.8.0 for now.

Thanks again for the quick fix, @djhoese !

As a non-napari dev or contributor even, my opinion is that you shouldn’t put the work in to limit against 0.8.0. This was a small bug that was only run into by accident for an event type that isn’t even currently used by napari (from my understanding).

do you think we should exclude vispy 0.8.0 from the requirements just to be safe or leave it as is. If it’s the latter, we can close this issue.

I don’t have strong feelings, maybe might as well make a PR to exclude. Would be a shame for someone to be on 0.8.0 when they could just as easily now be on 0.8.1 and have it work

see this little bit here: https://www.riverbankcomputing.com/static/Docs/PyQt5/gotchas.html#enums

tldr: starting with sip v4.19.9 (around PyQt 5.11) all enums are now scoped, and starting in PyQt6, the backwards compatibility allowing enums to be accessed in their top level namespace has been removed (so there may be a few more of these lurking around). If you’re still supporting < 5.11, you need to deal with this yourself (libs like qtpy can help) … otherwise, the scoped variants can be used all over the place. (i.e. prefer Qt.GestureType.PinchGesture over Qt.PinchGesture even if you’re on 5.12)

I have to help a user with microscope today, but I’ll try to clone my env and update vispy see what happens.