Skip to content

some fixes for PySide6 future compatibility#1495

Merged
j9ac9k merged 34 commits intopyqtgraph:masterfrom
pijyoi:future_compat
Jan 20, 2021
Merged

some fixes for PySide6 future compatibility#1495
j9ac9k merged 34 commits intopyqtgraph:masterfrom
pijyoi:future_compat

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Jan 10, 2021

fixup some code so that it will be future-compatible with PySide6

if hasattr(g, 'setStops'):
g.setStops(list(stops))
else:
# PySide6 has a missing setStops binding
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this documented anywhere? the method is referenced in the docs:

https://doc-snapshots.qt.io/qt6-dev/qgradient.html#setStops

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's present in Qt6 but the binding is missing in PySide6. It could just be an unintended omission.
https://doc.qt.io/qtforpython/PySide6/QtGui/QGradient.html

In any case, hasattr(QtGui.QLinearGradient, 'setStops') is True for PySide2 but False for PySide6.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 10, 2021

Hi @pijyoi thanks for this PR and tackling this issue!

I'm curious about the changes in all the templates files, for Qt6, we should likely be generating new template files, not modifying the existing ones.

If it would help, I can create new template files and add them to this PR, since they can be a bit annoying to generate.

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 11, 2021

I'm curious about the changes in all the templates files, for Qt6, we should likely be generating new template files, not modifying the existing ones.

The intention for these fixes is only to get the code "future"-ready. i.e. Minor fixes to convert usage of deprecated and obsolete APIs.

In this case, setWeight() in PySide6 no longer takes an integer, and in any case, the enum value 75 was no longer correct. Since setBold(True) already does the same thing as setWeight(Bold), removing the "weight" property altogether was the simpler solution.

If it would help, I can create new template files and add them to this PR, since they can be a bit annoying to generate.

I did try re-generating a template using pyside2-uic, but this resulted in numerous differences from the existing file, which I thought would clutter the git history.
As the change in the .ui files was minor, I manually edited the auto-generated template files.

In any case, the manual edits are localized to a single commit.

I noticed that examples/VideoTemplate_pyside2.py, compared to the files for the other bindings, imports RawImageGLWidget unconditionally, such that the example will fail to run if pyopengl isn't installed. Any ideas why?

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 11, 2021

On my local machine, I have manually "generated" all the *_pyside6.py files by making a copy of the corresponding *_pyside2.py files and changing PySide2 to PySide6.

Almost all the examples are able to launch and display something with PySide6

  • Remote Plotting example has a "Request timed out" error
    o failure was due to running in a virtualenv (on Windows anyway)
  • HDF5 big data example was not tested

MatplotlibWidget.py was not updated.

ScatterPlotItem.py seems to have a PySide2-specific codepath:
https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/graphicsItems/ScatterPlotItem.py#L37
I don't know if it should apply to PySide6.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 11, 2021

Hi @pijyoi would you like to hop on our slack (so we can communicate outside of issue trackers)? Is interested, feel free to email me, the email is in my github profile.

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 12, 2021

Hi @j9ac9k , I am good to remain on github for now.

@pijyoi pijyoi force-pushed the future_compat branch 2 times, most recently from aa706ac to b4e11fb Compare January 13, 2021 10:32
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 13, 2021

TIL about tools/rebuildUi.py, here I've been regenerating those template files manually, like a chump...

I did try re-generating a template using pyside2-uic, but this resulted in numerous differences from the existing file, which I thought would clutter the git history.
As the change in the .ui files was minor, I manually edited the auto-generated template files.

I've manually made small changes to these template files only to regret it. I've been tempted to migrate the creation of these template files to be part of the CI process ....but for the time being I decided that is more trouble than its worth.

The reason for this change is due to a complete reimplementation of uic. I actually had to regenerate a VideoExample_pyside2 template as part of #1466 (which I know isn't merged yet, but will be shortly).

Should this PR also attempt to get PyQt6 compatibility as well now that its' on PyPi?

