aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2019-05-23 19:35:51 +0200
committerChristian Tismer <tismer@stackless.com>2019-06-17 12:14:33 +0200
commit80a6f91c553eaf9ed4d7d002a5abb442693e8e08 (patch)
treebeaeea39a02af3e60aa288e279faff39c0a1877b /sources/pyside2/tests
parentbc5805e38d922ae8161c97a25e272c1ec5749d2f (diff)
Support the qApp macro in "scriptable application"
Renamed from "Fix scriptable application to support the qApp macro" because qApp was improved instead of scriptable application. The qApp macro needed some extra effort to support the qApp "macro" which is only defined in the Python wrappers. I took some generated code, created a QApplication instance in Python and used then reduced generated code to get at the object and adjust the refcount. This solution was then rejected, because I can do better, and in fact, scriptable application now has a correct qApp macro too, without any change to scriptable application. The central idea was to look into the module init function at import time and to see if a Q*Application already exists. I was not aware of that import. Many thanks for the rejection! :-) Update.. -------- After many attempts to make the qApp variable correctly behave like always, I recognized that pre-existing Q*Application instances have no wrappers or constructors at all! With that, it is not possible to create a sophisticated qApp macro as a singleton variable in the desired way. Fortunately, this is also not necessary, because a C++ Q*Application cannot be deleted from Python, and there is no point in supporting more that a simple variable. So in case of a pre-existing instance, the qApp variable now gets redirected to that instance. A small test was added to application_test.py that is triggered by an import. A weird effect when "qApp" was typed interactively before calling "QApplication()" was fixed, too. Change-Id: Ic69dd6a21c964838a90f63e316d299b62a54d612 Fixes: PYSIDE-571 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r--sources/pyside2/tests/QtWidgets/application_test.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/sources/pyside2/tests/QtWidgets/application_test.py b/sources/pyside2/tests/QtWidgets/application_test.py
index bd0f94125..0b8f73cd6 100644
--- a/sources/pyside2/tests/QtWidgets/application_test.py
+++ b/sources/pyside2/tests/QtWidgets/application_test.py
@@ -31,19 +31,25 @@
import unittest
from testbinding import TestObject
from PySide2.QtWidgets import QApplication
+from PySide2 import __all__ as all
class QApplicationInstance(unittest.TestCase):
def appDestroyed(self):
- sefl.assertTrue(False)
+ self.assertTrue(False)
def testInstanceObject(self):
+ self.assertEqual(type(qApp), type(None))
TestObject.createApp()
app1 = QApplication.instance()
app2 = QApplication.instance()
app1.setObjectName("MyApp")
self.assertEqual(app1, app2)
self.assertEqual(app2.objectName(), app1.objectName())
+ if len(all) > 3:
+ # an import triggers qApp initialization
+ __import__("PySide2." + all[-1])
+ self.assertEqual(app1, qApp)
app1.destroyed.connect(self.appDestroyed)
if __name__ == '__main__':