[Python-modules-commits] [python-qtpy] 01/01: Imported Upstream version 1.1.1

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Fri Jul 8 14:40:47 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch upstream
in repository python-qtpy.

commit d0ff155a509a9f08169cb67b48ce9f50dbfbc5db
Author: Ghislain Antony Vaillant <ghisvail at gmail.com>
Date:   Sun Jul 3 13:50:06 2016 +0100

    Imported Upstream version 1.1.1
---
 .travis.yml                   |  87 ++++++----------
 AUTHORS.md                    |   5 +
 CHANGELOG.md                  | 103 +++++++++++++++++--
 README.md                     |  20 +++-
 appveyor.yml                  |  39 ++++++++
 qtpy/QtCore.py                |  22 ++---
 qtpy/QtDesigner.py            |  11 +--
 qtpy/QtGui.py                 |  14 +--
 qtpy/QtNetwork.py             |  14 +--
 qtpy/QtPrintSupport.py        |  14 +--
 qtpy/QtSvg.py                 |  14 +--
 qtpy/QtTest.py                |  18 +---
 qtpy/QtWebEngineWidgets.py    |  14 +--
 qtpy/QtWidgets.py             |  29 +++---
 qtpy/__init__.py              |  43 ++++----
 qtpy/_patch/__init__.py       |   0
 qtpy/_patch/qcombobox.py      | 101 +++++++++++++++++++
 qtpy/_version.py              |   2 +-
 qtpy/compat.py                |   4 +-
 qtpy/uic.py                   | 223 ++++++++++++++++++++++++++++++++++++++++++
 setup.py                      |  10 +-
 tests/conftest.py             |  59 +++++++++++
 tests/test.ui                 |  35 +++++++
 tests/test_custom.ui          |  42 ++++++++
 tests/test_main.py            |  71 ++++++++++++++
 tests/test_patch_qcombobox.py |  94 ++++++++++++++++++
 tests/test_uic.py             |  68 +++++++++++++
 tests/tests.py                |  11 ---
 28 files changed, 961 insertions(+), 206 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 90acd7e..d394dee 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,71 +1,44 @@
-language: python
+# We set the language to c because python isn't supported on the MacOS X nodes
+# on Travis. However, the language ends up being irrelevant anyway, since we
+# install Python ourselves using conda.
+language: c
+
 sudo: false
 
+os:
+  - linux
+  - osx
+
 env:
   global:
-    - MINCONDA_VERSION="latest"
-    - MINCONDA_LINUX="Linux-x86_64"
-    - MINCONDA_OSX="MacOSX-x86_64"
-matrix:
-  include:
-    # Linux
-    - python: "2.7"
-      env: USE_QT_API=PyQt5
-      os: linux
-    - python: "2.7"
-      env: USE_QT_API=PyQt4
-      os: linux
-    - python: "2.7"
-      env: USE_QT_API=PySide
-      os: linux
-    - python: "3.4"
-      env: USE_QT_API=PyQt4
-      os: linux
-    - python: "3.5"
-      env: USE_QT_API=PyQt5
-      os: linux
-    - python: "3.5"
-      env: USE_QT_API=PyQt4
-      os: linux
-before_install:
-  - "export DISPLAY=:99.0"
-  - "sh -e /etc/init.d/xvfb start"
-install:
-  # Define the value to download
-  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
-      MINCONDA_OS=$MINCONDA_LINUX;
-    elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
-      MINCONDA_OS=$MINCONDA_OSX;
-    fi
-  # You may want to periodically update this, although the conda update
-  # conda line below will keep everything up-to-date. We do this
-  # conditionally because it saves us some downloading if the version is
-  # the same.
-  - if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
-      wget "http://repo.continuum.io/miniconda/Miniconda-$MINCONDA_VERSION-$MINCONDA_OS.sh" -O miniconda.sh;
-    else
-      wget "http://repo.continuum.io/miniconda/Miniconda3-$MINCONDA_VERSION-$MINCONDA_OS.sh" -O miniconda.sh;
-    fi
-  - bash miniconda.sh -b -p $HOME/miniconda
-  - export PATH="$HOME/miniconda/bin:$PATH"
-  - hash -r
-  - conda config --set always_yes yes --set changeps1 no
-  - conda update -q conda
-  # Useful for debugging any issues with conda
-  - conda info -a
+    - SETUP_XVFB=True
+    - CONDA_DEPENDENCIES='pytest'
+  matrix:
+    - PYTHON_VERSION=2.7 USE_QT_API=PyQt5
+    - PYTHON_VERSION=2.7 USE_QT_API=PyQt4
+    - PYTHON_VERSION=2.7 USE_QT_API=PySide
+    - PYTHON_VERSION=3.4 USE_QT_API=PyQt4
+    - PYTHON_VERSION=3.5 USE_QT_API=PyQt4
+    - PYTHON_VERSION=3.5 USE_QT_API=PyQt5
 
