Skip to content
Permalink
Browse files

Simplfiy some python3 handling

  • Loading branch information
m-kuhn committed Mar 9, 2016
1 parent f4c5106 commit 72764b29378875836dc8000e79d8424e919e6e12
Showing with 6 additions and 17 deletions.
  1. +1 −3 cmake/FindPythonLibrary.cmake
  2. +5 −14 src/python/qgspythonutilsimpl.cpp
@@ -46,10 +46,8 @@ else(EXISTS "${PYTHON_INCLUDE_PATH}" AND EXISTS "${PYTHON_LIBRARY}" AND EXISTS "

IF (ENABLE_QT5)
FIND_PACKAGE(PythonInterp 3)
ADD_DEFINITIONS(-DPYTHON3)
ELSE (ENABLE_QT5)
FIND_PACKAGE(PythonInterp 2)
ADD_DEFINITIONS(-DPYTHON2)
FIND_PACKAGE(PythonInterp 2.7)
ENDIF (ENABLE_QT5)

if(PYTHONINTERP_FOUND)
@@ -127,7 +127,7 @@ bool QgsPythonUtilsImpl::checkSystemImports()
return false;
}
}
#ifdef PYTHON2
#if (PY_VERSION_HEX < 0x03000000)
// import Qt bindings
if ( !runString( "from PyQt4 import QtCore, QtGui",
QObject::tr( "Couldn't load PyQt." ) + '\n' + QObject::tr( "Python support will be disabled." ) ) )
@@ -365,7 +365,7 @@ QString QgsPythonUtilsImpl::getTraceback()
PyErr_Fetch( &type, &value, &traceback );
PyErr_NormalizeException( &type, &value, &traceback );

#ifdef PYTHON2
#if (PY_VERSION_HEX < 0x03000000)
const char* iomod = "cStringIO";
#else
const char* iomod = "io";
@@ -403,7 +403,7 @@ QString QgsPythonUtilsImpl::getTraceback()

/* And it should be a string all ready to go - duplicate it. */
if ( !
#ifdef PYTHON2
#if (PY_VERSION_HEX < 0x03000000)
PyString_Check( obResult )
#else
PyUnicode_Check( obResult )
@@ -440,7 +440,7 @@ QString QgsPythonUtilsImpl::getTypeAsString( PyObject* obj )
if ( !obj )
return nullptr;

#ifdef PYTHON2
#if (PY_VERSION_HEX < 0x03000000)
if ( PyClass_Check( obj ) )
{
QgsDebugMsg( "got class" );
@@ -515,20 +515,11 @@ QString QgsPythonUtilsImpl::PyObjectToQString( PyObject* obj )
// check whether the object is already a unicode string
if ( PyUnicode_Check( obj ) )
{
#ifdef PYTHON2
PyObject* utf8 = PyUnicode_AsUTF8String( obj );
if ( utf8 )
result = QString::fromUtf8( PyString_AS_STRING( utf8 ) );
else
result = "(qgis error)";
Py_XDECREF( utf8 );
#else
result = PYOBJ2QSTRING( obj );
#endif
return result;
}

#if PYTHON2
#if (PY_VERSION_HEX < 0x03000000)
// check whether the object is a classical (8-bit) string
if ( PyString_Check( obj ) )
{

0 comments on commit 72764b2

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