@pijyoi pijyoi force-pushed the future_compat branch 2 times, most recently from e497713 to fe526ca Compare January 14, 2021 07:47
@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 14, 2021

Should this PR also attempt to get PyQt6 compatibility as well now that its' on PyPi?

I have tried to make the changes in this PR to be less PySide6 specific.

I attempted to add PyQt6 support but it appears that it is going to require more effort than PySide6. Many enums values are not in their old places.

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 14, 2021

For example, for the enum TransformationType.TxRotate, in PySide2, PySide6 and PyQt5, it can be accessed as

  1. QtGui.QTransform.TxRotate
  2. QtGui.QTransform.TransformationType.TxRotate

In PyQt6, it is only accessible from the latter.

https://riverbankcomputing.com/pipermail/pyqt/2020-December/043446.html

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 14, 2021

Thanks for looking into this @pijyoi

I'll have to figure out how to redo the matrix of test dependencies defined here:

https://github.com/pyqtgraph/pyqtgraph/blob/master/.github/workflows/main.yml#L11-L24

such that PySide6 is added to the test suite. If you have any suggestions, I would say feel free to modify the python-3.9 config such that it uses Qt6.

Also, I'd be curious to get your take on incorporating QtPy (I know they don't currently support Qt6 but they will at some point).

pijyoi added 11 commits January 15, 2021 08:25
convert QTreeWidget.setFirstItemColumnSpanned(item, True) to
item.setFirstColumnSpanned(True)

the former is deprecated since Qt 5.15.2 and removed in Qt 6.
the former is no longer present in Qt 6 as an alias
QFont.setBold(True) calls QFont.setWeight(QFont.Weight.Bold)

in Qt 5, QFont.Weight.Bold == 75
in Qt 6, QFont.Weight.Bold == 700

in PySide6, QFont.setWeight() no longer accepts an integer value.
the former is obsolete in 5.15 and is removed in 6.0
also update for PySide2.QImage to take in ndarray directly.
the "try, except" could be dropped if we drop Qt4 support.

however, primaryScreen() may not be the right screen.
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 16, 2021

I think PySide6 wheel may have been linked wrongly?

Perhaps? It's easy enough to add apt-get install libopengl-dev as part of the CI process to see what happens. I'll make that change (along w/ the matplotlib export skip) shortly

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 16, 2021

Sorry for spamming some CI change commits to your PR, feel free to rebase/squash those commits together. Looks like Qt6 effectively needs ubuntu 20.04, github actions was supposed to migrate to that for ubuntu-latest by now, but as they haven't, I've have now specified it. Also, it wasn't libopengl-dev that needed installing, but libopengl0.

A couple of notes:

test_reload was failing on pyside2/python3.9, whatever the reason it was failing there is likely present on pyside6.

For the image tests, we probably want to add PySide6 to this line here:
https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/tests/image_testing.py#L260

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 16, 2021

Is it possible to run the tests directly from the development directory without installing it?

I can run those under the tests subdir

$ pytest pyqtgraph/tests/test_reload.py

but those under the graphicsItems subdir will complain about "No module named pyqtgraph"

$ pytest pyqtgraph/graphicsItems/tests/test_ROI.py

pijyoi and others added 7 commits January 16, 2021 14:33
QDesktopWidget is deprecated in Qt5 and removed in Qt6
documentation for Qt 4.8 and Qt 5.12 have advised to "Use
AdjustToContents or AdjustToContentsOnFirstShow instead"

documentation in Qt 5.15 no longer shows AdjustToMinimumContentsLength.
Install package for libopengl.so
Mandate the use of ubuntu 20.04
test_ImageView()
- PySide6 fails the same as PySide2

test_PlotWidget() and test_GraphicsWindow()
- PySide6 succeeds.
- PySide2 also succeeds. (at least on Linux and on version 5.15.2)
@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 16, 2021

I think PySide6 wheel may have been linked wrongly?

