Created
July 1, 2013 18:56
-
-
Save jef-n/5903550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp | |
index 989c52e..268cdba 100644 | |
--- a/src/app/qgisapp.cpp | |
+++ b/src/app/qgisapp.cpp | |
@@ -799,10 +799,6 @@ QgisApp::~QgisApp() | |
QgsApplication::exitQgis(); | |
delete QgsProject::instance(); | |
- | |
- if ( mPythonUtils ) | |
- mPythonUtils->exitPython(); | |
- delete mPythonUtils; | |
} | |
void QgisApp::dragEnterEvent( QDragEnterEvent *event ) | |
diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt | |
index d6d6b9a..d9ccdae 100644 | |
--- a/src/python/CMakeLists.txt | |
+++ b/src/python/CMakeLists.txt | |
@@ -9,6 +9,7 @@ ELSE (WIN32) | |
ADD_DEFINITIONS(-DPYTHON_EXPORT=) | |
ENDIF (WIN32) | |
+QT4_WRAP_CPP(QGISPYTHON_MOC_SRCS qgspythonutilsimpl.h) | |
SET(QGISPYTHON_SRCS qgispython.cpp qgspythonutilsimpl.cpp) | |
INCLUDE_DIRECTORIES( | |
@@ -18,7 +19,7 @@ INCLUDE_DIRECTORIES( | |
${PYTHON_INCLUDE_PATH} | |
) | |
-ADD_LIBRARY (qgispython SHARED ${QGISPYTHON_SRCS}) | |
+ADD_LIBRARY (qgispython SHARED ${QGISPYTHON_SRCS} ${QGISPYTHON_MOC_SRCS}) | |
SET_TARGET_PROPERTIES(qgispython PROPERTIES | |
CLEAN_DIRECT_OUTPUT 1) | |
diff --git a/src/python/qgispython.cpp b/src/python/qgispython.cpp | |
index a822634..74ebcd2 100644 | |
--- a/src/python/qgispython.cpp | |
+++ b/src/python/qgispython.cpp | |
@@ -16,7 +16,16 @@ | |
#include "qgis.h" | |
#include "qgspythonutilsimpl.h" | |
-QGISEXTERN QgsPythonUtils* instance() | |
+#include <QCoreApplication> | |
+ | |
+QgsPythonUtils *smPythonUtils = 0; | |
+ | |
+QGISEXTERN QgsPythonUtils *instance() | |
{ | |
- return new QgsPythonUtilsImpl(); | |
+ if ( !smPythonUtils ) | |
+ { | |
+ smPythonUtils = new QgsPythonUtilsImpl( QCoreApplication::instance() ); | |
+ } | |
+ | |
+ return smPythonUtils; | |
} | |
diff --git a/src/python/qgspythonutilsimpl.cpp b/src/python/qgspythonutilsimpl.cpp | |
index 9756feb..64a6e76 100644 | |
--- a/src/python/qgspythonutilsimpl.cpp | |
+++ b/src/python/qgspythonutilsimpl.cpp | |
@@ -34,7 +34,7 @@ | |
#include <QDir> | |
-QgsPythonUtilsImpl::QgsPythonUtilsImpl() | |
+QgsPythonUtilsImpl::QgsPythonUtilsImpl( QObject *parent = NULL ) : QObject( parent ) | |
{ | |
mMainModule = NULL; | |
mMainDict = NULL; | |
@@ -43,6 +43,8 @@ QgsPythonUtilsImpl::QgsPythonUtilsImpl() | |
QgsPythonUtilsImpl::~QgsPythonUtilsImpl() | |
{ | |
+ QgsDebugCall; | |
+ exitPython(); | |
} | |
void QgsPythonUtilsImpl::initPython( QgisInterface* interface ) | |
@@ -148,13 +150,14 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface ) | |
void QgsPythonUtilsImpl::exitPython() | |
{ | |
- Py_Finalize(); | |
+ if ( mPythonEnabled ) | |
+ Py_Finalize(); | |
+ | |
mMainModule = NULL; | |
mMainDict = NULL; | |
mPythonEnabled = false; | |
} | |
- | |
bool QgsPythonUtilsImpl::isEnabled() | |
{ | |
return mPythonEnabled; | |
@@ -170,8 +173,6 @@ void QgsPythonUtilsImpl::uninstallErrorHook() | |
runString( "qgis.utils.uninstallErrorHook()" ); | |
} | |
- | |
- | |
bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command, bool single ) | |
{ | |
// acquire global interpreter lock to ensure we are in a consistent state | |
diff --git a/src/python/qgspythonutilsimpl.h b/src/python/qgspythonutilsimpl.h | |
index 1578af8..a9ce4d2 100644 | |
--- a/src/python/qgspythonutilsimpl.h | |
+++ b/src/python/qgspythonutilsimpl.h | |
@@ -26,11 +26,11 @@ typedef _object PyObject; | |
#endif | |
-class QgsPythonUtilsImpl : public QgsPythonUtils | |
+class QgsPythonUtilsImpl : public QObject, public QgsPythonUtils | |
{ | |
+ Q_OBJECT | |
public: | |
- | |
- QgsPythonUtilsImpl(); | |
+ QgsPythonUtilsImpl( QObject *parent ); | |
virtual ~QgsPythonUtilsImpl(); | |
@@ -107,7 +107,6 @@ class QgsPythonUtilsImpl : public QgsPythonUtils | |
bool unloadPlugin( QString packageName ); | |
protected: | |
- | |
void installErrorHook(); | |
void uninstallErrorHook(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment