Skip to content

Commit b8e570f

Browse files
committed
Fixed some PySide2 compatibility issues
1 parent ef72cd7 commit b8e570f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

qwt/plot_curve.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from qwt.plot_directpainter import QwtPlotDirectPainter
2828
from qwt.qthelpers import qcolor_from_str
2929

30+
from qtpy import PYSIDE2
3031
from qtpy.QtGui import QPen, QBrush, QPainter, QPolygonF, QColor
3132
from qtpy.QtCore import QSize, Qt, QRectF, QPointF
3233

@@ -59,15 +60,23 @@ def series_to_polyline(xMap, yMap, series, from_, to):
5960
"""
6061
Convert series data to QPolygon(F) polyline
6162
"""
62-
polyline = QPolygonF(to - from_ + 1)
63-
pointer = polyline.data()
64-
dtype, tinfo = np.float, np.finfo # integers: = np.int, np.iinfo
65-
pointer.setsize(2 * polyline.size() * tinfo(dtype).dtype.itemsize)
66-
memory = np.frombuffer(pointer, dtype)
67-
memory[: (to - from_) * 2 + 1 : 2] = xMap.transform(series.xData()[from_ : to + 1])
68-
memory[1 : (to - from_) * 2 + 2 : 2] = yMap.transform(
69-
series.yData()[from_ : to + 1]
70-
)
63+
size = to - from_ + 1
64+
polyline = QPolygonF(size)
65+
if not PYSIDE2:
66+
pointer = polyline.data()
67+
dtype, tinfo = np.float, np.finfo # integers: = np.int, np.iinfo
68+
pointer.setsize(2 * polyline.size() * tinfo(dtype).dtype.itemsize)
69+
memory = np.frombuffer(pointer, dtype)
70+
memory[: (to - from_) * 2 + 1 : 2] = xMap.transform(
71+
series.xData()[from_ : to + 1]
72+
)
73+
memory[1 : (to - from_) * 2 + 2 : 2] = yMap.transform(
74+
series.yData()[from_ : to + 1]
75+
)
76+
else:
77+
polyline.clear()
78+
for index in range(size):
79+
polyline.append(QPointF(series.xData()[index], series.yData()[index]))
7180
return polyline
7281

7382

qwt/text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
)
6363
from qtpy.QtWidgets import QFrame, QWidget, QSizePolicy, QApplication
6464
from qtpy.QtCore import Qt, QSizeF, QSize, QRectF
65+
from qtpy import PYSIDE2
6566

6667
from qwt.painter import QwtPainter
6768
from qwt.qthelpers import qcolor_from_str
@@ -436,7 +437,7 @@ def mightRender(self, text):
436437
:param str text: Text to be tested
437438
:return: True, if it can be rendered
438439
"""
439-
return Qt.mightBeRichText(text)
440+
return PYSIDE2 or Qt.mightBeRichText(text)
440441

441442
def textMargins(self, font):
442443
"""

0 commit comments

Comments
 (0)