Skip to content
Permalink
Browse files

Python3/Qt5/2to3 updates:

* pyqtwrappers update (add QtNetwork, QtXml, QtSql, QtTest, uic)
* 2to3 updates
* move QPyNullVariant/NULL to PyQt.QtCore
* add global unicode/basestring/long for Python3
* expand QtGui, QtCore module and star exports
* Qscintilla2
* replace Set import with set builtin
  • Loading branch information
jef-n committed Mar 14, 2016
1 parent 8c918ae commit fb3fcfa3a0448b1bade8bf789ee67bf070b7de73
Showing with 625 additions and 273 deletions.
  1. +1 −1 cmake/FindQScintilla.cmake
  2. +7 −1 cmake/FindQsci.cmake
  3. +16 −6 cmake/FindQsci.py
  4. +2 −2 cmake/PyQtMacros.cmake
  5. +1 −0 python/CMakeLists.txt
  6. +10 −2 python/PyQt/CMakeLists.txt
  7. +35 −0 python/PyQt/PyQt4/QtCore.py
  8. +26 −0 python/PyQt/PyQt4/QtNetwork.py
  9. +26 −0 python/PyQt/PyQt4/QtSql.py
  10. +26 −0 python/PyQt/PyQt4/QtTest.py
  11. +26 −0 python/PyQt/PyQt4/QtXml.py
  12. +26 −0 python/PyQt/PyQt4/uic.py
  13. +26 −0 python/PyQt/PyQt4/uic/__init__.py
  14. +1 −0 python/PyQt/PyQt4/uic/properties.py
  15. +26 −0 python/PyQt/PyQt4/uic/pyuic.py
  16. +2 −0 python/PyQt/PyQt5/QtCore.py
  17. +1 −0 python/PyQt/PyQt5/QtNetwork.py
  18. +1 −0 python/PyQt/PyQt5/QtSql.py
  19. +1 −0 python/PyQt/PyQt5/QtTest.py
  20. +2 −0 python/PyQt/PyQt5/QtWidgets.py
  21. +1 −0 python/PyQt/PyQt5/QtXml.py
  22. +29 −0 python/PyQt/PyQt5/uic/__init__.py
  23. +1 −0 python/PyQt/PyQt5/uic/properties.py
  24. +1 −0 python/PyQt/PyQt5/uic/pyuic.py
  25. +3 −2 python/console/console_sci.py
  26. +1 −40 python/core/__init__.py
  27. +4 −2 python/plugins/db_manager/db_plugins/__init__.py
  28. +0 −2 python/plugins/db_manager/db_plugins/oracle/connector.py
  29. +1 −2 python/plugins/db_manager/db_plugins/oracle/data_model.py
  30. +1 −2 python/plugins/db_manager/db_plugins/oracle/info_model.py
  31. +2 −2 python/plugins/db_manager/db_plugins/oracle/plugin.py
  32. +2 −2 python/plugins/db_manager/dlg_query_builder.py
  33. +1 −1 python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py
  34. +2 −2 python/plugins/processing/algs/grass7/nviz7.py
  35. +2 −2 python/plugins/processing/algs/lidar/fusion/FusionAlgorithm.py
  36. +7 −7 python/plugins/processing/algs/lidar/fusion/OpenViewerAction.py
  37. +1 −2 python/plugins/processing/algs/qgis/Delaunay.py
  38. +1 −1 python/plugins/processing/algs/qgis/Eliminate.py
  39. +1 −2 python/plugins/processing/algs/qgis/VoronoiPolygons.py
  40. +91 −90 python/plugins/processing/algs/qgis/ui/FieldsMappingPanel.py
  41. +2 −2 python/plugins/processing/algs/saga/SplitRGBBands.py
  42. +4 −3 python/plugins/processing/core/AlgorithmProvider.py
  43. +5 −2 python/plugins/processing/core/ProcessingConfig.py
  44. +2 −2 python/plugins/processing/gui/ContextAction.py
  45. +11 −10 python/plugins/processing/gui/PostgisTableSelector.py
  46. +4 −4 python/plugins/processing/gui/ToolboxAction.py
  47. +1 −1 python/plugins/processing/gui/menus.py
  48. +12 −11 python/plugins/processing/modeler/ModelerScene.py
  49. +7 −7 python/plugins/processing/modeler/MultilineTextPanel.py
  50. +2 −2 python/plugins/processing/script/ScriptAlgorithm.py
  51. +8 −2 python/pyplugin_installer/installer_data.py
  52. +23 −8 python/utils.py
  53. +1 −2 scripts/generate_test_mask_image.py
  54. 0 scripts/{pyuic4-wrapper.bat → pyuic-wrapper.bat}
  55. +7 −0 scripts/pyuic-wrapper.py
  56. +1 −1 scripts/{pyuic4-wrapper.sh → pyuic-wrapper.sh}
  57. +0 −10 scripts/pyuic4-wrapper.py
  58. +1 −0 scripts/qgis_fixes/fix_dict.py
  59. +9 −0 scripts/qgis_fixes/fix_import.py
  60. +1 −0 scripts/qgis_fixes/fix_imports.py
  61. +1 −0 scripts/qgis_fixes/fix_print.py
  62. +47 −19 scripts/qgis_fixes/fix_pyqt.py
  63. +45 −0 scripts/qgis_fixes/fix_uiimport.py
  64. +1 −1 src/app/qgsfieldsproperties.cpp
  65. +5 −1 src/app/qgswelcomepageitemsmodel.cpp
  66. +1 −1 tests/src/python/test_provider_virtual.py
  67. +3 −4 tests/src/python/test_qgsauthsystem.py
  68. +7 −7 tests/src/python/test_qgsrasterlayer.py
