summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-06-10 18:35:31 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-06-13 17:25:08 -0300
commit933669eeb7cd63937fa92b4e3c65641b7f041ed3 (patch)
treeb92f2e812531bca5f78f4b149a50ea5a06894274
parent1be25c54bb6e4759779347ed609f871311e20ffd (diff)
downloadpyside-933669eeb7cd63937fa92b4e3c65641b7f041ed3.tar.gz
pyside-933669eeb7cd63937fa92b4e3c65641b7f041ed3.tar.xz
pyside-933669eeb7cd63937fa92b4e3c65641b7f041ed3.zip
Fix bug 822 - "Can't use QApplication without X"
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--PySide/QtGui/glue/qapplication_init.cpp36
-rw-r--r--PySide/QtGui/typesystem_gui_common.xml16
-rw-r--r--tests/QtGui/CMakeLists.txt1
-rw-r--r--tests/QtGui/bug_882.py13
4 files changed, 52 insertions, 14 deletions
diff --git a/PySide/QtGui/glue/qapplication_init.cpp b/PySide/QtGui/glue/qapplication_init.cpp
index 16c7fef..f2e972a 100644
--- a/PySide/QtGui/glue/qapplication_init.cpp
+++ b/PySide/QtGui/glue/qapplication_init.cpp
@@ -5,23 +5,18 @@ static int QApplicationArgCount;
static char** QApplicationArgValues;
static const char QAPP_MACRO[] = "qApp";
-void QApplication_constructor(PyObject* self, PyObject* args, QApplicationWrapper** cptr)
+bool QApplicationConstructorStart(PyObject* argv)
{
if (QApplication::instance()) {
PyErr_SetString(PyExc_RuntimeError, "A QApplication instance already exists.");
- return;
+ return false;
}
- int numArgs = PyTuple_GET_SIZE(args);
- if (numArgs != 1
- || !Shiboken::sequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QApplicationArgCount, &QApplicationArgValues, "PySideApp")) {
- PyErr_BadArgument();
- return;
- }
-
- *cptr = new QApplicationWrapper(QApplicationArgCount, QApplicationArgValues);
- Shiboken::Object::releaseOwnership(reinterpret_cast<SbkObject*>(self));
+ return Shiboken::sequenceToArgcArgv(argv, &QApplicationArgCount, &QApplicationArgValues, "PySideApp");
+}
+void QApplicationConstructorEnd(PyObject* self)
+{
// Verify if qApp is in main module
PyObject* globalsDict = PyEval_GetGlobals();
if (globalsDict) {
@@ -34,3 +29,22 @@ void QApplication_constructor(PyObject* self, PyObject* args, QApplicationWrappe
PySide::registerCleanupFunction(&PySide::destroyQCoreApplication);
Py_INCREF(self);
}
+
+static void QApplicationConstructor(PyObject* self, PyObject* argv, QApplicationWrapper** cptr)
+{
+ if (QApplicationConstructorStart(argv)) {
+ *cptr = new QApplicationWrapper(QApplicationArgCount, QApplicationArgValues);
+ Shiboken::Object::releaseOwnership(reinterpret_cast<SbkObject*>(self));
+ QApplicationConstructorEnd(self);
+ }
+}
+
+template <typename T>
+static void QApplicationConstructor(PyObject* self, PyObject* argv, T extraArg, QApplicationWrapper** cptr)
+{
+ if (QApplicationConstructorStart(argv)) {
+ *cptr = new QApplicationWrapper(QApplicationArgCount, QApplicationArgValues, extraArg);
+ Shiboken::Object::releaseOwnership(reinterpret_cast<SbkObject*>(self));
+ QApplicationConstructorEnd(self);
+ }
+}
diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml
index 8ba49bd..d6bc0f2 100644
--- a/PySide/QtGui/typesystem_gui_common.xml
+++ b/PySide/QtGui/typesystem_gui_common.xml
@@ -5322,7 +5322,19 @@
<modify-function signature="QApplication(int&amp;,char**)" access="private" />
<add-function signature="QApplication(PySequence)">
<inject-code>
- QApplication_constructor(%PYSELF, args, &amp;%0);
+ QApplicationConstructor(%PYSELF, %1, &amp;%0);
+ </inject-code>
+ </add-function>
+ <modify-function signature="QApplication(int&amp;,char**,bool)" access="private"/>
+ <add-function signature="QApplication(PySequence,bool)">
+ <inject-code>
+ QApplicationConstructor(%PYSELF, %1, %2, &amp;%0);
+ </inject-code>
+ </add-function>
+ <modify-function signature="QApplication(int&amp;,char**,QApplication::Type)" access="private" />
+ <add-function signature="QApplication(PySequence,QApplication::Type)">
+ <inject-code>
+ QApplicationConstructor(%PYSELF, %1, %2, &amp;%0);
</inject-code>
</add-function>
<modify-function signature="exec()" rename="exec_" allow-thread="yes"/>
@@ -5331,9 +5343,7 @@
<!-- ### Causes warnings using generator. They were kept here to avoid generation even
removing Q_INTERNAL_QAPP_SRC || qdoc from #define section-->
<modify-function signature="QApplication(int&amp;,char**,int)" remove="all"/>
- <modify-function signature="QApplication(int&amp;,char**,bool)" remove="all"/>
<modify-function signature="QApplication(int&amp;,char**,bool,int)" remove="all"/>
- <modify-function signature="QApplication(int&amp;,char**,QApplication::Type)" remove="all"/>
<modify-function signature="QApplication(int&amp;,char**,QApplication::Type,int)" remove="all"/>
<!-- ### -->
diff --git a/tests/QtGui/CMakeLists.txt b/tests/QtGui/CMakeLists.txt
index 9afe317..5209ee5 100644
--- a/tests/QtGui/CMakeLists.txt
+++ b/tests/QtGui/CMakeLists.txt
@@ -64,6 +64,7 @@ PYSIDE_TEST(bug_854.py)
PYSIDE_TEST(bug_860.py)
PYSIDE_TEST(bug_862.py)
PYSIDE_TEST(bug_871.py)
+PYSIDE_TEST(bug_882.py)
PYSIDE_TEST(customproxywidget_test.py)
PYSIDE_TEST(deepcopy_test.py)
PYSIDE_TEST(event_filter_test.py)
diff --git a/tests/QtGui/bug_882.py b/tests/QtGui/bug_882.py
new file mode 100644
index 0000000..88f769c
--- /dev/null
+++ b/tests/QtGui/bug_882.py
@@ -0,0 +1,13 @@
+from PySide.QtGui import *
+from PySide.QtCore import *
+import os
+
+if "DISPLAY" in os.environ:
+ del os.environ["DISPLAY"]
+
+app = QApplication([], False)
+QTimer.singleShot(0, app.quit)
+app.exec_()
+
+
+