+before_install:
   # Test environments for different Qt bindings
   - if [[ "$USE_QT_API" == "PyQt5" ]]; then
-      conda config --add channels spyder-ide;
-      conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION qt5 pyqt5;
+      export CONDA_DEPENDENCIES='qt5 pyqt5 '$CONDA_DEPENDENCIES;
+      export CONDA_CHANNELS='spyder-ide';
     elif [[ "$USE_QT_API" == "PyQt4" ]]; then
-      conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION qt pyqt;
+      export CONDA_DEPENDENCIES='qt pyqt '$CONDA_DEPENDENCIES;
     elif [[ "$USE_QT_API" == "PySide" ]]; then
-      conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION qt pyside;
+      export CONDA_DEPENDENCIES='qt pyside '$CONDA_DEPENDENCIES;
     fi
-  - source activate test-environment
+
+install:
+  - git clone git://github.com/astropy/ci-helpers.git
+  - source ci-helpers/travis/setup_conda_$TRAVIS_OS_NAME.sh
   - python setup.py install
+
 before_script:
   - cd tests
+
 script:
-  - python tests.py
+  - py.test
diff --git a/AUTHORS.md b/AUTHORS.md
index d59ba80..a6b4d15 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -9,3 +9,8 @@ Main Authors
 * Colin Duquesnoy ([@ColinDuquesnoy](http://github.com/ColinDuquesnoy))
 
 * [The Spyder Development Team](https://github.com/spyder-ide/spyder/graphs/contributors)
+
+Contributors
+============
+
+* Thomas Robitaille ([@astrofrog](http://www.github.com/astrofrog))
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc3781c..c74fc99 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,15 +1,98 @@
 # History of changes
 
-## Version 1.0.2 (01/06/16)
+## Version 1.1.1 (2016-07-01)
 
-* Add a WEBENGINE constant to QtWebEngineWidgets, which is True if Qt 5 comes
-  with the WebEngine module and False otherwise.
+### Bugfixes
 
-## Version 1.0.1 (10/04/16)
+**Pull requests**
 
-* Import QIntValidator in QtGui and remove it from QtWidgets (PR #19)
+* [PR 44](https://github.com/spyder-ide/qtpy/pull/44) - Make qtpy to set the QT_API environment variable
 
-## Version 1.0 (22/03/16)
+In this release 1 pull requests were merged
+
+
+---
+
+
+## Version 1.1 (2016-06-30)
+
+### New features
+
+* Make importing `qtpy` thread-safe
+* Add a uic module to make loadUI work for PySide
+* Add QtTest support for PySide
+
+### Bugfixes
+
+**Issues**
+
+* [Issue 42](https://github.com/spyder-ide/qtpy/issues/42) - Wrong old PyQt4 version check
+* [Issue 21](https://github.com/spyder-ide/qtpy/issues/21) - Patch QComboBox with PySide?
+* [Issue 16](https://github.com/spyder-ide/qtpy/issues/16) - Add loadUI functionality
+
+In this release 3 issues were closed
+
+**Pull requests**
+
+* [PR 43](https://github.com/spyder-ide/qtpy/pull/43) - Don't check PyQt version with qtpy's version for old PyQt versions
+* [PR 41](https://github.com/spyder-ide/qtpy/pull/41) - `qtpy.__version__` should be QtPy version, not Qt version
+* [PR 40](https://github.com/spyder-ide/qtpy/pull/40) - Mention qt-helpers in README.md, and add myself to AUTHORS.md
+* [PR 39](https://github.com/spyder-ide/qtpy/pull/39) - Fix remaining segmentation fault that occurs with the patched QComboBox in PySide
+* [PR 38](https://github.com/spyder-ide/qtpy/pull/38) - QtTest for PySide
+* [PR 37](https://github.com/spyder-ide/qtpy/pull/37) - Automatically load custom widget classes when using PySide
+* [PR 33](https://github.com/spyder-ide/qtpy/pull/33) - Ignore case for QT_API env variable in qtpy submodules
+* [PR 32](https://github.com/spyder-ide/qtpy/pull/32) - Remove QItemSelectionModel from QtWidgets for PyQt4 and PySide
+* [PR 31](https://github.com/spyder-ide/qtpy/pull/31) - Add compatibility for QItemSelectionModel
+* [PR 29](https://github.com/spyder-ide/qtpy/pull/29) - Use ci-helpers (from Astropy) for CI and enable AppVeyor
+* [PR 28](https://github.com/spyder-ide/qtpy/pull/28) - Make tests.py into proper unit test, and add Qt version info to pytest header
+* [PR 27](https://github.com/spyder-ide/qtpy/pull/27) - Make sure loadUi is available
+* [PR 25](https://github.com/spyder-ide/qtpy/pull/25) - Add patched version of QComboBox
+
+In this release 13 pull requests were merged
+
+
+---
+
+
+## Version 1.0.2 (2016-06-02)
+
+### New features
+
+* Add a WEBENGINE constant to QtWebEngineWidgets, which is True if Qt 5 comes with the WebEngine module and False otherwise.
+
+### Bugfixes
+
+**Pull requests**
+
+* [PR 24](https://github.com/spyder-ide/qtpy/pull/24) - Add constant to QtWebEngineWidgets to see if we are using WebEngine or WebKit
+* [PR 23](https://github.com/spyder-ide/qtpy/pull/23) - Fix "Prefer `format()` over string interpolation operator" issue
+
+In this release 2 pull requests were merged
+
+
+---
+
+
+## Version 1.0.1 (2016-04-10)
+
+### Bugfixes
+
+**Issues**
+
+* [Issue 18](https://github.com/spyder-ide/qtpy/issues/18) - QIntValidator left in QtWidgets, should be in QtGui
+
+In this release 1 issues were closed
+
+**Pull requests**
+
+* [PR 19](https://github.com/spyder-ide/qtpy/pull/19) - Import QIntValidator in QtGui and remove it from QtWidgets
+
+In this release 1 pull requests were merged
+
+
+----
+
+## Version 1.0 (2016-03-22)
 
 * Add QtWebEngineWidgets module for Qt 5.6. This module replaces the previous
   QtWebKit one.
@@ -18,10 +101,14 @@
 
 * Add a QtPrintSupport module
 
-## Version 0.1.3 (30/12/15)
+
+---
+
+
+## Version 0.1.3 (2015-12-30)
 
 * Add tests and continuous integration
 
-## Version 0.1.2 (1/03/15)
+## Version 0.1.2 (2015-03-01)
 
 * First release
diff --git a/README.md b/README.md
index 40c37f1..0ee4058 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## QtPy: Abtraction layer for PySide/PyQt4/PyQt5
+## QtPy: Abtraction layer for PyQt5/PyQt4/PySide
 
 **QtPy** (pronounced *'cutie pie'*) is a small abstraction layer that lets you
 write applications using a single API call to either PyQt or PySide.
@@ -14,9 +14,12 @@ from `qtpy` instead of `PyQt5`.
 
 This project is based on the [pyqode.qt](https://github.com/pyQode/pyqode.qt)
 project and the [spyderlib.qt](https://github.com/spyder-ide/spyder/tree/2.3/spyderlib/qt)
-module from the [Spyder](https://github.com/spyder-ide/spyder) project.
+module from the [Spyder](https://github.com/spyder-ide/spyder) project, and
+also includes contributions adapted from
+[qt-helpers](https://github.com/glue-viz/qt-helpers), developed as part of the
+[glue](http://glueviz.org) project.
 
-Unlike `pyqode.qt` this is not a namespace package so it is not tied
+Unlike `pyqode.qt` this is not a namespace package, so it is not tied
 to a particular project or namespace.
 
 
@@ -27,8 +30,15 @@ This project is licensed under the MIT license.
 
 ### Requirements
 
-You need PyQt5 or PyQt4 or PySide installed on your system to make use
-of QtPy.
+You need PyQt5, PyQt4 or PySide installed in your system to make use
+of QtPy. If several of these packages are found, PyQt5 is used by
+default unless you set the `QT_API` environment variable.
+
+`QT_API` can take the following values:
+
+* `pyqt5` (to use PyQt5).
+* `pyqt` or `pyqt4` (to use PyQt4).
+* `pyside` (to use PySide).
 
 
 ### Installation
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..d310e75
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,39 @@
+environment:
+
+  global:
+      PYTHON: "C:\\conda"
+      CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci-helpers\\appveyor\\windows_sdk.cmd"
+      PYTHON_ARCH: "64" # needs to be set for CMD_IN_ENV to succeed. If a mix
+                        # of 32 bit and 64 bit builds are needed, move this
+                        # to the matrix section.
+
+  matrix:
+
+    # - PYTHON_VERSION: "2.7"
+    #   CONDA_CHANNELS: "msarahan"
+    #   CONDA_DEPENDENCIES: "pytest qt5 pyqt5"
+    - PYTHON_VERSION: "2.7"
+      CONDA_DEPENDENCIES: "pytest qt pyqt"
+    - PYTHON_VERSION: "2.7"
+      CONDA_DEPENDENCIES: "pytest qt pyside"
+    # - PYTHON_VERSION: "3.5"
+    #   CONDA_CHANNELS: "msarahan"
+    #   CONDA_DEPENDENCIES: "pytest qt5 pyqt5"
+    - PYTHON_VERSION: "3.5"
+      CONDA_DEPENDENCIES: "pytest qt pyqt"
+
+platform:
+    -x64
+
+install:
+    - "git clone git://github.com/astropy/ci-helpers.git"
+    - "powershell ci-helpers/appveyor/install-miniconda.ps1"
+    - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
+    - "activate test"
+
+# Not a .NET project, we build in the install step instead
+build: false
+
+test_script:
+  - "%CMD_IN_ENV% py.test"
+
diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py
index 8667ba3..0ca69d3 100644
--- a/qtpy/QtCore.py
+++ b/qtpy/QtCore.py
@@ -10,35 +10,29 @@
 Provides QtCore classes and functions.
 """
 
-import os
+from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError
 
-from qtpy import QT_API
-from qtpy import PYQT5_API
-from qtpy import PYQT4_API
-from qtpy import PYSIDE_API
-from qtpy import PythonQtError
 
-
-if os.environ[QT_API] in PYQT5_API:
+if PYQT5:
     from PyQt5.QtCore import *
     from PyQt5.QtCore import pyqtSignal as Signal
     from PyQt5.QtCore import pyqtSlot as Slot
     from PyQt5.QtCore import pyqtProperty as Property
     from PyQt5.QtCore import QT_VERSION_STR as __version__
-elif os.environ[QT_API] in PYQT4_API:
+elif PYQT4:
     from PyQt4.QtCore import *
     from PyQt4.QtCore import QCoreApplication
     from PyQt4.QtCore import Qt
     from PyQt4.QtCore import pyqtSignal as Signal
     from PyQt4.QtCore import pyqtSlot as Slot
     from PyQt4.QtCore import pyqtProperty as Property
-    from PyQt4.QtGui import (QItemSelection, QItemSelectionRange,
-                             QSortFilterProxyModel)
+    from PyQt4.QtGui import (QItemSelection, QItemSelectionModel,
+                             QItemSelectionRange, QSortFilterProxyModel)
     from PyQt4.QtCore import QT_VERSION_STR as __version__
-elif os.environ[QT_API] in PYSIDE_API:
+elif PYSIDE:
     from PySide.QtCore import *
-    from PySide.QtGui import (QItemSelection, QItemSelectionRange,
-                              QSortFilterProxyModel)
+    from PySide.QtGui import (QItemSelection, QItemSelectionModel,
+                              QItemSelectionRange, QSortFilterProxyModel)
     import PySide.QtCore
     __version__ = PySide.QtCore.__version__
 else:
diff --git a/qtpy/QtDesigner.py b/qtpy/QtDesigner.py
index fc7bd8c..8b2dded 100644
--- a/qtpy/QtDesigner.py
+++ b/qtpy/QtDesigner.py
@@ -9,17 +9,12 @@
 Provides QtDesigner classes and functions.
 """
 
-import os
+from qtpy import PYQT5, PYQT4, PythonQtError
 
-from qtpy import QT_API
-from qtpy import PYQT5_API
-from qtpy import PYQT4_API
-from qtpy import PythonQtError
 
-
-if os.environ[QT_API] in PYQT5_API:
+if PYQT5:
     from PyQt5.QtDesigner import *
-elif os.environ[QT_API] in PYQT4_API:
+elif PYQT4:
     from PyQt4.QtDesigner import *
 else:
     raise PythonQtError('No Qt bindings could be found')
diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py
index 213901d..84049e5 100644
--- a/qtpy/QtGui.py
+++ b/qtpy/QtGui.py
@@ -13,18 +13,12 @@ Provides QtGui classes and functions.
     the ``PyQt5.QtGui`` module.
 """
 
-import os
+from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError
 
-from qtpy import QT_API
-from qtpy import PYQT5_API
-from qtpy import PYQT4_API
-from qtpy import PYSIDE_API
-from qtpy import PythonQtError
 
-
-if os.environ[QT_API] in PYQT5_API:
+if PYQT5:
     from PyQt5.QtGui import *
-elif os.environ[QT_API] in PYQT4_API:
+elif PYQT4:
     from PyQt4.Qt import QKeySequence, QTextCursor
     from PyQt4.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap,
                              QBrush, QClipboard, QCloseEvent, QColor,
@@ -65,7 +59,7 @@ elif os.environ[QT_API] in PYQT4_API:
                              QWindowStateChangeEvent, qAlpha, qBlue,
                              qFuzzyCompare, qGray, qGreen, qIsGray, qRed, qRgb,
                              qRgba, QIntValidator)
-elif os.environ[QT_API] in PYSIDE_API:
+elif PYSIDE:
     from PySide.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap,
                               QBrush, QClipboard, QCloseEvent, QColor,
                               QConicalGradient, QContextMenuEvent, QCursor,
diff --git a/qtpy/QtNetwork.py b/qtpy/QtNetwork.py
index d905638..aca335b 100644
--- a/qtpy/QtNetwork.py
+++ b/qtpy/QtNetwork.py
@@ -10,20 +10,14 @@
 Provides QtNetwork classes and functions.
 """
 
-import os
+from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError
 
-from qtpy import QT_API
-from qtpy import PYQT5_API
-from qtpy import PYQT4_API
-from qtpy import PYSIDE_API
-from qtpy import PythonQtError
 
-
-if os.environ[QT_API] in PYQT5_API:
+if PYQT5:
     from PyQt5.QtNetwork import *
-elif os.environ[QT_API] in PYQT4_API:
+elif PYQT4:
     from PyQt4.QtNetwork import *
-elif os.environ[QT_API] in PYSIDE_API:
+elif PYSIDE:
     from PySide.QtNetwork import *
 else:
     raise PythonQtError('No Qt bindings could be found')
diff --git a/qtpy/QtPrintSupport.py b/qtpy/QtPrintSupport.py
index d728b61..b272174 100644
--- a/qtpy/QtPrintSupport.py
+++ b/qtpy/QtPrintSupport.py
@@ -9,22 +9,16 @@
 Provides QtPrintSupport classes and functions.
 """
 
-import os
+from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError
 
-from qtpy import QT_API
-from qtpy import PYQT5_API
-from qtpy import PYQT4_API
-from qtpy import PYSIDE_API
-from qtpy import PythonQtError
 
-
-if os.environ[QT_API] in PYQT5_API:
+if PYQT5:
     from PyQt5.QtPrintSupport import *
-elif os.environ[QT_API] in PYQT4_API:
+elif PYQT4:
     from PyQt4.QtGui import (QAbstractPrintDialog, QPageSetupDialog,
                              QPrintDialog, QPrintEngine, QPrintPreviewDialog,
                              QPrintPreviewWidget, QPrinter, QPrinterInfo)
-elif os.environ[QT_API] in PYSIDE_API:
+elif PYSIDE:
     from PySide.QtGui import (QAbstractPrintDialog, QPageSetupDialog,
                               QPrintDialog, QPrintEngine, QPrintPreviewDialog,
                               QPrintPreviewWidget, QPrinter, QPrinterInfo)
diff --git a/qtpy/QtSvg.py b/qtpy/QtSvg.py
index 4aca018..10e4183 100644
--- a/qtpy/QtSvg.py
+++ b/qtpy/QtSvg.py
@@ -8,20 +8,14 @@
 Provides QtSvg classes and functions.
 """
 
-import os
+from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError
 
-from qtpy import QT_API
-from qtpy import PYQT5_API
-from qtpy import PYQT4_API
-from qtpy import PYSIDE_API
-from qtpy import PythonQtError
 
-
-if os.environ[QT_API] in PYQT5_API:
+if PYQT5:
     from PyQt5.QtSvg import *
-elif os.environ[QT_API] in PYQT4_API:
+elif PYQT4:
     from PyQt4.QtSvg import *
-elif os.environ[QT_API] in PYSIDE_API:
+elif PYSIDE:
     from PySide.QtSvg import *
 else:
     raise PythonQtError('No Qt bindings could be found')
diff --git a/qtpy/QtTest.py b/qtpy/QtTest.py
index 0f91160..6d59c76 100644
--- a/qtpy/QtTest.py
+++ b/qtpy/QtTest.py
@@ -8,29 +8,21 @@
 
 """
 Provides QtTest and functions
-.. warning:: PySide is not supported here, that's why there is not unit tests
-    running with PySide.
 """
 
-import os
+from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError
 
-from qtpy import QT_API
-from qtpy import PYQT5_API
-from qtpy import PYQT4_API
-from qtpy import PYSIDE_API
-from qtpy import PythonQtError
 
-
-if os.environ[QT_API] in PYQT5_API:
+if PYQT5:
     from PyQt5.QtTest import QTest
-elif os.environ[QT_API] in PYQT4_API:
+elif PYQT4:
     from PyQt4.QtTest import QTest as OldQTest
 
     class QTest(OldQTest):
         @staticmethod
         def qWaitForWindowActive(QWidget):
             OldQTest.qWaitForWindowShown(QWidget)
-elif os.environ[QT_API] in PYSIDE_API:
-    raise ImportError('QtTest support is incomplete for PySide')
+elif PYSIDE:
+    from PySide.QtTest import QTest
 else:
     raise PythonQtError('No Qt bindings could be found')
diff --git a/qtpy/QtWebEngineWidgets.py b/qtpy/QtWebEngineWidgets.py
index c1a6b77..bd07369 100644
--- a/qtpy/QtWebEngineWidgets.py
+++ b/qtpy/QtWebEngineWidgets.py
@@ -10,20 +10,14 @@
 Provides QtWebEngineWidgets classes and functions.
 """
 
-import os
-
-from qtpy import QT_API
-from qtpy import PYQT5_API
-from qtpy import PYQT4_API
-from qtpy import PYSIDE_API
-from qtpy import PythonQtError
+from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError
 
 
 # To test if we are using WebEngine or WebKit
 WEBENGINE = True
 
 
-if os.environ[QT_API] in PYQT5_API:
+if PYQT5:
     try:
         from PyQt5.QtWebEngineWidgets import QWebEnginePage
         from PyQt5.QtWebEngineWidgets import QWebEngineView
@@ -33,12 +27,12 @@ if os.environ[QT_API] in PYQT5_API:
         from PyQt5.QtWebKitWidgets import QWebView as QWebEngineView
         from PyQt5.QtWebKit import QWebSettings as QWebEngineSettings
         WEBENGINE = False
-elif os.environ[QT_API] in PYQT4_API:
+elif PYQT4:
     from PyQt4.QtWebKit import QWebPage as QWebEnginePage
     from PyQt4.QtWebKit import QWebView as QWebEngineView
     from PyQt4.QtWebKit import QWebSettings as QWebEngineSettings
     WEBENGINE = False
-elif os.environ[QT_API] in PYSIDE_API:
+elif PYSIDE:
     from PySide.QtWebKit import QWebPage as QWebEnginePage
     from PySide.QtWebKit import QWebView as QWebEngineView
     from PySide.QtWebKit import QWebSettings as QWebEngineSettings
diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py
index b375969..e1656ab 100644
--- a/qtpy/QtWidgets.py
+++ b/qtpy/QtWidgets.py
@@ -13,18 +13,13 @@ Provides widget classes and functions.
     were the ``PyQt5.QtWidgets`` module.
 """
 
-import os
+from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError
+from qtpy._patch.qcombobox import patch_qcombobox
 
-from qtpy import QT_API
-from qtpy import PYQT5_API
-from qtpy import PYQT4_API
-from qtpy import PYSIDE_API
-from qtpy import PythonQtError
 
-
-if os.environ[QT_API] in PYQT5_API:
+if PYQT5:
     from PyQt5.QtWidgets import *
-elif os.environ[QT_API] in PYQT4_API:
+elif PYQT4:
     from PyQt4.QtGui import *
     QStyleOptionViewItem = QStyleOptionViewItemV4
 
@@ -63,8 +58,13 @@ elif os.environ[QT_API] in PYQT4_API:
          QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo)
 
     # These objects belong to QtCore
-    del (QItemSelection, QItemSelectionRange, QSortFilterProxyModel)
-elif os.environ[QT_API] in PYSIDE_API:
+    del (QItemSelection, QItemSelectionModel, QItemSelectionRange,
+         QSortFilterProxyModel)
+
+    # Patch QComboBox to allow Python objects to be passed to userData
+    patch_qcombobox(QComboBox)
+
+elif PYSIDE:
     from PySide.QtGui import *
     QStyleOptionViewItem = QStyleOptionViewItemV4
 
@@ -103,6 +103,11 @@ elif os.environ[QT_API] in PYSIDE_API:
          QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo)
 
     # These objects belong to QtCore
-    del (QItemSelection, QItemSelectionRange, QSortFilterProxyModel)
+    del (QItemSelection, QItemSelectionModel, QItemSelectionRange,
+         QSortFilterProxyModel)
+
+    # Patch QComboBox to allow Python objects to be passed to userData
+    patch_qcombobox(QComboBox)
+
 else:
     raise PythonQtError('No Qt bindings could be found')
diff --git a/qtpy/__init__.py b/qtpy/__init__.py
index 8ab8a20..b6392f5 100644
--- a/qtpy/__init__.py
+++ b/qtpy/__init__.py
@@ -52,6 +52,9 @@ packages::
 
 import os
 
+# Version of QtPy
+from qtpy._version import __version__
+
 #: Qt API environment variable name
 QT_API = 'QT_API'
 #: names of the expected PyQt5 api
@@ -65,11 +68,8 @@ PYQT4_API = [
 PYSIDE_API = ['pyside']
 
 os.environ.setdefault(QT_API, 'pyqt5')
-assert os.environ[QT_API] in (PYQT5_API + PYQT4_API + PYSIDE_API)
-
 API = os.environ[QT_API]
-API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyqt4': 'PyQt4',
-            'pyside': 'PySide'}[API]
+assert API in (PYQT5_API + PYQT4_API + PYSIDE_API)
 
 is_old_pyqt = is_pyqt46 = False
 PYQT5 = True
@@ -83,11 +83,11 @@ class PythonQtError(Exception):
 
 if API in PYQT5_API:
     try:
-        from PyQt5.QtCore import PYQT_VERSION_STR as __version__
-        from PyQt5 import uic                                     # analysis:ignore
+        from PyQt5.Qt import PYQT_VERSION_STR as PYQT_VERSION  # analysis:ignore
+        from PyQt5.Qt import QT_VERSION_STR as QT_VERSION  # analysis:ignore
+        PYSIDE_VERSION = None
     except ImportError:
         API = os.environ['QT_API'] = 'pyqt'
-        API_NAME = 'PyQt4'
 
 if API in PYQT4_API:
     try:
@@ -103,27 +103,32 @@ if API in PYQT4_API:
         except AttributeError:
             # PyQt < v4.6
             pass
-
-        from PyQt4.QtCore import PYQT_VERSION_STR as __version__  # analysis:ignore
-        from PyQt4 import uic                                     # analysis:ignore
+        from PyQt4.Qt import PYQT_VERSION_STR as PYQT_VERSION  # analysis:ignore
+        from PyQt4.Qt import QT_VERSION_STR as QT_VERSION  # analysis:ignore
+        PYSIDE_VERSION = None
         PYQT5 = False
         PYQT4 = True
     except ImportError:
         API = os.environ['QT_API'] = 'pyside'
-        API_NAME = 'PySide'
     else:
-        is_old_pyqt = __version__.startswith(('4.4', '4.5', '4.6', '4.7'))
-        is_pyqt46 = __version__.startswith('4.6')
-        import sip
-        try:
-            API_NAME += (" (API v{0})".format(sip.getapi('QString')))
-        except AttributeError:
-            pass
+        is_old_pyqt = PYQT_VERSION.startswith(('4.4', '4.5', '4.6', '4.7'))
+        is_pyqt46 = PYQT_VERSION.startswith('4.6')
 
 if API in PYSIDE_API:
     try:
-        from PySide import __version__                            # analysis:ignore
+        from PySide import __version__ as PYSIDE_VERSION  # analysis:ignore
+        from PySide.QtCore import __version__ as QT_VERSION  # analysis:ignore
+        PYQT_VERSION = None
         PYQT5 = False
         PYSIDE = True
     except ImportError:
         raise PythonQtError('No Qt bindings could be found')
+
+API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyqt4': 'PyQt4',
+            'pyside': 'PySide'}[API]
+if PYQT4:
+        import sip
+        try:
+            API_NAME += (" (API v{0})".format(sip.getapi('QString')))
+        except AttributeError:
+            pass
diff --git a/qtpy/_patch/__init__.py b/qtpy/_patch/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/qtpy/_patch/qcombobox.py b/qtpy/_patch/qcombobox.py
new file mode 100644
index 0000000..ec7c01d
--- /dev/null
+++ b/qtpy/_patch/qcombobox.py
@@ -0,0 +1,101 @@
+# The code below, as well as the associated test were adapted from
+# qt-helpers, which was released under a 3-Clause BSD license:
+#
+# Copyright (c) 2015, Chris Beaumont and Thomas Robitaille
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#  * Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+#  * Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the
+#    distribution.
+#  * Neither the name of the Glue project nor the names of its
+#    contributors may be used to endorse or promote products derived
+#    from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+def patch_qcombobox(QComboBox):
+    """
+    In PySide, using Python objects as userData in QComboBox causes
+    Segmentation faults under certain conditions. Even in cases where it
+    doesn't, findData does not work correctly. Likewise, findData also does not
+    work correctly with Python objects when using PyQt4. On the other hand,
+    PyQt5 deals with this case correctly. We therefore patch QComboBox when
+    using PyQt4 and PySide to avoid issues.
+    """
+
+    from qtpy.QtGui import QIcon
+    from qtpy.QtCore import Qt, QObject
+
+    class userDataWrapper():
+        """
+        This class is used to wrap any userData object. If we don't do this,
+        then certain types of objects can cause segmentation faults or issues
+        depending on whether/how __getitem__ is defined.
+        """
+        def __init__(self, data):
+            self.data = data
+
+    _addItem = QComboBox.addItem
+
+    def addItem(self, *args, **kwargs):
+        if len(args) == 3 or (not isinstance(args[0], QIcon)
+                              and len(args) == 2):
+            args, kwargs['userData'] = args[:-1], args[-1]
+        if 'userData' in kwargs:
+            kwargs['userData'] = userDataWrapper(kwargs['userData'])
+        _addItem(self, *args, **kwargs)
+
+    _insertItem = QComboBox.insertItem
+
+    def insertItem(self, *args, **kwargs):
+        if len(args) == 4 or (not isinstance(args[1], QIcon)
+                              and len(args) == 3):
+            args, kwargs['userData'] = args[:-1], args[-1]
+        if 'userData' in kwargs:
+            kwargs['userData'] = userDataWrapper(kwargs['userData'])
+        _insertItem(self, *args, **kwargs)
+
+    _setItemData = QComboBox.setItemData
+
+    def setItemData(self, index, value, role=Qt.UserRole):
+        value = userDataWrapper(value)
+        _setItemData(self, index, value, role=role)
+
+    _itemData = QComboBox.itemData
+
+    def itemData(self, index, role=Qt.UserRole):
+        userData = _itemData(self, index, role=role)
+        if isinstance(userData, userDataWrapper):
+            userData = userData.data
+        return userData
+
+    def findData(self, value):
+        for i in range(self.count()):
+            if self.itemData(i) == value:
+                return i
+        return -1
+
+    QComboBox.addItem = addItem
+    QComboBox.insertItem = insertItem
+    QComboBox.setItemData = setItemData
+    QComboBox.itemData = itemData
+    QComboBox.findData = findData
\ No newline at end of file
diff --git a/qtpy/_version.py b/qtpy/_version.py
index a812ee2..68e807a 100644
--- a/qtpy/_version.py
+++ b/qtpy/_version.py
@@ -1,2 +1,2 @@
-version_info = (1, 0, 2)
+version_info = (1, 1, 1)
 __version__ = '.'.join(map(str, version_info))
diff --git a/qtpy/compat.py b/qtpy/compat.py
index e15beef..ae38090 100644
--- a/qtpy/compat.py
+++ b/qtpy/compat.py
@@ -8,10 +8,10 @@ Compatibility functions
 """
 
 from __future__ import print_function
-import os
 import sys
 import collections
 
+from qtpy import PYQT4
 from qtpy.QtWidgets import QFileDialog
 from qtpy.py3compat import is_text_string, to_text_string, TEXT_TYPES
 
@@ -20,7 +20,7 @@ from qtpy.py3compat import is_text_string, to_text_string, TEXT_TYPES
 # QVariant conversion utilities
 # =============================================================================
 PYQT_API_1 = False
-if os.environ['QT_API'] == 'pyqt':
+if PYQT4:
     import sip
     try:
         PYQT_API_1 = sip.getapi('QVariant') == 1  # PyQt API #1
diff --git a/qtpy/uic.py b/qtpy/uic.py
new file mode 100644
index 0000000..ff049ff
--- /dev/null
+++ b/qtpy/uic.py
@@ -0,0 +1,223 @@
+import os
+
+from qtpy import PYSIDE, PYQT4, PYQT5
+from qtpy.QtWidgets import QComboBox
+
+__all__ = ['loadUi']
+
+if PYQT5:
+
+    from PyQt5.uic import loadUi
+
+elif PYQT4:
+
+    from PyQt4.uic import loadUi
+
+elif PYSIDE:
+
+    # In PySide, loadUi does not exist, so we define it using QUiLoader, and
+    # then make sure we expose that function. This is adapted from qt-helpers
+    # which was released under a 3-clause BSD license:
+    # qt-helpers - a common front-end to various Qt modules
+    #
+    # Copyright (c) 2015, Chris Beaumont and Thomas Robitaille
+    #
+    # All rights reserved.
+    #
+    # Redistribution and use in source and binary forms, with or without
+    # modification, are permitted provided that the following conditions are
+    # met:
+    #
+    #  * Redistributions of source code must retain the above copyright
+    #    notice, this list of conditions and the following disclaimer.
+    #  * Redistributions in binary form must reproduce the above copyright
+    #    notice, this list of conditions and the following disclaimer in the
+    #    documentation and/or other materials provided with the
+    #    distribution.
+    #  * Neither the name of the Glue project nor the names of its contributors
+    #    may be used to endorse or promote products derived from this software
+    #    without specific prior written permission.
+    #
+    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+    # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+    # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+    # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+    # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+    # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+    # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+    # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+    # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+    # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+    # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+    #
+    # Which itself was based on the solution at
+    #
+    # https://gist.github.com/cpbotha/1b42a20c8f3eb9bb7cb8
+    #
+    # which was released under the MIT license:
+    #
+    # Copyright (c) 2011 Sebastian Wiesner <lunaryorn at gmail.com>
... 622 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-qtpy.git



More information about the Python-modules-commits mailing list