Blob Blame History Raw
From 6e4b67fed40687ca2f7dcd028e8b80f4394f75c3 Mon Sep 17 00:00:00 2001
From: Corran Webster <cwebster@enthought.com>
Date: Sun, 29 Sep 2019 10:45:30 +0100
Subject: [PATCH 1/2] Support PyQt 4.12.2.

---
 pyface/qt/__init__.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/pyface/qt/__init__.py b/pyface/qt/__init__.py
index 6aa63f8d..70846131 100644
--- a/pyface/qt/__init__.py
+++ b/pyface/qt/__init__.py
@@ -25,7 +25,11 @@ def prepare_pyqt4():
     """ Set PySide compatible APIs. """
     # This is not needed for Python 3 and can be removed when we no longer
     # support Python 2.
-    import sip
+    try:
+        # required for PyQt >= 4.12.2
+        from PyQt4 import sip
+    except ImportError:
+        import sip
     try:
         sip.setapi('QDate', 2)
         sip.setapi('QDateTime', 2)
@@ -56,7 +60,7 @@ def prepare_pyqt4():
 for api_name, module in QtAPIs:
     if module in sys.modules:
         qt_api = api_name
-        if qt_api == 'pyqt':
+        if qt_api == 'pyqt' and sys.version_info[0] <= 2:
             # set the PyQt4 APIs
             # this is a likely place for failure - pyface really wants to be
             # imported first, before eg. matplotlib

From 8b2e3261b556a7767add7b6fb4d003ff711f1c9a Mon Sep 17 00:00:00 2001
From: Corran Webster <cwebster@enthought.com>
Date: Mon, 30 Sep 2019 07:54:31 +0100
Subject: [PATCH 2/2] Remove extra check for Python 2.

---
 pyface/qt/__init__.py | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/pyface/qt/__init__.py b/pyface/qt/__init__.py
index 70846131..c1dff630 100644
--- a/pyface/qt/__init__.py
+++ b/pyface/qt/__init__.py
@@ -39,19 +39,15 @@ def prepare_pyqt4():
         sip.setapi('QUrl', 2)
         sip.setapi('QVariant', 2)
     except ValueError as exc:
-        if sys.version_info[0] <= 2:
-            # most likely caused by something else setting the API version
-            # before us: try to give a better error message to direct the user
-            # how to fix.
-            msg = exc.args[0]
-            msg += (". Pyface expects PyQt API 2 under Python 2. "
-                    "Either import Pyface before any other Qt-using packages, "
-                    "or explicitly set the API before importing any other "
-                    "Qt-using packages.")
-            raise ValueError(msg)
-        else:
-            # don't expect the above on Python 3, so just re-raise
-            raise
+        # most likely caused by something else setting the API version
+        # before us: try to give a better error message to direct the user
+        # how to fix.
+        msg = exc.args[0]
+        msg += (". Pyface expects PyQt API 2 under Python 2. "
+                "Either import Pyface before any other Qt-using packages, "
+                "or explicitly set the API before importing any other "
+                "Qt-using packages.")
+        raise ValueError(msg)
 
 
 qt_api = None