Skip to content

Commit

Permalink
Merge pull request #2889 from m-kuhn/py3improvements
Browse files Browse the repository at this point in the history
Simplify some python3 handling, refs #13686 (redmine)
  • Loading branch information
m-kuhn committed Mar 10, 2016
2 parents 9b35a98 + 72764b2 commit a98fefd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
4 changes: 1 addition & 3 deletions cmake/FindPythonLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 5 additions & 14 deletions src/python/qgspythonutilsimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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." ) ) )
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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 ) )
{
Expand Down

0 comments on commit a98fefd

Please sign in to comment.