Skip to content

Commit 468a62c

Browse files
committed
Restored compatibility with original Qwt signals (QwtPlot, ...)
1 parent e0efb4c commit 468a62c

File tree

7 files changed

+75
-35
lines changed

7 files changed

+75
-35
lines changed

qwt/legend.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,35 @@ class QwtLegend(QwtAbstractLegend):
177177
Constructor
178178
179179
:param QWidget parent: Parent widget
180+
181+
.. py:data:: clicked
182+
183+
A signal which is emitted when the user has clicked on
184+
a legend label, which is in `QwtLegendData.Clickable` mode.
185+
186+
:param itemInfo: Info for the item item of the selected legend item
187+
:param index: Index of the legend label in the list of widgets that are associated with the plot item
188+
189+
.. note::
190+
191+
Clicks are disabled as default
192+
193+
.. py:data:: checked
194+
195+
A signal which is emitted when the user has clicked on
196+
a legend label, which is in `QwtLegendData.Checkable` mode
197+
198+
:param itemInfo: Info for the item of the selected legend label
199+
:param index: Index of the legend label in the list of widgets that are associated with the plot item
200+
:param on: True when the legend label is checked
201+
202+
.. note::
203+
204+
Clicks are disabled as default
180205
"""
181206

182-
SIG_CLICKED = Signal("PyQt_PyObject", int)
183-
SIG_CHECKED = Signal("PyQt_PyObject", bool, int)
207+
clicked = Signal("PyQt_PyObject", int)
208+
checked = Signal("PyQt_PyObject", bool, int)
184209

185210
def __init__(self, parent=None):
186211
QwtAbstractLegend.__init__(self, parent)
@@ -338,8 +363,8 @@ def createWidget(self, data):
338363
"""
339364
label = QwtLegendLabel()
340365
label.setItemMode(self.defaultItemMode())
341-
label.SIG_CLICKED.connect(lambda: self.itemClicked(label))
342-
label.SIG_CHECKED.connect(lambda state: self.itemChecked(state, label))
366+
label.clicked.connect(lambda: self.itemClicked(label))
367+
label.checked.connect(lambda state: self.itemChecked(state, label))
343368
return label
344369

345370
def updateWidget(self, widget, data):
@@ -421,7 +446,7 @@ def itemClicked(self, widget):
421446
widgetList = self.__data.itemMap.legendWidgets(itemInfo)
422447
if w in widgetList:
423448
index = widgetList.index(w)
424-
self.SIG_CLICKED.emit(itemInfo, index)
449+
self.clicked.emit(itemInfo, index)
425450

426451
def itemChecked(self, on, widget):
427452
# w = self.sender() #TODO: cast to QWidget
@@ -432,7 +457,7 @@ def itemChecked(self, on, widget):
432457
widgetList = self.__data.itemMap.legendWidgets(itemInfo)
433458
if w in widgetList:
434459
index = widgetList.index(w)
435-
self.SIG_CHECKED.emit(itemInfo, on, index)
460+
self.checked.emit(itemInfo, on, index)
436461

437462
def renderLegend(self, painter, rect, fillBackground):
438463
"""

qwt/legend_label.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def __init__(self):
4545
class QwtLegendLabel(QwtTextLabel):
4646
"""A widget representing something on a QwtLegend."""
4747

48-
SIG_CLICKED = Signal()
49-
SIG_PRESSED = Signal()
50-
SIG_RELEASED = Signal()
51-
SIG_CHECKED = Signal(bool)
48+
clicked = Signal()
49+
pressed = Signal()
50+
released = Signal()
51+
checked = Signal(bool)
5252

5353
def __init__(self, parent=None):
5454
QwtTextLabel.__init__(self, parent)
@@ -229,12 +229,12 @@ def setDown(self, down):
229229
self.update()
230230
if self.__data.itemMode == QwtLegendData.Clickable:
231231
if self.__data.isDown:
232-
self.SIG_PRESSED.emit()
232+
self.pressed.emit()
233233
else:
234-
self.SIG_RELEASED.emit()
235-
self.SIG_CLICKED.emit()
234+
self.released.emit()
235+
self.clicked.emit()
236236
if self.__data.itemMode == QwtLegendData.Checkable:
237-
self.SIG_CHECKED.emit(self.__data.isDown)
237+
self.checked.emit(self.__data.isDown)
238238

239239
def isDown(self):
240240
"""