@@ -34,7 +34,7 @@ ELSE(EXISTS QSCINTILLA_VERSION_STR)
)

if(ENABLE_QT5)
set(QSCINTILLA_LIBRARY_NAMES qscintilla2-qt5 libqscintilla2-qt5 qt5scintilla2 libqscintilla2-qt5.dylib)
set(QSCINTILLA_LIBRARY_NAMES qscintilla2-qt5 libqt5scintilla2 libqscintilla2-qt5 qt5scintilla2 libqscintilla2-qt5.dylib)
else(ENABLE_QT5)
set(QSCINTILLA_LIBRARY_NAMES qscintilla2 libqscintilla2 libqscintilla2.dylib)
endif(ENABLE_QT5)
@@ -23,7 +23,13 @@ ELSE(EXISTS QSCI_MOD_VERSION_STR)

FIND_FILE(_find_qsci_py FindQsci.py PATHS ${CMAKE_MODULE_PATH})

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_qsci_py} OUTPUT_VARIABLE qsci_ver)
IF(ENABLE_QT5)
SET(QSCI_VER 5)
ELSE(ENABLE_QT5)
SET(QSCI_VER 4)
ENDIF(ENABLE_QT5)

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_qsci_py} ${QSCI_VER} OUTPUT_VARIABLE qsci_ver)

IF(qsci_ver)
STRING(REGEX REPLACE "^qsci_version_str:([^\n]+).*$" "\\1" QSCI_MOD_VERSION_STR ${qsci_ver})
@@ -34,15 +34,25 @@
__date__ = '22/10/2012'
__copyright__ = 'Copyright 2012, The QGIS Project'

import sys

try:
from PyQt4.Qsci import QSCINTILLA_VERSION_STR
VER = QSCINTILLA_VERSION_STR
except ImportError:
try:
VER = ""
if len(sys.argv) > 0:
if sys.argv[1] == "4":
from PyQt4.Qsci import QSCINTILLA_VERSION_STR
VER = QSCINTILLA_VERSION_STR
else:
from PyQt5.Qsci import QSCINTILLA_VERSION_STR
VER = QSCINTILLA_VERSION_STR
else:
try:
from PyQt4.Qsci import QSCINTILLA_VERSION_STR
VER = QSCINTILLA_VERSION_STR
except ImportError:
VER = ""
try:
from PyQt5.Qsci import QSCINTILLA_VERSION_STR
VER = QSCINTILLA_VERSION_STR
except ImportError:
pass

