Skip to content
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

Add support for PyQt6 and PySide6 (<6.4) to Qt backends #2318

Merged
merged 7 commits into from
Oct 17, 2022

Conversation

astrofrog
Copy link
Member

Work in progress!

@dhomeier
Copy link
Collaborator

@astrofrog I have added CI envs for PyQt6 and PySide6 in #2320 if you want to test those here. The setup is taken from the working one in glue-viz/echo#34; pyqt63 is failing on collection with the get_qapp error that is probably fixed here, pyside63 is running all tests with 3 failures.

@astrofrog
Copy link
Member Author

The PySide6 6.4 errors are due to spyder-ide/qtpy#373

@dhomeier
Copy link
Collaborator

dhomeier commented Oct 17, 2022

Testing PySide6 6.4.0 with spyder-ide/qtpy#374 installed from git+https://github.com/astrofrog/qtpy.git@ad9d386 seems to get a bit further, but then fails on the matplotlib side with

    from glue.viewers.matplotlib.qt.widget import MplWidget
../../opt/mambax86/envs/pyside6/lib/python3.10/site-packages/glue/viewers/matplotlib/qt/widget.py:13: in <module>
    from matplotlib.backends.backend_qt5 import FigureManagerQT
../../opt/mambax86/envs/pyside6/lib/python3.10/site-packages/matplotlib/backends/backend_qt5.py:6: in <module>
    from .backend_qt import (  # noqa
../../opt/mambax86/envs/pyside6/lib/python3.10/site-packages/matplotlib/backends/backend_qt.py:72: in <module>
    _MODIFIER_KEYS = [
../../opt/mambax86/envs/pyside6/lib/python3.10/site-packages/matplotlib/backends/backend_qt.py:73: in <listcomp>
    (_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),
E   TypeError: int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'

There was a change in type from 6.3.2

type(PySide6.QtCore.Qt.KeyboardModifier.ControlModifier)
<class 'PySide6.QtCore.Qt.KeyboardModifier'>

which supports __int__(), in 6.4.0 to

type(PySide6.QtCore.Qt.KeyboardModifier.ControlModifier)
<enum 'KeyboardModifier'>

which has no __int__(), but does provide a value returning the same.

Matplotlib may need to define something like

_to_int = operator.attrgetter("value") if QT_API in ("PyQt6", "PySide64") else int

@astrofrog
Copy link
Member Author

@dhomeier - thanks for investigating! Could you report that upstream to Matplotlib?

@astrofrog astrofrog marked this pull request as ready for review October 17, 2022 14:10
@astrofrog
Copy link
Member Author

@dhomeier - I think this is ready for now, happy to merge? (the pyside63 failure that is not an allowed failure is a non-deterministic error).

@dhomeier
Copy link
Collaborator

Yes; I could get MplWidget to load and the test session to start patching that in my matplotlib installation, but starting the app fails at

GlueApplication(self.data_collection)

../../opt/mambax86/envs/pyside6/lib/python3.10/site-packages/glue/viewers/image/qt/tests/test_python_export.py:18: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../opt/mambax86/envs/pyside6/lib/python3.10/site-packages/glue/app/qt/application.py:303: in __init__
    self._setup_ui()
../../opt/mambax86/envs/pyside6/lib/python3.10/site-packages/glue/app/qt/application.py:369: in _setup_ui
    lw = LayerTreeWidget(session=self._session)
../../opt/mambax86/envs/pyside6/lib/python3.10/site-packages/glue/app/qt/layer_tree_widget.py:519: in __init__
    self._create_actions()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <glue.app.qt.layer_tree_widget.LayerTreeWidget(0x6000031be160) at 0x1924ffb00>

    def _create_actions(self):
>       tree = self.ui.layerTree
E       AttributeError: 'PySide6.QtWidgets.QWidget' object has no attribute 'layerTree'

../../opt/mambax86/envs/pyside6/lib/python3.10/site-packages/glue/app/qt/layer_tree_widget.py:582: AttributeError
-------------------------------------------------------------------- Captured stderr setup ---------------------------------------------------------------------
qt.pysideplugin: Environment variable PYSIDE_DESIGNER_PLUGINS is not set, bailing out.
qt.pysideplugin: No instance of QPyDesignerCustomWidgetCollection was found.
Qt WebEngine seems to be initialized from a plugin. Please set Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute and QSGRendererInterface::OpenGLRhi using QQuickWindow::setGraphicsApi before constructing QGuiApplication.
qt.pysideplugin: No instance of QPyDesignerCustomWidgetCollection was found.
Traceback (most recent call last):
  File "/Users/derek/opt/mambax86/envs/pyside6/lib/python3.10/site-packages/qtpy/uic.py", line 166, in createWidget
    widget = self.customWidgets[class_name](parent)
  File "/Users/derek/opt/mambax86/envs/pyside6/lib/python3.10/site-packages/glue/core/qt/data_collection_model.py", line 455, in __init__
    self.setEditTriggers(self.NoEditTriggers)
AttributeError: 'DataCollectionView' object has no attribute 'NoEditTriggers'. Did you mean: 'editTriggers'?
"Empty widget item in QVBoxLayout 'layout'."

so I'd also recommend to wait for the qtpy and matplotlib errors to be fixed, and then continue to work on PySide 6.4 support.

I also noticed when launching pytest directly, I am getting the environment listing as

                glue:	0.1.dev6471+g2d83dd8

               PYTHON
              Python:	INSTALLED (3.10.6)

        GUI FRAMEWORK
               PyQt5:	NOT INSTALLED
             PySide2:	NOT INSTALLED

             REQUIRED

and so on, but no report on the PyQt6 and PySide6 installations; could not figure out where that printout is generated though.

@dhomeier
Copy link
Collaborator

@dhomeier - I think this is ready for now, happy to merge? (the pyside63 failure that is not an allowed failure is a non-deterministic error).

Should it not still be better in allowed_failures so as not to block the publish job?

How about a more changelog-usable title like "Add support for PyQt6 and PySide6 backends"?

@dhomeier
Copy link
Collaborator

Ah, mpl is already fixed in matplotlib/matplotlib#24158 (GH search is just performing very awkwardly)!

@dhomeier dhomeier changed the title Fix compatibility with PyQt6 Add support for PyQt6 and PySide6 (<6.4) to Qt backends Oct 17, 2022
@dhomeier dhomeier merged commit 67992cf into glue-viz:main Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants