aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2024-02-13 18:18:37 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-03-05 13:37:13 +0100
commitfb0270f39de6ed190a114b8b87afe9ba9b4d93b1 (patch)
treef145ca0d2e2e61aac463f789df3a45f088e64ea8
parentd985296478c053202e41999bcb1826cf055652b1 (diff)
Enum: Move special Flag patch into a snippet
A patch that corrects Qt.Modifier and Qt.KeyboardModifier causes early loading of QtCore.Qt . Move the patch into snippets, running it only when needed. Task-number: PYSIDE-1735 Task-number: PYSIDE-2404 Change-Id: I26cc7aa767d5474bf54a22fbad24fae62daafa5f Pick-to: 6.6 Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/pyside6/PySide6/QtCore/typesystem_core_common.xml2
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp36
-rw-r--r--sources/pyside6/PySide6/support/deprecated.py53
-rw-r--r--sources/pyside6/tests/QtGui/timed_app_and_patching_test.py21
-rw-r--r--sources/pyside6/tests/pysidetest/qvariant_test.py19
5 files changed, 44 insertions, 87 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
index 47c3ae4ea..93b831f95 100644
--- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
+++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
@@ -653,6 +653,8 @@
<enum-type name="WindowType" python-type="IntFlag" flags="WindowFlags"/>
<enum-type name="CursorMoveStyle" since="4.8" revision="4800"/>
+ <inject-code class="target" position="end" file="../glue/qtcore.cpp"
+ snippet="qt-modifier"/>
</namespace-type>
<add-function signature="QEnum(PyObject*)" return-type="PyObject*">
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index 0bf71de04..7c79585a4 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -2106,3 +2106,39 @@ Q_IMPORT_PLUGIN(QDarwinCalendarPermissionPlugin)
#endif
// @snippet darwin_permission_plugin
+// @snippet qt-modifier
+PyObject *_inputDict = PyDict_New();
+// Note: The builtins line is no longer needed since Python 3.10. Undocumented!
+PyDict_SetItemString(_inputDict, "__builtins__", PyEval_GetBuiltins());
+PyDict_SetItemString(_inputDict, "QtCore", module);
+PyDict_SetItemString(_inputDict, "Qt", reinterpret_cast<PyObject *>(pyType));
+// Explicitly not dereferencing the result.
+PyRun_String(R"PY(if True:
+ from enum import Flag
+ from textwrap import dedent
+ from warnings import warn
+ # QtCore and Qt come as globals.
+
+ 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):
+ warn(dedent(f"""
+ The "+" operator is deprecated in Qt For Python 6.0 .
+ Please use "|" instead."""), 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
+
+)PY", Py_file_input, _inputDict, _inputDict);
+// @snippet qt-modifier
diff --git a/sources/pyside6/PySide6/support/deprecated.py b/sources/pyside6/PySide6/support/deprecated.py
index f215f2ff5..263dd3ed7 100644
--- a/sources/pyside6/PySide6/support/deprecated.py
+++ b/sources/pyside6/PySide6/support/deprecated.py
@@ -13,59 +13,6 @@ 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
-from textwrap import dedent
-
-
-class PySideDeprecationWarningRemovedInQt6(Warning):
- pass
-
-
-def constData(self):
- cls = self.__class__
- name = cls.__qualname__
- warnings.warn(dedent(f"""
- {name}.constData is unpythonic and will be removed in Qt For Python 6.0 .
- Please use {name}.data instead."""), PySideDeprecationWarningRemovedInQt6, stacklevel=2)
- return cls.data(self)
-
-
-# No longer needed but kept for reference.
-def _unused_fix_for_QtGui(QtGui):
- for name, cls in QtGui.__dict__.items():
- 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
diff --git a/sources/pyside6/tests/QtGui/timed_app_and_patching_test.py b/sources/pyside6/tests/QtGui/timed_app_and_patching_test.py
index c45d762b5..6e9a661ce 100644
--- a/sources/pyside6/tests/QtGui/timed_app_and_patching_test.py
+++ b/sources/pyside6/tests/QtGui/timed_app_and_patching_test.py
@@ -7,13 +7,10 @@ import unittest
from pathlib import Path
sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
-from init_paths import init_test_paths
+from init_paths import init_test_paths # noqa: E402
init_test_paths(False)
from helper.timedqguiapplication import TimedQGuiApplication
-from PySide6.support import deprecated
-from PySide6.support.signature import importhandler
-from PySide6 import QtGui
class TestTimedApp(TimedQGuiApplication):
@@ -23,21 +20,7 @@ class TestTimedApp(TimedQGuiApplication):
# Simple test of TimedQGuiApplication
self.app.exec()
-
-def fix_for_QtGui(QtGui):
- QtGui.something = 42
-
-
-class TestPatchingFramework(unittest.TestCase):
- """Simple test that verifies that deprecated.py works"""
-
- deprecated.fix_for_QtGui = fix_for_QtGui
-
- def test_patch_works(self):
- something = "something"
- self.assertFalse(hasattr(QtGui, something))
- importhandler.finish_import(QtGui)
- self.assertTrue(hasattr(QtGui, something))
+# deprecated.py is no longer needed.
if __name__ == '__main__':
diff --git a/sources/pyside6/tests/pysidetest/qvariant_test.py b/sources/pyside6/tests/pysidetest/qvariant_test.py
index 8b789b2c7..faefc8169 100644
--- a/sources/pyside6/tests/pysidetest/qvariant_test.py
+++ b/sources/pyside6/tests/pysidetest/qvariant_test.py
@@ -11,9 +11,9 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(True)
-from testbinding import TestObject, TestQVariantEnum, QVariantHolder
+from testbinding import TestObject, TestQVariantEnum
from PySide6.QtCore import Qt, QKeyCombination
-from PySide6.QtGui import QKeySequence, QAction, QMatrix3x3
+from PySide6.QtGui import QKeySequence, QAction
from helper.usesqapplication import UsesQApplication
@@ -26,8 +26,8 @@ class PyTestQVariantEnum(TestQVariantEnum):
return Qt.Orientation.Vertical
def channelingEnum(self, rval_enum):
- return (isinstance(rval_enum, enum.Enum) and
- rval_enum == Qt.Orientation.Vertical)
+ return (isinstance(rval_enum, enum.Enum)
+ and rval_enum == Qt.Orientation.Vertical)
class QVariantTest(UsesQApplication):
@@ -43,8 +43,6 @@ class QVariantTest(UsesQApplication):
QAction().setShortcut(Qt.CTRL | Qt.AltModifier | Qt.Key_B)
QAction().setShortcut(QKeySequence(QKeyCombination(Qt.CTRL | Qt.Key_B)))
QKeySequence(Qt.CTRL | Qt.Key_Q)
- # Issues a warning but works as well
- QKeySequence(Qt.CTRL + Qt.Key_Q)
def testEnum(self):
# Testing C++ class
@@ -64,15 +62,6 @@ class QVariantTest(UsesQApplication):
# check toInt() conversion for IntEnum
self.assertEqual(PyTestQVariantEnum.getNumberFromQVarEnum(Qt.GestureType.TapGesture), 1)
- def testMatrixTemplates(self):
- holder = QVariantHolder()
- matrix = QMatrix3x3()
- matrix.setToIdentity()
- holder.setValue(matrix)
- returned = holder.value()
- self.assertTrue(returned, QMatrix3x3)
- self.assertTrue(returned.isIdentity())
-
if __name__ == '__main__':
unittest.main()