print("qsci_version_str:%s" % VER)
@@ -32,11 +32,11 @@ ENDIF(NOT PYUIC_PROGRAM)
# Adapted from QT4_WRAP_UI
MACRO(PYQT_WRAP_UI outfiles )
IF(WIN32)
SET(PYUIC_WRAPPER "${CMAKE_SOURCE_DIR}/scripts/${PYUIC_PROG_NAME}-wrapper.bat")
SET(PYUIC_WRAPPER "${CMAKE_SOURCE_DIR}/scripts/pyuic-wrapper.bat")
SET(PYUIC_WRAPPER_PATH "${QGIS_OUTPUT_DIRECTORY}/bin/${CMAKE_BUILD_TYPE}")
ELSE(WIN32)
# TODO osx
SET(PYUIC_WRAPPER "${CMAKE_SOURCE_DIR}/scripts/pyuic4-wrapper.sh")
SET(PYUIC_WRAPPER "${CMAKE_SOURCE_DIR}/scripts/pyuic-wrapper.sh")
SET(PYUIC_WRAPPER_PATH "${QGIS_OUTPUT_DIRECTORY}/lib")
ENDIF(WIN32)

@@ -284,6 +284,7 @@ INSTALL(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}")
FOREACH(pyfile ${PY_FILES})
ADD_CUSTOM_COMMAND(TARGET pyutils
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${QGIS_PYTHON_OUTPUT_DIRECTORY}"
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} "${QGIS_PYTHON_OUTPUT_DIRECTORY}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${pyfile}
@@ -9,7 +9,14 @@ SET(PYQT_COMPAT_FILES
QtPrintSupport.py
QtWebKit.py
QtWebKitWidgets.py
QtNetwork.py
QtXml.py
QtSql.py
QtTest.py
Qsci.py
uic/__init__.py
uic/pyuic.py
uic/properties.py
)

ADD_CUSTOM_TARGET(pyqtcompat ALL)
@@ -21,12 +28,13 @@ ELSE(ENABLE_QT5)
ENDIF(ENABLE_QT5)

FOREACH(pyfile ${PYQT_COMPAT_FILES})
GET_FILENAME_COMPONENT(_dir ${pyfile} DIRECTORY)
SET(pyfile ${PYQT_PREFIX}/${pyfile})
LIST(APPEND PYQT_COMPAT_FILES_PREFIXED ${pyfile})
ADD_CUSTOM_COMMAND(TARGET pyqtcompat
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_OUTPUT_DIRECTORY}/PyQt
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} ${PYTHON_OUTPUT_DIRECTORY}/PyQt
COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_OUTPUT_DIRECTORY}/PyQt/${_dir}
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} ${PYTHON_OUTPUT_DIRECTORY}/PyQt/${_dir}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${pyfile}
)
@@ -25,3 +25,38 @@

from PyQt4.QtCore import *
from PyQt4.QtGui import QItemSelectionModel, QSortFilterProxyModel

# Add a __nonzero__ method onto QPyNullVariant so we can check for null values easier.
# >>> value = QPyNullVariant("int")
# >>> if value:
# >>> print "Not a null value"
from types import MethodType
from PyQt4.QtCore import QPyNullVariant


def __nonzero__(self):
return False


def __repr__(self):
return 'NULL'


def __eq__(self, other):
return isinstance(other, QPyNullVariant) or other is None


def __ne__(self, other):
return not isinstance(other, QPyNullVariant) and other is not None


def __hash__(self):
return 2178309

QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)
QPyNullVariant.__repr__ = MethodType(__repr__, None, QPyNullVariant)
QPyNullVariant.__eq__ = MethodType(__eq__, None, QPyNullVariant)
QPyNullVariant.__ne__ = MethodType(__ne__, None, QPyNullVariant)
QPyNullVariant.__hash__ = MethodType(__hash__, None, QPyNullVariant)

NULL = QPyNullVariant(int)
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
QtNetwork.py
---------------------
Date : February 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* 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. *
* *
***************************************************************************
"""

__author__ = 'Jürgen E. Fischer'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtNetwork import *
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
QtSql.py
---------------------
Date : February 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* 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. *
* *
***************************************************************************
"""

__author__ = 'Jürgen E. Fischer'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtSql import *
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
QtTest.py
---------------------
Date : February 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* 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. *
* *
***************************************************************************
"""

__author__ = 'Jürgen E. Fischer'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtTest import *
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
QtXml.py
---------------------
Date : February 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* 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. *
* *
***************************************************************************
"""

__author__ = 'Jürgen E. Fischer'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtXml import *
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
uic.py
---------------------
Date : February 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* 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. *
* *
***************************************************************************
"""

__author__ = 'Jürgen E. Fischer'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.uic import *
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
uic.py
---------------------
Date : February 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* 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. *
* *
***************************************************************************
"""

__author__ = 'Jürgen E. Fischer'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.uic import *
@@ -0,0 +1 @@
from PyQt4.uic import properties
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
pyuic.py
---------------------
Date : February 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* 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. *
* *
***************************************************************************
"""

__author__ = 'Jürgen E. Fischer'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.uic import pyuic
@@ -1 +1,3 @@
from PyQt5.QtCore import *
NULL = QVariant()
QPyNullVariant = QVariant()
@@ -0,0 +1 @@
from PyQt5.QtNetwork import *
@@ -0,0 +1 @@
from PyQt5.QtSql import *
@@ -0,0 +1 @@
from PyQt5.QtTest import *
@@ -1 +1,3 @@
from PyQt5.QtWidgets import *

QLayout.setMargin = lambda self, m: self.setContentsMargins(m, m, m, m)
@@ -0,0 +1 @@
from PyQt5.QtXml import *
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
__init__.py
---------------------
Date : February 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* 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. *
* *
***************************************************************************
"""

__author__ = 'Jürgen E. Fischer'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt5.uic.Compiler import indenter, compiler
from PyQt5.uic.objcreator import widgetPluginPath
from PyQt5.uic import properties, uiparser, Compiler
from PyQt5.uic import *
@@ -0,0 +1 @@
from PyQt5.uic import properties
@@ -0,0 +1 @@
from PyQt5.uic import pyuic

6 comments on commit fb3fcfa

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 15, 2016

@jef-n , could this have caused the following error:

[ 98%] Generating ui_widgetTileIndex.py Traceback (most recent call last): File "../../../../../scripts/pyuic-wrapper.py", line 7, in <module> import PyQt.uic.pyuic ImportError: No module named uic.pyuic python/plugins/GdalTools/tools/CMakeFiles/zzz-GdalTools-2-depend.dir/build.make:108: recipe for target 'python/plugins/GdalTools/tools/ui_widgetTileIndex.py' failed make[2]: *** [python/plugins/GdalTools/tools/ui_widgetTileIndex.py] Error 1 CMakeFiles/Makefile2:4055: recipe for target 'python/plugins/GdalTools/tools/CMakeFiles/zzz-GdalTools-2-depend.dir/all' failed make[1]: *** [python/plugins/GdalTools/tools/CMakeFiles/zzz-GdalTools-2-depend.dir/all] Error 2 Makefile:136: recipe for target 'all' failed make: *** [all] Error 2

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 15, 2016

FYI, I've tried building using a fresh build directory, but still get a fatal error.

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 15, 2016

I've temporarily changed pyuic-wrapper.py line 7 from "import PyQt.uic.pyuic" to "from PyQt4.uic import pyuic", which creates a successful build, but obviously bypasses the compatibility layer.

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Mar 15, 2016

@jef-n FYI I'm also seeing the same error @nirvn reported now

@jef-n

This comment has been minimized.

Copy link
Member Author

@jef-n jef-n replied Mar 16, 2016

should be fix in 4089ed8

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Mar 16, 2016

@jef-n thanks for the quick fix, and huge thanks for moving us towards python3 support.

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