From 590abafc54206e458066f5632accda94e37f5edf Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Fri, 10 Jun 2011 18:35:31 -0300 Subject: Fix bug 822 - "Can't use QApplication without X" Reviewer: Marcelo Lira Luciano Wolf --- PySide/QtGui/glue/qapplication_init.cpp | 36 +++++++++++++++++++++++---------- PySide/QtGui/typesystem_gui_common.xml | 16 ++++++++++++--- 2 files changed, 38 insertions(+), 14 deletions(-) (limited to 'PySide/QtGui') diff --git a/PySide/QtGui/glue/qapplication_init.cpp b/PySide/QtGui/glue/qapplication_init.cpp index 16c7fef7a..f2e972a63 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(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(self)); + QApplicationConstructorEnd(self); + } +} + +template +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(self)); + QApplicationConstructorEnd(self); + } +} diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml index 8ba49bd20..d6bc0f2fb 100644 --- a/PySide/QtGui/typesystem_gui_common.xml +++ b/PySide/QtGui/typesystem_gui_common.xml @@ -5322,7 +5322,19 @@ - QApplication_constructor(%PYSELF, args, &%0); + QApplicationConstructor(%PYSELF, %1, &%0); + + + + + + QApplicationConstructor(%PYSELF, %1, %2, &%0); + + + + + + QApplicationConstructor(%PYSELF, %1, %2, &%0); @@ -5331,9 +5343,7 @@ - - -- cgit v1.2.3