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>
This commit is contained in:
renatofilho 2010-09-17 17:03:01 -03:00
commit 6974551674
6 changed files with 59 additions and 20 deletions

View file

@ -24,18 +24,22 @@
#include "pyside.h"
#include "signalmanager.h"
#include "qproperty.h"
#include "qsignal.h"
#include <basewrapper.h>
#include <conversions.h>
#include <algorithm>
#include "qsignal.h"
#include <QStack>
extern "C" void init_signal(PyObject* module);
extern "C" void init_slot(PyObject* module);
extern "C" void init_qproperty(PyObject* module);
static QStack<PySide::CleanupFunction> cleanupFunctionList;
namespace PySide
{
void init(PyObject *module)
{
init_signal(module);
@ -82,5 +86,20 @@ bool fillQtProperties(PyObject* qObj, const QMetaObject* metaObj, PyObject* kwds
return true;
}
void registerCleanupFunction(CleanupFunction func)
{
cleanupFunctionList.push(func);
}
void runCleanupFunctions()
{
while (!cleanupFunctionList.isEmpty()) {
CleanupFunction f = cleanupFunctionList.pop();
f();
}
}
} //namespace PySide

View file

@ -75,6 +75,15 @@ template<typename T>
struct initQtMetaType<T, false> {
};
typedef void (*CleanupFunction)(void);
/**
* Register a function to be called before python die
*/
PYSIDE_API void registerCleanupFunction(CleanupFunction func);
PYSIDE_API void runCleanupFunctions();
} //namespace PySide

View file

@ -22,6 +22,7 @@
#include "signalmanager.h"
#include "qproperty.h"
#include "pyside.h"
#include <QHash>
#include <QStringList>
@ -223,6 +224,11 @@ struct SignalManager::SignalManagerPrivate
GlobalReceiver m_globalReceiver;
};
static void clearSignalManager()
{
PySide::SignalManager::instance().clear();
}
SignalManager::SignalManager() : m_d(new SignalManagerPrivate)
{
// Register Qt primitive typedefs used on signals.
@ -234,6 +240,7 @@ SignalManager::SignalManager() : m_d(new SignalManagerPrivate)
TypeResolver::createValueTypeResolver<PyObjectWrapper>(PYTHON_TYPE);
TypeResolver::createValueTypeResolver<PyObjectWrapper>("object");
TypeResolver::createValueTypeResolver<PyObjectWrapper>("PySide::PyObjectWrapper");
PySide::registerCleanupFunction(clearSignalManager);
}
void SignalManager::clear()