Skip to content

Commit 58a5d38

Browse files
committed
Added support for QtPy 2, PyQt6, PySide6
1 parent 4fc7a03 commit 58a5d38

25 files changed

+149
-188
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# PythonQwt Releases
22

3+
## Version 0.10.0
4+
5+
- Added support for QtPy 2, PyQt6 and PySide6.
6+
- Dropped support for Python 2.
7+
38
## Version 0.9.2
49

510
- Curve plotting: added support for `numpy.float32` data type.

README.md

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ from qwt import tests
5555
tests.run()
5656
```
5757

58-
or from the command line (script name depends on Python major version number):
58+
or from the command line:
5959

6060
```bash
61-
PythonQwt-py3
61+
PythonQwt
6262
```
6363

6464
Tests may also be executed in unattended mode:
6565

6666
```bash
67-
PythonQwt-tests-py3 --mode unattended
67+
PythonQwt-tests --mode unattended
6868
```
6969

7070
## Overview
@@ -87,65 +87,11 @@ for more details on API limitations when comparing to Qwt.
8787

8888
### Requirements
8989

90-
- Python >=2.6 or Python >=3.2
91-
- PyQt4 >=4.4 or PyQt5 >= 5.5 (or PySide2, still experimental, see below)
90+
- Python >=3.4
91+
- PyQt4, PyQt5, PyQt6 or PySide6
9292
- QtPy >= 1.3
9393
- NumPy >= 1.5
9494

95-
### Why PySide2 support is still experimental
96-
97-
![PyQt5 vs PySide2](doc/images/pyqt5_vs_pyside2.png)
98-
99-
Try running the `curvebenchmark1.py` test with PyQt5 and PySide: you will notice a
100-
huge performance issue with PySide2 (see screenshot above). This is due to the fact
101-
that `QPainter.drawPolyline` (the `QPainter.drawPolyline` method has already been
102-
optimized thanks to Cristian Maureira-Fredes from Python-Qt development team, see
103-
[this bug report](https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1366)) is
104-
much more efficient in PyQt5 than it is in PySide2 (see
105-
[this bug report](https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1540)).
106-
107-
As a consequence, until this bug is fixed in PySide2, we still recommend using PyQt5
108-
instead of PySide2 when it comes to representing huge data sets (except if you do not
109-
use the "dots" style for drawing curves).
110-
111-
However, PySide2 support was significatively improved betwen PythonQwt V0.8.0 and
112-
V0.8.1 thanks to the new `array2d_to_qpolygonf` function (see the part related to
113-
PySide2 in the code below).
114-
115-
```python
116-
def array2d_to_qpolygonf(xdata, ydata):
117-
"""
118-
Utility function to convert two 1D-NumPy arrays representing curve data
119-
(X-axis, Y-axis data) into a single polyline (QtGui.PolygonF object).
120-
This feature is compatible with PyQt4, PyQt5 and PySide2 (requires QtPy).
121-
122-
License/copyright: MIT License © Pierre Raybaut 2020.
123-
124-
:param numpy.ndarray xdata: 1D-NumPy array (numpy.float64)
125-
:param numpy.ndarray ydata: 1D-NumPy array (numpy.float64)
126-
:return: Polyline
127-
:rtype: QtGui.QPolygonF
128-
"""
129-
dtype = np.float64
130-
if not (
131-
xdata.size == ydata.size == xdata.shape[0] == ydata.shape[0]
132-
and xdata.dtype == ydata.dtype == dtype
133-
):
134-
raise ValueError("Arguments must be 1D, float64 NumPy arrays with same size")
135-
size = xdata.size
136-
polyline = QPolygonF(size)
137-
if PYSIDE2: # PySide2 (obviously...)
138-
address = shiboken2.getCppPointer(polyline.data())[0]
139-
buffer = (ctypes.c_double * 2 * size).from_address(address)
140-
else: # PyQt4, PyQt5
141-
buffer = polyline.data()
142-
buffer.setsize(2 * size * np.finfo(dtype).dtype.itemsize)
143-
memory = np.frombuffer(buffer, dtype)
144-
memory[: (size - 1) * 2 + 1 : 2] = xdata
145-
memory[1 : (size - 1) * 2 + 2 : 2] = ydata
146-
return polyline
147-
```
148-
14995
## Installation
15096

15197
From the source package:

doc/examples/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ The two lines above execute the ``PythonQwt`` test launcher:
1616
.. image:: /../qwt/tests/data/testlauncher.png
1717

1818
GUI-based test launcher can be executed from the command line thanks to the
19-
``PythonQwt-py3`` test script (or ``PythonQwt-py2`` for Python 2).
19+
``PythonQwt`` test script.
2020

2121
Unit tests may be executed from the commande line thanks to the console-based script
22-
``PythonQwt-tests-py3``: ``PythonQwt-tests-py3 --mode unattended``.
22+
``PythonQwt-tests``: ``PythonQwt-tests --mode unattended``.
2323

2424
Tests
2525
-----

doc/images/QwtPlot_example.png

-22.3 KB
Loading

doc/images/pyqt5_vs_pyside2.png

-18.1 KB
Binary file not shown.

doc/images/symbol_path_example.png

-17 Bytes
Loading

doc/installation.rst

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Dependencies
55
------------
66

77
Requirements:
8-
* Python 2.x (x>=6) or 3.x (x>=2)
9-
* PyQt4 4.x (x>=4) or PyQt5 5.x (x>=5) or PySide2 (still experimental, see below)
8+
* Python 3.x (x>=4)
9+
* PyQt4 4.x (x>=4), PyQt5 5.x (x>=5), PyQt6 or PySide6
1010
* QtPy >= 1.3
1111
* NumPy 1.x (x>=5)
1212
* Sphinx 1.x (x>=1) for documentation generation
@@ -18,25 +18,6 @@ From the source package:
1818

1919
`python setup.py install`
2020

21-
Why PySide2 support is still experimental
22-
-----------------------------------------
23-
24-
.. image:: /images/pyqt5_vs_pyside2.png
25-
26-
Try running the `curvebenchmark1.py` test with PyQt5 and PySide: you will notice a
27-
huge performance issue with PySide2 (see screenshot above). This is due to the fact
28-
that `QPainter.drawPolyline` is much more efficient in PyQt5 than it is in PySide2
29-
(see `this bug report <https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1366>`_).
30-
31-
As a consequence, until this bug is fixed in PySide2, we still recommend using PyQt5
32-
instead of PySide2 when it comes to representing huge data sets.
33-
34-
However, PySide2 support was significatively improved betwen PythonQwt V0.8.0 and
35-
V0.8.1 thanks to the new `array2d_to_qpolygonf` function (see code below).
36-
37-
.. literalinclude:: /../qwt/plot_curve.py
38-
:pyobject: array2d_to_qpolygonf
39-
4021
Help and support
4122
----------------
4223

qwt/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
1111
The ``PythonQwt`` package is a 2D-data plotting library using Qt graphical
1212
user interfaces for the Python programming language. It is compatible with
13-
both ``PyQt4`` and ``PyQt5`` (``PySide`` is currently not supported but it
14-
could be in the near future as it would "only" requires testing to support
15-
it as a stable alternative to PyQt).
13+
``PyQt4``, ``PyQt5``, ``PyQt6`` and ``PySide6``.
1614
1715
It consists of a single Python package named `qwt` which is a pure Python
1816
implementation of Qwt C++ library with some limitations.
@@ -28,7 +26,7 @@
2826
.. _GitHubPage: http://pierreraybaut.github.io/PythonQwt
2927
.. _GitHub: https://github.com/PierreRaybaut/PythonQwt
3028
"""
31-
__version__ = "0.9.2"
29+
__version__ = "0.10.0"
3230
QWT_VERSION_STR = "6.1.5"
3331

3432
import warnings

qwt/legend.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ def sizeHint(self):
390390
sz.setHeight(max([sz.height(), self.__data.icon.height() + 4]))
391391
if self.__data.itemMode != QwtLegendData.ReadOnly:
392392
sz += buttonShift(self)
393-
sz = sz.expandedTo(QApplication.globalStrut())
394393
return sz
395394

396395
def paintEvent(self, e):
@@ -912,7 +911,7 @@ def renderLegend(self, painter, rect, fillBackground):
912911
legendLayout = self.__data.view.contentsWidget.layout()
913912
if legendLayout is None:
914913
return
915-
left, right, top, bottom = self.getContentsMargins()
914+
left, right, top, bottom = self.layout().getContentsMargins()
916915
layoutRect = QRect()
917916
layoutRect.setLeft(math.ceil(rect.left()) + left)
918917
layoutRect.setTop(math.ceil(rect.top()) + top)

qwt/null_paintdevice.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
:members:
1414
"""
1515

16+
import os
17+
1618
from qtpy.QtGui import QPaintEngine, QPainterPath, QPaintDevice
17-
from qtpy import PYSIDE2
19+
20+
QT_API = os.environ["QT_API"]
1821

1922

2023
class QwtNullPaintDevice_PrivateData(object):
@@ -59,7 +62,7 @@ def drawLines(self, lines, lineCount=None):
5962
device = self.nullDevice()
6063
if device is None:
6164
return
62-
if device.mode() != QwtNullPaintDevice.NormalMode and not PYSIDE2:
65+
if device.mode() != QwtNullPaintDevice.NormalMode and QT_API.startswith("pyqt"):
6366
try:
6467
QPaintEngine.drawLines(lines, lineCount)
6568
except TypeError:

0 commit comments

Comments
 (0)