Skip to content
Permalink
Browse files

Improve qgis.PyQt compatibility layer

  • Loading branch information
m-kuhn committed May 2, 2016
1 parent f5763f0 commit 5558ff9ad159d5babb7c26402c67a2a2fcf5fca2
@@ -1,8 +1,9 @@
usr/lib/python*/*-packages/qgis/*.py
usr/lib/python*/*-packages/qgis/*.so
usr/lib/python*/*-packages/qgis/PyQt/*
usr/lib/python*/*-packages/qgis/analysis/*
usr/lib/python*/*-packages/qgis/core/*
usr/lib/python*/*-packages/qgis/gui/*
usr/lib/python*/*-packages/qgis/analysis/*
usr/lib/python*/*-packages/qgis/networkanalysis/*
usr/lib/python*/*-packages/qgis/server/*
usr/lib/python*/*-packages/qgis/testing/*
@@ -1,5 +1,5 @@
SET (QGIS_PYQT_DIR ${QGIS_DATA_DIR}/python/PyQt)
SET (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)
SET (QGIS_PYQT_DIR ${PYTHON_SITE_PACKAGES_DIR}/qgis/PyQt)
SET (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python/qgis/PyQt)

SET(PYQT_COMPAT_FILES
__init__.py
@@ -9,7 +9,15 @@ SET(PYQT_COMPAT_FILES
QtPrintSupport.py
QtWebKit.py
QtWebKitWidgets.py
QtNetwork.py
QtXml.py
QtSql.py
QtTest.py
QtSvg.py
Qsci.py
uic/__init__.py
uic/pyuic.py
uic/properties.py
)

ADD_CUSTOM_TARGET(pyqtcompat ALL)
@@ -21,16 +29,16 @@ ELSE(ENABLE_QT5)
ENDIF(ENABLE_QT5)

FOREACH(pyfile ${PYQT_COMPAT_FILES})
GET_FILENAME_COMPONENT(_dir ${pyfile} PATH)
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}/${_dir}
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} ${PYTHON_OUTPUT_DIRECTORY}/${_dir}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${pyfile}
)
INSTALL(FILES ${pyfile} DESTINATION "${QGIS_PYQT_DIR}/${_dir}")
ENDFOREACH(pyfile)
PY_COMPILE(pyqtcompat "${PYTHON_OUTPUT_DIRECTORY}/PyQt")

INSTALL(FILES ${PYQT_COMPAT_FILES_PREFIXED} DESTINATION "${QGIS_PYQT_DIR}")
PY_COMPILE(pyqtcompat "${PYTHON_OUTPUT_DIRECTORY}")
@@ -23,4 +23,44 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import sip
for api in ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]:
sip.setapi(api, 2)

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 -*-

"""
***************************************************************************
QtSvg.py
---------------------
Date : March 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__ = 'March 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.QtSvg 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,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 PyQt4.uic.Compiler import indenter, compiler
from PyQt4.uic.objcreator import widgetPluginPath
from PyQt4.uic import properties, uiparser, Compiler
from PyQt4.uic import *
@@ -0,0 +1 @@
from PyQt4.uic import properties
@@ -0,0 +1,31 @@
# -*- 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$'


import sip
for api in ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]:
sip.setapi(api, 2)

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.QtSvg 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

0 comments on commit 5558ff9

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