Skip to content

Fixes for API changes in Qt#2248

Closed
campagnola wants to merge 3 commits intopyqtgraph:masterfrom
campagnola:masked-mouse
Closed

Fixes for API changes in Qt#2248
campagnola wants to merge 3 commits intopyqtgraph:masterfrom
campagnola:masked-mouse

Conversation

@campagnola
Copy link
Copy Markdown
Member

In my most recent environment (PyQt5 5.12.3 Qt 5.12.9), I started seeing errors in comparisons between MouseButton and MouseButtons (we used to be able to use & to determine whether a MouseButton was included in a MouseButtons, but now this generates TypeError: unsupported operand type(s) for &: 'MouseButton' and 'MouseButtons').

This PR fixes a few instances of this comparison, plus a similar comparison between KeyboardModifier and KeyboardModifiers.

Also snuck in a fix for the HDF5 exporter; seems like importlib.util is no longer imported by default.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 8, 2022

I may be remembering wrong, but int casting I don't think is a reliable way anymore to handle the enum/flags in newer versions of Qt.

I'd have to dig into the library to figure out what we do elsewhere.

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Apr 9, 2022

I am not getting the error though.
Putting MouseButtons on the left hand side seems to allow avoiding the deprecation warning (on Python 3.8).
The resulting expression can be used where a boolean is needed.

In [21]: QtCore.PYQT_VERSION_STR
Out[21]: '5.12.3'

In [22]: MB = QtCore.Qt.MouseButton

In [23]: btns = MB.LeftButton | MB.RightButton

In [24]: btns & MB.LeftButton
Out[24]: <PyQt5.QtCore.Qt.MouseButtons at 0x204a452c820>

In [25]: MB.LeftButton & btns
<ipython-input-25-27340288dfca>:1: DeprecationWarning: an integer is required (got type MouseButtons).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
  MB.LeftButton & btns
Out[25]: <PyQt5.QtCore.Qt.MouseButtons at 0x204a4495580>

In [26]: bool(btns & MB.LeftButton)
Out[26]: True

In [27]: bool(btns & MB.MiddleButton)
Out[27]: False

@campagnola
Copy link
Copy Markdown
Member Author

Closing in favor of #2250

@campagnola campagnola closed this Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants