Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 fb3fcfa
Show file tree
Hide file tree
Showing 68 changed files with 625 additions and 273 deletions.
2 changes: 1 addition & 1 deletion cmake/FindQScintilla.cmake
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion cmake/FindQsci.cmake
Expand Up @@ -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})
Expand Down
22 changes: 16 additions & 6 deletions cmake/FindQsci.py
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions cmake/PyQtMacros.cmake
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Expand Up @@ -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}
Expand Down
12 changes: 10 additions & 2 deletions python/PyQt/CMakeLists.txt
Expand Up @@ -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)
Expand 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}
)
Expand Down
35 changes: 35 additions & 0 deletions python/PyQt/PyQt4/QtCore.py
Expand Up @@ -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)
26 changes: 26 additions & 0 deletions python/PyQt/PyQt4/QtNetwork.py
@@ -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 *
26 changes: 26 additions & 0 deletions python/PyQt/PyQt4/QtSql.py
@@ -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 *
26 changes: 26 additions & 0 deletions python/PyQt/PyQt4/QtTest.py
@@ -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 *
26 changes: 26 additions & 0 deletions python/PyQt/PyQt4/QtXml.py
@@ -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 *
26 changes: 26 additions & 0 deletions python/PyQt/PyQt4/uic.py
@@ -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 *
26 changes: 26 additions & 0 deletions python/PyQt/PyQt4/uic/__init__.py
@@ -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 *
1 change: 1 addition & 0 deletions python/PyQt/PyQt4/uic/properties.py
@@ -0,0 +1 @@
from PyQt4.uic import properties
26 changes: 26 additions & 0 deletions python/PyQt/PyQt4/uic/pyuic.py
@@ -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
2 changes: 2 additions & 0 deletions python/PyQt/PyQt5/QtCore.py
@@ -1 +1,3 @@
from PyQt5.QtCore import *
NULL = QVariant()
QPyNullVariant = QVariant()
1 change: 1 addition & 0 deletions python/PyQt/PyQt5/QtNetwork.py
@@ -0,0 +1 @@
from PyQt5.QtNetwork import *
1 change: 1 addition & 0 deletions python/PyQt/PyQt5/QtSql.py
@@ -0,0 +1 @@
from PyQt5.QtSql import *
1 change: 1 addition & 0 deletions python/PyQt/PyQt5/QtTest.py
@@ -0,0 +1 @@
from PyQt5.QtTest import *
2 changes: 2 additions & 0 deletions python/PyQt/PyQt5/QtWidgets.py
@@ -1 +1,3 @@
from PyQt5.QtWidgets import *

QLayout.setMargin = lambda self, m: self.setContentsMargins(m, m, m, m)
1 change: 1 addition & 0 deletions python/PyQt/PyQt5/QtXml.py
@@ -0,0 +1 @@
from PyQt5.QtXml import *
29 changes: 29 additions & 0 deletions python/PyQt/PyQt5/uic/__init__.py
@@ -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 *
1 change: 1 addition & 0 deletions python/PyQt/PyQt5/uic/properties.py
@@ -0,0 +1 @@
from PyQt5.uic import properties
1 change: 1 addition & 0 deletions python/PyQt/PyQt5/uic/pyuic.py
@@ -0,0 +1 @@
from PyQt5.uic import pyuic

6 comments on commit fb3fcfa

@nirvn
Copy link
Contributor

@nirvn nirvn commented on fb3fcfa Mar 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Contributor

@nirvn nirvn commented on fb3fcfa Mar 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@nirvn
Copy link
Contributor

@nirvn nirvn commented on fb3fcfa Mar 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jef-n
Copy link
Member Author

@jef-n jef-n commented on fb3fcfa Mar 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fix in 4089ed8

@nirvn
Copy link
Contributor

@nirvn nirvn commented on fb3fcfa Mar 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.