qwt/plot.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939

4040
def qwtEnableLegendItems(plot, on):
4141
if on:
42-
plot.SIG_LEGEND_DATA_CHANGED.connect(plot.updateLegendItems)
42+
plot.legendDataChanged.connect(plot.updateLegendItems)
4343
else:
44-
plot.SIG_LEGEND_DATA_CHANGED.disconnect(plot.updateLegendItems)
44+
plot.legendDataChanged.disconnect(plot.updateLegendItems)
4545

4646
def qwtSetTabOrder(first, second, with_children):
4747
tab_chain = [first, second]
@@ -255,10 +255,26 @@ class QwtPlot(QFrame, QwtPlotDict):
255255
256256
:param str title: Title text
257257
:param QWidget parent: Parent widget
258+
259+
.. py:data:: itemAttached
260+
261+
A signal indicating, that an item has been attached/detached
262+
263+
:param plotItem: Plot item
264+
:param on: Attached/Detached
265+
266+
.. py:data:: legendDataChanged
267+
268+
A signal with the attributes how to update
269+
the legend entries for a plot item.
270+
271+
:param itemInfo: Info about a plot item, build from itemToInfo()
272+
:param data: Attributes of the entries (usually <= 1) for the plot item.
273+
258274
"""
259275

260-
SIG_ITEM_ATTACHED = Signal("PyQt_PyObject", bool)
261-
SIG_LEGEND_DATA_CHANGED = Signal("PyQt_PyObject", "PyQt_PyObject")
276+
itemAttached = Signal("PyQt_PyObject", bool)
277+
legendDataChanged = Signal("PyQt_PyObject", "PyQt_PyObject")
262278

263279
# enum Axis
264280
yLeft, yRight, xBottom, xTop, axisCnt = list(range(5))
@@ -1432,8 +1448,7 @@ def insertLegend(self, legend, pos=None, ratio=-1):
14321448
del self.__data.legend
14331449
self.__data.legend = legend
14341450
if self.__data.legend:
1435-
self.SIG_LEGEND_DATA_CHANGED.connect(
1436-
self.__data.legend.updateLegend)
1451+
self.legendDataChanged.connect(self.__data.legend.updateLegend)
14371452
if self.__data.legend.parent() is not self:
14381453
self.__data.legend.setParent(self)
14391454

@@ -1467,14 +1482,14 @@ def insertLegend(self, legend, pos=None, ratio=-1):
14671482

14681483
def updateLegend(self, plotItem=None):
14691484
"""
1470-
If plotItem is None, emit QwtPlot.SIG_LEGEND_DATA_CHANGED for all
1485+
If plotItem is None, emit QwtPlot.legendDataChanged for all
14711486
plot item. Otherwise, emit the signal for passed plot item.
14721487
14731488
:param qwt.plot.QwtPlotItem plotItem: Plot item
14741489
14751490
.. seealso::
14761491
1477-
:py:meth:`QwtPlotItem.legendData()`, :py:data:`QwtPlot.SIG_LEGEND_DATA_CHANGED`
1492+
:py:meth:`QwtPlotItem.legendData()`, :py:data:`QwtPlot.legendDataChanged`
14781493
"""
14791494
if plotItem is None:
14801495
items = list(self.itemList())
@@ -1486,7 +1501,7 @@ def updateLegend(self, plotItem=None):
14861501
legendData = []
14871502
if plotItem.testItemAttribute(QwtPlotItem.Legend):
14881503
legendData = plotItem.legendData()
1489-
self.SIG_LEGEND_DATA_CHANGED.emit(plotItem, legendData)
1504+
self.legendDataChanged.emit(plotItem, legendData)
14901505

14911506
def updateLegendItems(self, plotItem, legendData):
14921507
"""
@@ -1527,13 +1542,13 @@ def attachItem(self, plotItem, on):
15271542
else:
15281543
self.removeItem(plotItem)
15291544

1530-
self.SIG_ITEM_ATTACHED.emit(plotItem, on)
1545+
self.itemAttached.emit(plotItem, on)
15311546

