Skip to content

fix: handle qmods like QT5 for pyside6 not 6.4#179

Merged
tlambert03 merged 2 commits intopyapp-kit:mainfrom
psobolewskiPhD:pyside_631_support
Mar 18, 2024
Merged

fix: handle qmods like QT5 for pyside6 not 6.4#179
tlambert03 merged 2 commits intopyapp-kit:mainfrom
psobolewskiPhD:pyside_631_support

Conversation

@psobolewskiPhD
Copy link
Copy Markdown
Contributor

@psobolewskiPhD psobolewskiPhD commented Mar 17, 2024

We're trying to Goldilocks a pyside6 version for napari tests.
Recently (napari/napari#6738) when testing with pyside6 6.3.1, we got this failure:
https://github.com/napari/napari/actions/runs/8303510051/job/22727974608?pr=6738#step:12:209

Traceback (most recent call last):
    File "/home/runner/work/napari/napari/napari/_qt/widgets/qt_keyboard_settings.py", line 685, in keyPressEvent
      kb = qkeysequence2modelkeybinding(event_keyseq)
    File "/home/runner/work/napari/napari/.tox/py39-linux-pyside6-cov/lib/python3.9/site-packages/app_model/backends/qt/_qkeymap.py", line 316, in qkeysequence2modelkeybinding
      parts = [SimpleKeyBinding.from_int(qkeycombo2modelkey(x)) for x in iter(key)]
    File "/home/runner/work/napari/napari/.tox/py39-linux-pyside6-cov/lib/python3.9/site-packages/app_model/backends/qt/_qkeymap.py", line 316, in <listcomp>
      parts = [SimpleKeyBinding.from_int(qkeycombo2modelkey(x)) for x in iter(key)]
    File "/home/runner/work/napari/napari/.tox/py39-linux-pyside6-cov/lib/python3.9/site-packages/app_model/backends/qt/_qkeymap.py", line 308, in qkeycombo2modelkey
      qmods = _get_qmods(key)
    File "/home/runner/work/napari/napari/.tox/py39-linux-pyside6-cov/lib/python3.9/site-packages/app_model/backends/qt/_qkeymap.py", line 85, in _get_qmods
      return key.keyboardModifiers()
  AttributeError: 'int' object has no attribute 'keyboardModifiers'

In this PR, for versions of pyside6 before 6.4, just use the QT5 handling.
I tested locally with pyside 6.3.1, and latest, as well as pyqt6 6.3.1 and latest.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (03f5e1a) to head (a9e7265).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #179   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           31        31           
  Lines         1785      1786    +1     
=========================================
+ Hits          1785      1786    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@psobolewskiPhD psobolewskiPhD changed the title handle qmods like QT5 for pyside6 not 6.4 Fix: handle qmods like QT5 for pyside6 not 6.4 Mar 17, 2024
@tlambert03 tlambert03 changed the title Fix: handle qmods like QT5 for pyside6 not 6.4 fix: handle qmods like QT5 for pyside6 not 6.4 Mar 18, 2024
@tlambert03
Copy link
Copy Markdown
Member

works for me.

fwiw, i think the underlying cause here is the fact that the behavior of QKeySequence.__iter__ (called here) is changing. Another way to fix this would be, in qkeycombo2modelkey, to use:

if isinstance(key, int):
    key = QKeyCombination.fromCombined(key)

which is a generic (Qt6+) way to cast an integer to a QKeyCombination. but i'll add more qt version testing in a follow up PR and consider a change then. Thanks @psobolewskiPhD

@tlambert03 tlambert03 merged commit fb3d23b into pyapp-kit:main Mar 18, 2024
@psobolewskiPhD psobolewskiPhD deleted the pyside_631_support branch March 18, 2024 01:05
@tlambert03 tlambert03 added the bug Something isn't working label Mar 18, 2024
@tlambert03
Copy link
Copy Markdown
Member

@psobolewskiPhD, we're now testing everything from Qt 5.15; 6.2-6.6 #180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Development

Successfully merging this pull request may close these issues.

2 participants