Skip to content

Commit 4e6a8a6

Browse files
author
Pierre Raybaut
committed
Supporting deprecated features (better compatibility with Qwt5) with warnings
1 parent 7e6690b commit 4e6a8a6

File tree

5 files changed

+103
-6
lines changed

5 files changed

+103
-6
lines changed

qwt/__init__.py

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11

22
QWT_VERSION_STR = '6.1.2'
33

4+
import warnings
5+
46
from qwt.qwt_plot import QwtPlot
5-
from qwt.qwt_symbol import QwtSymbol
7+
from qwt.qwt_symbol import QwtSymbol as QSbl # see deprecated section
68
from qwt.qwt_scale_engine import QwtLinearScaleEngine, QwtLogScaleEngine
79
from qwt.qwt_text import QwtText
810
from qwt.qwt_plot_canvas import QwtPlotCanvas
9-
from qwt.qwt_plot_curve import QwtPlotCurve, QwtPlotItem
11+
from qwt.qwt_plot_curve import QwtPlotCurve as QPC # see deprecated section
12+
from qwt.qwt_plot_curve import QwtPlotItem
1013
from qwt.qwt_scale_map import QwtScaleMap
1114
from qwt.qwt_interval import QwtInterval
1215
from qwt.qwt_legend import QwtLegend
1316
from qwt.qwt_plot_marker import QwtPlotMarker
14-
from qwt.qwt_plot_grid import QwtPlotGrid
17+
from qwt.qwt_plot_grid import QwtPlotGrid as QPG # see deprecated section
1518
from qwt.qwt_color_map import QwtLinearColorMap
1619

1720
from qwt.toqimage import toQImage
@@ -26,4 +29,74 @@
2629

2730
from qwt.qwt_plot_renderer import QwtPlotRenderer
2831

32+
33+
## ============================================================================
34+
## Deprecated classes and attributes (to be removed in next major release)
35+
## ============================================================================
36+
# Remove deprecated QwtPlotItem.setAxis (replaced by setAxes)
37+
# Remove deprecated QwtPlotCanvas.invalidatePaintCache (replaced by replot)
38+
## ============================================================================
39+
class QwtDoubleInterval(QwtInterval):
40+
def __init__(self, minValue=0., maxValue=-1., borderFlags=None):
41+
warnings.warn("`QwtDoubleInterval` has been removed in Qwt6: "\
42+
"please use `QwtInterval` instead", RuntimeWarning)
43+
super(QwtDoubleInterval, self).__init__(minValue, maxValue, borderFlags)
44+
## ============================================================================
45+
class QwtLog10ScaleEngine(QwtLogScaleEngine):
46+
def __init__(self):
47+
warnings.warn("`QwtLog10ScaleEngine` has been removed in Qwt6: "\
48+
"please use `QwtLogScaleEngine` instead",
49+
RuntimeWarning)
50+
super(QwtLog10ScaleEngine, self).__init__(10)
51+
## ============================================================================
52+
class QwtPlotPrintFilter(object):
53+
def __init__(self):
54+
raise NotImplementedError("`QwtPlotPrintFilter` has been removed in Qwt6: "\
55+
"please rely on `QwtPlotRenderer` instead")
56+
## ============================================================================
57+
class QwtPlotCurve(QPC):
58+
@property
59+
def Yfx(self):
60+
raise NotImplementedError("`Yfx` attribute has been removed "\
61+
"(curve types are no longer implemented in Qwt6)")
62+
@property
63+
def Xfy(self):
64+
raise NotImplementedError("`Yfx` attribute has been removed "\
65+
"(curve types are no longer implemented in Qwt6)")
66+
## ============================================================================
67+
class QwtSymbol(QSbl):
68+
def draw(self, painter, *args):
69+
warnings.warn("`draw` has been removed in Qwt6: "\
70+
"please rely on `drawSymbol` and `drawSymbols` instead",
71+
RuntimeWarning)
72+
from qwt.qt.QtCore import QPointF
73+
if len(args) == 2:
74+
self.drawSymbols(painter, [QPointF(*args)])
75+
else:
76+
self.drawSymbol(painter, *args)
77+
## ============================================================================
78+
class QwtPlotGrid(QPG):
79+
def majPen(self):
80+
warnings.warn("`majPen` has been removed in Qwt6: "\
81+
"please use `majorPen` instead",
82+
RuntimeWarning)
83+
return self.majorPen()
84+
def minPen(self):
85+
warnings.warn("`minPen` has been removed in Qwt6: "\
86+
"please use `minorPen` instead",
87+
RuntimeWarning)
88+
return self.minorPen()
89+
def setMajPen(self, *args):
90+
warnings.warn("`setMajPen` has been removed in Qwt6: "\
91+
"please use `setMajorPen` instead",
92+
RuntimeWarning)
93+
return self.setMajorPen(*args)
94+
def setMinPen(self, *args):
95+
warnings.warn("`setMinPen` has been removed in Qwt6: "\
96+
"please use `setMinorPen` instead",
97+
RuntimeWarning)
98+
return self.setMinorPen(*args)
99+
## ============================================================================
100+
101+
29102
#TODO: implement QwtClipper: needed for SVG export for example

qwt/qwt_clipper.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def intersection(self, p1, p2):
4747

4848
class PointBuffer(object):
4949
def __init__(self, capacity=0):
50-
self.capacity = capacity
50+
self.m_capacity = capacity
5151
self.m_size = 0
5252
self.m_buffer = None
5353
if capacity > 0:
@@ -56,8 +56,19 @@ def __init__(self, capacity=0):
5656
def setPoints(self, numPoints, points):
5757
self.reserve(numPoints)
5858
self.m_size = numPoints
59-
60-
59+
60+
def reset(self):
61+
self.m_size = 0
62+
63+
def size(self):
64+
return self.m_size
65+
66+
def data(self):
67+
return self.m_buffer
68+
69+
def operator(self, i):
70+
return self.m_buffer[i]
71+
6172

6273

6374
class QwtClipper(object):

qwt/qwt_interval.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,4 @@ def extend(self, value):
237237
return self
238238
return QwtInterval(min([value, self.__minValue]),
239239
max([value, self.__maxValue]))
240+

qwt/qwt_plot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,12 @@ def setAxes(self, xAxis, yAxis):
10221022
if yAxis == QwtPlot.yLeft or yAxis == QwtPlot.yRight:
10231023
self.__data.yAxis = yAxis
10241024
self.itemChanged()
1025+
1026+
def setAxis(self, xAxis, yAxis):
1027+
import warnings
1028+
warnings.warn("`setAxis` has been removed in Qwt6: "\
1029+
"please use `setAxes` instead", RuntimeWarning)
1030+
self.setAxes(xAxis, yAxis)
10251031

10261032
def setXAxis(self, axis):
10271033
if axis in (QwtPlot.xBottom, QwtPlot.xTop):

qwt/qwt_plot_canvas.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,12 @@ def replot(self):
522522
else:
523523
self.update(self.contentsRect())
524524

525+
def invalidatePaintCache(self):
526+
import warnings
527+
warnings.warn("`invalidatePaintCache` has been removed: "\
528+
"please use `replot` instead", RuntimeWarning)
529+
self.replot()
530+
525531
def updateStyleSheetInfo(self):
526532
if not self.testAttribute(Qt.WA_StyledBackground):
527533
return

0 commit comments

Comments
 (0)