-
-
Notifications
You must be signed in to change notification settings - Fork 163
PR: Unscoped enums access for PyQt6 and other missing PyQt6 compatibility changes #271
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
943c622
PyQt6: Add support for initial unscoped enum access and tests
dalthviz 6d75a4a
PyQt6: Missing aliases for QtCore. Add comments for patches
dalthviz dc86e18
PyQt6: Apply suggestions from code review for enum access
dalthviz 8ef3b5d
PyQt6: Remove unused promote_specific_enums function
dalthviz 589d09c
PyQt6: Update copyright string
dalthviz 8590108
Compat: Restore use of QFileDialog.ShowDirsOnly (unscoped enum access)
dalthviz bfa5cbf
PyQt6: Add missing map for QDateTime.toPython
dalthviz 61c3478
PyQt6: Apply suggestions from code review for enum access
dalthviz b02425b
PyQt6: Remove imported QtCore, QtGui and QtWidgets after promoting enums
dalthviz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright © 2009- The Spyder Development Team | ||
| # Copyright © 2012- University of North Carolina at Chapel Hill | ||
| # Luke Campagnola ('luke.campagnola@%s.com' % 'gmail') | ||
| # Ogi Moore ('ognyan.moore@%s.com' % 'gmail') | ||
| # KIU Shueng Chuan ('nixchuan@%s.com' % 'gmail') | ||
| # Licensed under the terms of the MIT License | ||
|
|
||
| """ | ||
| Compatibility functions for scoped and unscoped enum access. | ||
| """ | ||
|
|
||
| from . import PYQT6 | ||
|
|
||
| if PYQT6: | ||
| import enum | ||
|
|
||
| from . import sip | ||
|
|
||
dalthviz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def promote_enums(module): | ||
| """ | ||
| Search enums in the given module and allow unscoped access. | ||
|
|
||
| Taken from: | ||
| https://github.com/pyqtgraph/pyqtgraph/blob/pyqtgraph-0.12.1/pyqtgraph/Qt.py#L331-L377 | ||
| """ | ||
| class_names = [name for name in dir(module) if name.startswith('Q')] | ||
| for class_name in class_names: | ||
| klass = getattr(module, class_name) | ||
| if not isinstance(klass, sip.wrappertype): | ||
| continue | ||
| attrib_names = [name for name in dir(klass) if name[0].isupper()] | ||
| for attrib_name in attrib_names: | ||
| attrib = getattr(klass, attrib_name) | ||
| if not isinstance(attrib, enum.EnumMeta): | ||
| continue | ||
| for enum_obj in attrib: | ||
| setattr(klass, enum_obj.name, enum_obj) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # | ||
| # Copyright © 2009- The Spyder Development Team | ||
| # | ||
| # Licensed under the terms of the MIT License | ||
| # (see LICENSE.txt for details) | ||
|
|
||
| from . import PYQT6, PYQT5, PythonQtError | ||
|
|
||
| if PYQT6: | ||
| from PyQt6.sip import * | ||
| elif PYQT5: | ||
| from PyQt5.sip import * | ||
| else: | ||
| raise PythonQtError( | ||
| 'Currently selected Qt binding does not support this module') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """Test QtGui.""" | ||
| import pytest | ||
|
|
||
| from qtpy import PYQT5, PYQT_VERSION, QtGui | ||
|
|
||
|
|
||
| def test_qdrag_functions(): | ||
| """Test functions mapping for QtGui.QDrag.""" | ||
| assert QtGui.QDrag.exec_ | ||
|
|
||
|
|
||
| def test_qguiapplication_functions(): | ||
| """Test functions mapping for QtGui.QGuiApplication.""" | ||
| assert QtGui.QGuiApplication.exec_ | ||
|
|
||
|
|
||
| def test_qtextdocument_functions(): | ||
| """Test functions mapping for QtGui.QTextDocument.""" | ||
| assert QtGui.QTextDocument.print_ | ||
|
|
||
|
|
||
| @pytest.mark.skipif(PYQT5 and PYQT_VERSION.startswith('5.9'), | ||
| reason="A specific setup with at least sip 4.9.9 is needed for PyQt5 5.9.*" | ||
| "to work with scoped enum access") | ||
| def test_enum_access(): | ||
| """Test scoped and unscoped enum access for qtpy.QtWidgets.*.""" | ||
| assert QtGui.QColor.Rgb == QtGui.QColor.Spec.Rgb | ||
| assert QtGui.QFont.AllUppercase == QtGui.QFont.Capitalization.AllUppercase | ||
| assert QtGui.QIcon.Normal == QtGui.QIcon.Mode.Normal | ||
| assert QtGui.QImage.Format_Invalid == QtGui.QImage.Format.Format_Invalid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """Test QtWidgets.""" | ||
| import pytest | ||
|
|
||
| from qtpy import PYQT5, PYQT_VERSION, QtWidgets | ||
|
|
||
|
|
||
| def test_qtextedit_functions(): | ||
| """Test functions mapping for QtWidgets.QTextEdit.""" | ||
| assert QtWidgets.QTextEdit.setTabStopWidth | ||
| assert QtWidgets.QTextEdit.tabStopWidth | ||
| assert QtWidgets.QTextEdit.print_ | ||
|
|
||
|
|
||
| def test_qplaintextedit_functions(): | ||
| """Test functions mapping for QtWidgets.QPlainTextEdit.""" | ||
| assert QtWidgets.QPlainTextEdit.setTabStopWidth | ||
| assert QtWidgets.QPlainTextEdit.tabStopWidth | ||
| assert QtWidgets.QPlainTextEdit.print_ | ||
|
|
||
|
|
||
| def test_qapplication_functions(): | ||
| """Test functions mapping for QtWidgets.QApplication.""" | ||
| assert QtWidgets.QApplication.exec_ | ||
|
|
||
|
|
||
| def test_qdialog_functions(): | ||
| """Test functions mapping for QtWidgets.QDialog.""" | ||
| assert QtWidgets.QDialog.exec_ | ||
|
|
||
|
|
||
| def test_qmenu_functions(): | ||
| """Test functions mapping for QtWidgets.QDialog.""" | ||
| assert QtWidgets.QMenu.exec_ | ||
|
|
||
|
|
||
| @pytest.mark.skipif(PYQT5 and PYQT_VERSION.startswith('5.9'), | ||
| reason="A specific setup with at least sip 4.9.9 is needed for PyQt5 5.9.*" | ||
| "to work with scoped enum access") | ||
| def test_enum_access(): | ||
| """Test scoped and unscoped enum access for qtpy.QtWidgets.*.""" | ||
| assert QtWidgets.QFileDialog.AcceptOpen == QtWidgets.QFileDialog.AcceptMode.AcceptOpen | ||
| assert QtWidgets.QMessageBox.InvalidRole == QtWidgets.QMessageBox.ButtonRole.InvalidRole | ||
| assert QtWidgets.QStyle.State_None == QtWidgets.QStyle.StateFlag.State_None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.