aboutsummaryrefslogtreecommitdiffstats
path: root/PySide
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-09-17 17:03:01 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-09-17 18:54:08 -0300
commit6974551674d72a828ff9ae19af510c90a62a09ec (patch)
tree1dac32e9240ede7429569b4d25b672e8c017022a /PySide
parentb8436f6b1e1efb4da51c6bcc6c22d997541d10c6 (diff)
Created PySide cleanup functions used to register functions to be called before the python die.
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'PySide')
-rw-r--r--PySide/QtCore/glue/qcoreapplication_init.cpp11
-rw-r--r--PySide/QtCore/typesystem_core.xml11
-rw-r--r--PySide/QtGui/glue/qapplication_init.cpp20
3 files changed, 23 insertions, 19 deletions
diff --git a/PySide/QtCore/glue/qcoreapplication_init.cpp b/PySide/QtCore/glue/qcoreapplication_init.cpp
index 7601dbd1d..14ccbb8f9 100644
--- a/PySide/QtCore/glue/qcoreapplication_init.cpp
+++ b/PySide/QtCore/glue/qcoreapplication_init.cpp
@@ -1,21 +1,20 @@
// Global variables used to store argc and argv values
static int QCoreApplicationArgCount;
static char** QCoreApplicationArgValues;
-static bool leavingPython = false;
/**
* Called at QtCore module exit
*/
void DeleteQCoreApplicationAtExit()
{
- leavingPython = true;
QCoreApplication *cpp = QCoreApplication::instance();
if (cpp) {
Shiboken::BindingManager &bmngr = Shiboken::BindingManager::instance();
PyObject* pySelf = bmngr.retrieveWrapper(cpp);
- if (pySelf)
- bmngr.invalidateWrapper(pySelf);
- cpp->deleteLater();
+ cpp->flush();
+ QCoreApplication::processEvents();
+ bmngr.invalidateWrapper(pySelf);
+ delete cpp;
}
}
@@ -54,7 +53,7 @@ int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*)
PySide::signalUpdateSource(self);
cptr->metaObject();
- Py_AtExit(DeleteQCoreApplicationAtExit);
+ PySide::registerCleanupFunction(DeleteQCoreApplicationAtExit);
Py_INCREF(self);
return 1;
}
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index d7c5891a7..f10ed0709 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -552,8 +552,8 @@
</inject-code>
<add-function signature="__moduleShutdown()">
- <inject-code class="target" position="beginning">
- PySide::SignalManager::instance().clear();
+ <inject-code class="target" position="beginning">
+ PySide::runCleanupFunctions();
</inject-code>
</add-function>
@@ -1875,12 +1875,7 @@
<!-- Obsolete -->
<modify-function signature="argc()" remove="all"/>
<!-- Obsolete -->
- <modify-function signature="notify(QObject*,QEvent*)">
- <inject-code class="shell" position="beginning">
- Shiboken::ThreadStateSaver threadStateSaver;
- if (!leavingPython)
- threadStateSaver.save();
- </inject-code>
+ <modify-function signature="notify(QObject*,QEvent*)" allow-thread="yes">
<modify-argument index="2" invalidate-after-use="yes"/>
</modify-function>
<modify-function signature="QCoreApplication(int &amp;, char **)" access="private"/>
diff --git a/PySide/QtGui/glue/qapplication_init.cpp b/PySide/QtGui/glue/qapplication_init.cpp
index 699633a1d..208d59a52 100644
--- a/PySide/QtGui/glue/qapplication_init.cpp
+++ b/PySide/QtGui/glue/qapplication_init.cpp
@@ -4,19 +4,29 @@ extern PyObject* moduleQtGui;
static int QApplicationArgCount;
static char** QApplicationArgValues;
static const char QAPP_MACRO[] = "qApp";
-static bool leavingPython = false;
void DeleteQApplicationAtExit()
{
- leavingPython = true;
PySide::SignalManager::instance().clear();
QCoreApplication* cpp = QApplication::instance();
if (cpp) {
Shiboken::BindingManager &bmngr = Shiboken::BindingManager::instance();
- PyObject* pySelf = bmngr.retrieveWrapper(cpp);
- if (pySelf)
+ cpp->flush();
+
+ // Delete all widgets, this is slow but is necessary to avoid problems with python object
+ foreach(QWidget* w, QApplication::allWidgets()) {
+ PyObject* pySelf = bmngr.retrieveWrapper(w);
+
+ w->deleteLater();
+ //Make sure all events will send before invalidated the python object
+ QApplication::processEvents();
bmngr.invalidateWrapper(pySelf);
+ }
+
+ PyObject* pySelf = bmngr.retrieveWrapper(cpp);
cpp->deleteLater();
+ QApplication::processEvents();
+ bmngr.invalidateWrapper(pySelf);
}
}
@@ -62,7 +72,7 @@ int SbkQApplication_Init(PyObject* self, PyObject* args, PyObject*)
}
PyObject_SetAttrString(moduleQtGui, QAPP_MACRO, self);
- Py_AtExit(DeleteQApplicationAtExit);
+ PySide::registerCleanupFunction(DeleteQApplicationAtExit);
Py_INCREF(self);
return 1;
}