mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Simplfiy some python3 handling
This commit is contained in:
parent
f4c5106454
commit
72764b2937
@ -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 ) )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user