Perhaps? It's easy enough to add apt-get install libopengl-dev as part of the CI process to see what happens. I'll make that change (along w/ the matplotlib export skip) shortly

https://bugreports.qt.io/plugins/servlet/mobile#issue/PYSIDE-1461

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 16, 2021

Is it possible to run the tests directly from the development directory without installing it?

I can run those under the tests subdir

$ pytest pyqtgraph/tests/test_reload.py

but those under the graphicsItems subdir will complain about "No module named pyqtgraph"

$ pytest pyqtgraph/graphicsItems/tests/test_ROI.py

In the case of test_reload the pyqtgraph directory is added to the path, so you're able to import the pyqtgraph module by directory name

pgpath = os.path.join(os.path.dirname(pg.__file__), '..')
pgpath_repr = repr(pgpath)

The other directories don't attempt to do the same, and assume the pyqtgraph module is installed.

Is there a reason you're trying to run tests w/o installing the library? When making a bunch of changes, I often install pyqtgraph in editable mode pip install -e . that way differences from branches, take affect right away.

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 17, 2021

Is there a reason you're trying to run tests w/o installing the library? When making a bunch of changes, I often install pyqtgraph in editable mode pip install -e . that way differences from branches, take affect right away.

Oh, I didn't know about "pip install -e"
Normally, my "install" of pyqtgraph is to just copy the pyqtgraph/pyqtgraph subdir.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 17, 2021

Is there a reason you're trying to run tests w/o installing the library? When making a bunch of changes, I often install pyqtgraph in editable mode pip install -e . that way differences from branches, take affect right away.

Oh, I didn't know about "pip install -e"
Normally, my "install" of pyqtgraph is to just copy the pyqtgraph/pyqtgraph subdir.

Highly recommend using editable installs as it best simulates an end-user interaction with the library. There is one difference I've found with editable installs vs. non-editable pip installs; and that is accessing the example app can be different.

@pijyoi pijyoi mentioned this pull request Jan 20, 2021
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 20, 2021

@pijyoi I think I know how to fix that git error that comes up on the macOS builds, I'm going to try and get the fix merged shortly... if CI here comes back all green after that, this PR ready to merge?

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 20, 2021

if CI here comes back all green after that, this PR ready to merge?

Yes, ready for merging.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 20, 2021

if CI here comes back all green after that, this PR ready to merge?

Yes, ready for merging.

Sorry, forgot one last requested change, can you update the Qt Bindings test matrix in README.md, to add another row:

| Qt-Bindings    | Python 3.7         | Python 3.8         | Python 3.9         |
| :------------- | :----------------: | :----------------: | :----------------: |
| PySide2-5.12   | :white_check_mark: | :x:                | :x:                |
| PyQt5-5.12     | :white_check_mark: | :x:                | :x:                |
| PySide2-5.15   | :x:                | :white_check_mark: | :white_check_mark: |
| PyQt5-5.15     | :x:                | :white_check_mark: | :x:                |
| PySide6-6.0    | :x:                | :x:                | :white_check_mark: |

As well as the supported Qt binding up higher.

That's the last change I got...

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 20, 2021

@pijyoi do you have strong opinions if this should be squashed or merged with all the commits?

@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Jan 20, 2021

Well, at the very least, the commit that adds the generated files should be separate.

But otherwise, I have already tried to squash related things together. I try to keep each commit to only perform one type of fix, so that it can be cherry-picked or reverted. i.e I have a mild preference to keep the commits separate.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 20, 2021

I have a mild preference to keep the commits separate.

Good enough for me.

@j9ac9k j9ac9k merged commit 78bc0fd into pyqtgraph:master Jan 20, 2021
@ksunden
Copy link
Copy Markdown
Contributor

ksunden commented Jan 20, 2021

Woot

@j9ac9k j9ac9k mentioned this pull request Jan 24, 2021
@pijyoi pijyoi deleted the future_compat branch February 10, 2021 02:42
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.

4 participants