From 882d6044ab474725999b1289fdd2199d18e63ceb Mon Sep 17 00:00:00 2001 From: dalthviz Date: Tue, 22 Aug 2023 13:00:07 -0500 Subject: [PATCH 1/4] Improve enum to flags aliasing for PyQt6 --- qtpy/QtCore.py | 5 +++-- qtpy/QtWidgets.py | 7 +++++-- qtpy/tests/test_qtcore.py | 1 + qtpy/tests/test_qtwidgets.py | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index 1cf60668..cab4d061 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -62,10 +62,11 @@ # Alias for MiddleButton removed in PyQt6 but available in PyQt5, PySide2 and PySide6 Qt.MidButton = Qt.MiddleButton - # Add removed definition for `Qt.ItemFlags` as an alias of `Qt.ItemFlag` as PySide6 does. + # Add removed definition for `Qt.ItemFlags` as an alias of `Qt.ItemFlag` + # passing as default value 0 in the same way PySide6 does. # Note that for PyQt5 and PySide2 those definitions are two different classes # (one is the flag definition and the other the enum definition) - Qt.ItemFlags = Qt.ItemFlag + Qt.ItemFlags = lambda value=0: Qt.ItemFlag(value) elif PYSIDE2: from PySide2.QtCore import * diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py index ebb1d87b..0b4fd154 100644 --- a/qtpy/QtWidgets.py +++ b/qtpy/QtWidgets.py @@ -71,8 +71,11 @@ def _directory_to_dir_(*args, **kwargs): QMenu.exec_ = lambda *args, **kwargs: possibly_static_exec(QMenu, *args, **kwargs) QLineEdit.getTextMargins = lambda self: (self.textMargins().left(), self.textMargins().top(), self.textMargins().right(), self.textMargins().bottom()) - # Map missing flags definitions - QFileDialog.Options = QFileDialog.Option + # Add removed definition for `QFileDialog.Options` as an alias of `QFileDialog.Option` + # passing as default value 0 in the same way PySide6 does. + # Note that for PyQt5 and PySide2 those definitions are two different classes + # (one is the flag definition and the other the enum definition) + QFileDialog.Options = lambda value=0: QFileDialog.Option(value) # Allow unscoped access for enums inside the QtWidgets module from .enums_compat import promote_enums diff --git a/qtpy/tests/test_qtcore.py b/qtpy/tests/test_qtcore.py index 20f21cbc..9b68c36d 100644 --- a/qtpy/tests/test_qtcore.py +++ b/qtpy/tests/test_qtcore.py @@ -162,3 +162,4 @@ def test_itemflags_typedef(): Test existence of `QFlags` typedef `ItemFlags` that was removed from PyQt6 """ assert QtCore.Qt.ItemFlags is not None + assert QtCore.Qt.ItemFlags() == QtCore.Qt.ItemFlag(0) diff --git a/qtpy/tests/test_qtwidgets.py b/qtpy/tests/test_qtwidgets.py index 203c11b7..5607ccf5 100644 --- a/qtpy/tests/test_qtwidgets.py +++ b/qtpy/tests/test_qtwidgets.py @@ -236,4 +236,5 @@ def test_qfiledialog_flags_typedef(): """ Test existence of `QFlags