aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6/support/deprecated.py
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-08-25 11:54:56 +0200
committerChristian Tismer <tismer@stackless.com>2022-09-01 11:47:15 +0200
commit20729eb6ffda8771c192e1614f8e53823108cab1 (patch)
treea0c083b1c6ef3fc0b63bef9004a01d6ff2ce880d /sources/pyside6/PySide6/support/deprecated.py
parentedbee6b65aeafc0fb9a5cdb8d53e04e15a94edbe (diff)
PyEnum: Improve the handling of QKeyCombination
After turning IntEnum into Enum, a few classes need more attention because the simple int coercion is no more sufficient. Instead, a bit of help is necessary to make the usage of the __or__ operator consistent, again. On first sight, this coercion to KeyCombination looks slightly unpythonic. But this originates in the complex matters. If you observe what types are actually added, this is very correct. Using the IntEnum version instead is not better. It is just hiding the ongoings by using int, which would also allow to combine two characters as a bad side effect. [ChangeLog][PySide6] PyEnum now handles QKeyCombination correctly with "|" or (deprecated) "+" operators, without falling back to using IntEnum. Task-number: PYSIDE-1735 Change-Id: I08b93b8b7ece75ca650f2916ec6f6f5bb711a70b Pick-to: 6.3 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/support/deprecated.py')
-rw-r--r--sources/pyside6/PySide6/support/deprecated.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/support/deprecated.py b/sources/pyside6/PySide6/support/deprecated.py
index 272e01967..f215f2ff5 100644
--- a/sources/pyside6/PySide6/support/deprecated.py
+++ b/sources/pyside6/PySide6/support/deprecated.py
@@ -13,6 +13,9 @@ Functions that are to be called for
Note that this fixing code is run after all initializations, but before the
import is finished. But that is no problem since the module is passed in.
+
+PYSIDE-1735: This is also used now for missing other functions (overwriting __or__
+ in Qt.(Keyboard)Modifier).
"""
import warnings
@@ -38,4 +41,31 @@ def _unused_fix_for_QtGui(QtGui):
if name.startswith("QMatrix") and "data" in cls.__dict__:
cls.constData = constData
+# PYSIDE-1735: Fix for a special enum function
+def fix_for_QtCore(QtCore):
+ from enum import Flag
+ Qt = QtCore.Qt
+ flag_or = Flag.__or__
+
+ def func_or(self, other):
+ if isinstance(self, Flag) and isinstance(other, Flag):
+ # this is normal or-ing flags together
+ return Qt.KeyboardModifier(self.value | other.value)
+ return QtCore.QKeyCombination(self, other)
+
+ def func_add(self, other):
+ warnings.warn(dedent(f"""
+ The "+" operator is deprecated in Qt For Python 6.0 .
+ Please use "|" instead."""), PySideDeprecationWarningRemovedInQt6, stacklevel=2)
+ return func_or(self, other)
+
+ Qt.KeyboardModifier.__or__ = func_or
+ Qt.KeyboardModifier.__ror__ = func_or
+ Qt.Modifier.__or__ = func_or
+ Qt.Modifier.__ror__ = func_or
+ Qt.KeyboardModifier.__add__ = func_add
+ Qt.KeyboardModifier.__radd__ = func_add
+ Qt.Modifier.__add__ = func_add
+ Qt.Modifier.__radd__ = func_add
+
# eof