Skip to content

Commit

Permalink
Improve qgis.PyQt compatibility layer
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 2, 2016
1 parent f5763f0 commit 5558ff9
Show file tree
Hide file tree
Showing 26 changed files with 304 additions and 24 deletions.
3 changes: 2 additions & 1 deletion debian/python-qgis.install.in
@@ -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/*
Expand Down
22 changes: 15 additions & 7 deletions python/PyQt/CMakeLists.txt
@@ -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
Expand All @@ -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)
Expand 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}")
40 changes: 40 additions & 0 deletions python/PyQt/PyQt4/QtCore.py
Expand Up @@ -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)
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/QtSvg.py
@@ -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 *
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 *
29 changes: 29 additions & 0 deletions python/PyQt/PyQt4/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 PyQt4.uic.Compiler import indenter, compiler
from PyQt4.uic.objcreator import widgetPluginPath
from PyQt4.uic import properties, uiparser, Compiler
from PyQt4.uic import *
1 change: 1 addition & 0 deletions python/PyQt/PyQt4/uic/properties.py
@@ -0,0 +1 @@
from PyQt4.uic import properties
31 changes: 31 additions & 0 deletions python/PyQt/PyQt4/uic/pyuic.py
@@ -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
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/QtSvg.py
@@ -0,0 +1 @@
from PyQt5.QtSvg 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

0 comments on commit 5558ff9

Please sign in to comment.