15321547
if plotItem.testItemAttribute(QwtPlotItem.Legend):
15331548
if on:
15341549
self.updateLegend(plotItem)
15351550
else:
1536-
self.SIG_LEGEND_DATA_CHANGED.emit(plotItem, [])
1551+
self.legendDataChanged.emit(plotItem, [])
15371552

15381553
self.autoRefresh()
15391554

qwt/scale_widget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class QwtScaleWidget(QWidget):
7373
:param QWidget parent: Parent widget
7474
"""
7575

76-
SIG_SCALE_DIV_CHANGED = Signal()
76+
scaleDivChanged = Signal()
7777

7878
# enum LayoutFlag
7979
TitleInverted = 1
@@ -694,7 +694,7 @@ def setScaleDiv(self, scaleDiv):
694694
if sd.scaleDiv() != scaleDiv:
695695
sd.setScaleDiv(scaleDiv)
696696
self.layoutScale()
697-
self.SIG_SCALE_DIV_CHANGED.emit()
697+
self.scaleDivChanged.emit()
698698

699699
def setTransformation(self, transformation):
700700
"""

qwt/tests/CPUplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def __init__(self, *args):
347347

348348
self.startTimer(1000)
349349

350-
legend.SIG_CHECKED.connect(self.showCurve)
350+
legend.checked.connect(self.showCurve)
351351
self.replot()
352352

353353
def timerEvent(self, e):

qwt/tests/EventFilterDemo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
class ColorBar(QWidget):
23-
SIG_COLOR_SELECTED = Signal(QColor)
23+
colorSelected = Signal(QColor)
2424

2525
def __init__(self, orientation, *args):
2626
QWidget.__init__(self, *args)
@@ -63,7 +63,7 @@ def mousePressEvent(self, event):
6363
pm = QPixmap.grabWidget(self)
6464
color = QColor()
6565
color.setRgb(pm.toImage().pixel(event.x(), event.y()))
66-
self.SIG_COLOR_SELECTED.emit(color)
66+
self.colorSelected.emit(color)
6767
event.accept()
6868

6969
def paintEvent(self, _):
@@ -136,7 +136,7 @@ def __init__(self, *args):
136136
self.__colorBar.setRange(
137137
QColor(Qt.red), QColor(Qt.darkBlue))
138138
self.__colorBar.setFocusPolicy(Qt.TabFocus)
139-
self.__colorBar.SIG_COLOR_SELECTED.connect(self.setCanvasColor)
139+
self.__colorBar.colorSelected.connect(self.setCanvasColor)
140140

141141
# we need the resize events, to lay out the color bar
142142
scaleWidget.installEventFilter(self)
@@ -376,7 +376,7 @@ def __shiftPointCursor(self, up):
376376

377377

378378
class ScalePicker(QObject):
379-
SIG_CLICKED = Signal(int, float)
379+
clicked = Signal(int, float)
380380

381381
def __init__(self, plot):
382382
QObject.__init__(self, plot)
@@ -412,7 +412,7 @@ def __mouseClicked(self, scale, pos):
412412
elif scale.alignment() == QwtScaleDraw.TopScale:
413413
value = sd.scaleMap().invTransform(pos.x())
414414
axis = QwtPlot.xBottom
415-
self.SIG_CLICKED.emit(axis, value)
415+
self.clicked.emit(axis, value)
416416

417417
def __scaleRect(self, scale):
418418
bld = scale.margin()
@@ -447,7 +447,7 @@ def make():
447447
)
448448
CanvasPicker(plot)
449449
scalePicker = ScalePicker(plot)
450-
scalePicker.SIG_CLICKED.connect(plot.insertCurve)
450+
scalePicker.clicked.connect(plot.insertCurve)
451451
demo.resize(540, 400)
452452
demo.show()
453453
return demo

qwt/tests/ImagePlotDemo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def __init__(self, *args):
167167
plotImage.setData(square(512, -2*np.pi, 2*np.pi),
168168
(-2*np.pi, 2*np.pi), (-2*np.pi, 2*np.pi))
169169

170-
legend.SIG_CLICKED.connect(self.toggleVisibility)
170+
legend.clicked.connect(self.toggleVisibility)
171171

172172
# replot
173173
self.replot()

0 commit comments

Comments
 (0)