Skip to content
Permalink
Browse files

Moved python support to a library, QGIS app now during the initializa…

…tion tries to load that library.

git-svn-id: http://svn.osgeo.org/qgis/trunk@8530 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed May 28, 2008
1 parent 2542e85 commit ab06574c8198d3b3eb904fdc1c09e9faeb3140ab
@@ -1,6 +1,10 @@

SUBDIRS(core ui gui app providers plugins helpviewer)

IF (HAVE_PYTHON AND WITH_BINDINGS)
SUBDIRS(python)
ENDIF (HAVE_PYTHON AND WITH_BINDINGS)

IF (APPLE)
SUBDIRS(mac)
ENDIF(APPLE)
@@ -153,10 +153,6 @@ IF (POSTGRES_FOUND)
)
ENDIF (POSTGRES_FOUND)

# Python support
IF (PYTHON_FOUND)
SET (QGIS_APP_SRCS ${QGIS_APP_SRCS} qgspythonutils.cpp)
ENDIF (PYTHON_FOUND)

QT4_WRAP_CPP(QGIS_APP_MOC_SRCS ${QGIS_APP_MOC_HDRS})

@@ -198,6 +194,7 @@ INCLUDE_DIRECTORIES(
../core/raster ../core/renderer ../core/symbology
../gui
../plugins
../python
${PROJ_INCLUDE_DIR}
${SQLITE3_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
@@ -208,10 +205,6 @@ IF (POSTGRES_FOUND)
INCLUDE_DIRECTORIES(${POSTGRES_INCLUDE_DIR})
ENDIF (POSTGRES_FOUND)

IF (PYTHON_FOUND)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
ENDIF (PYTHON_FOUND)

#############

IF (WIN32)
@@ -250,10 +243,6 @@ SET_TARGET_PROPERTIES(qgis PROPERTIES
INSTALL_RPATH_USE_LINK_PATH true
)

IF (PYTHON_FOUND)
TARGET_LINK_LIBRARIES(qgis ${PYTHON_LIBRARIES})
ENDIF (PYTHON_FOUND)

IF (POSTGRES_FOUND)
TARGET_LINK_LIBRARIES (qgis ${POSTGRES_LIBRARY})
ENDIF (POSTGRES_FOUND)
@@ -169,9 +169,6 @@

#include "qgspythondialog.h"
#include "qgspythonutils.h"
#ifdef HAVE_PYTHON
#include "qgspythonutilsimpl.h"
#endif

#ifndef WIN32
#include <dlfcn.h>
@@ -360,17 +357,44 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
qApp->processEvents();
QgsApplication::initQgis();

#ifdef HAVE_PYTHON
mSplash->showMessage(tr("Starting Python"), Qt::AlignHCenter | Qt::AlignBottom);
qApp->processEvents();

mPythonUtils = QgsPythonUtilsImpl::instance();

mPythonUtils->initPython(mQgisInterface);
#endif

if (!mPythonUtils || !mPythonUtils->isEnabled())
// try to load python support
QLibrary pythonlib("qgispython");
// It's necessary to set these two load hints, otherwise Python library won't work correctly
// see http://lists.kde.org/?l=pykde&m=117190116820758&w=2
pythonlib.setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint);
if (pythonlib.load())
{
QgsDebugMsg("Python support library loaded successfully.");
typedef QgsPythonUtils* (*inst)();
inst pythonlib_inst = (inst) pythonlib.resolve("instance");
if (pythonlib_inst)
{
QgsDebugMsg("Python support library's instance() symbol resolved.");
mPythonUtils = pythonlib_inst();
mPythonUtils->initPython(mQgisInterface);
}
else
{
QgsDebugMsg("Couldn't resolve python support library's instance() symbol.");
}
}
else
{
QgsDebugMsg("Couldn't load Python support library.");
}

if (mPythonUtils && mPythonUtils->isEnabled())
{
QgsDebugMsg("Python support ENABLED :-)");
}
else
{
mActionShowPythonDialog->setEnabled(false);
QgsDebugMsg("Python support DISABLED :-(");
}

// Create the plugin registry and load plugins
// load any plugins that were running in the last session
@@ -0,0 +1,25 @@

SET(QGISPYTHON_SRCS qgispython.cpp qgspythonutilsimpl.cpp)

INCLUDE_DIRECTORIES(
../core
../core/raster ../core/renderer ../core/symbology
../gui
${PYTHON_INCLUDE_PATH})

ADD_LIBRARY (qgispython SHARED ${QGISPYTHON_SRCS})

SET_TARGET_PROPERTIES(qgispython PROPERTIES
VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}
SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR})


TARGET_LINK_LIBRARIES(qgispython
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${PYTHON_LIBRARIES}
)

INSTALL(TARGETS qgispython
RUNTIME DESTINATION ${QGIS_BIN_DIR}
LIBRARY DESTINATION ${QGIS_LIB_DIR})
@@ -0,0 +1,23 @@
/***************************************************************************
qgispython.cpp - python support in QGIS
---------------------
begin : May 2008
copyright : (C) 2008 by Martin Dobias
email : wonder.sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */

#include "qgis.h"
#include "qgspythonutilsimpl.h"

QGISEXTERN QgsPythonUtils* instance()
{
return new QgsPythonUtilsImpl();
}
File renamed without changes.
@@ -28,7 +28,6 @@
#include <QStringList>
#include <QDir>

QgsPythonUtilsImpl* QgsPythonUtilsImpl::mInstance = NULL;

QgsPythonUtilsImpl::QgsPythonUtilsImpl()
{
@@ -41,14 +40,6 @@ QgsPythonUtilsImpl::~QgsPythonUtilsImpl()
{
}

QgsPythonUtilsImpl* QgsPythonUtilsImpl::instance()
{
if (mInstance == NULL)
mInstance = new QgsPythonUtilsImpl();
return mInstance;
}


void QgsPythonUtilsImpl::initPython(QgisInterface* interface)
{
// initialize python
@@ -63,7 +54,6 @@ void QgsPythonUtilsImpl::initPython(QgisInterface* interface)
runString("import traceback"); // for formatting stack traces
runString("import __main__"); // to access explicitly global variables


// expect that bindings are installed locally, so add the path to modules
// also add path to plugins
runString("sys.path = [\"" + pythonPath() + "\", \"" + homePluginsPath() + "\", \"" + pluginsPath() + "\"] + sys.path");
@@ -35,8 +35,6 @@ class QgsPythonUtilsImpl : public QgsPythonUtils

virtual ~QgsPythonUtilsImpl();

static QgsPythonUtilsImpl* instance();

/* general purpose functions */

//! initialize python and import bindings
@@ -124,8 +122,6 @@ class QgsPythonUtilsImpl : public QgsPythonUtils

//! flag determining that python support is enabled
bool mPythonEnabled;

static QgsPythonUtilsImpl* mInstance;
};


0 comments on commit ab06574

Please sign in to comment.
You can’t perform that action at this time.