From 00c9c1e2a73b02dae944c86cc901487cd4a7aef4 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Tue, 25 Mar 2014 09:21:19 -0400 Subject: [PATCH] Fix ROI.sigRemoveClicked to avoid repeated signal emission Update ROI example to demonstrate removal --- examples/ROIExamples.py | 8 +++++++- pyqtgraph/graphicsItems/ROI.py | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/ROIExamples.py b/examples/ROIExamples.py index 56b15bcf..55c671ad 100644 --- a/examples/ROIExamples.py +++ b/examples/ROIExamples.py @@ -132,7 +132,7 @@ label4 = w4.addLabel(text, row=0, col=0) v4 = w4.addViewBox(row=1, col=0, lockAspect=True) g = pg.GridItem() v4.addItem(g) -r4 = pg.ROI([0,0], [100,100]) +r4 = pg.ROI([0,0], [100,100], removable=True) r4.addRotateHandle([1,0], [0.5, 0.5]) r4.addRotateHandle([0,1], [0.5, 0.5]) img4 = pg.ImageItem(arr) @@ -142,6 +142,12 @@ img4.setParentItem(r4) v4.disableAutoRange('xy') v4.autoRange() +# Provide a callback to remove the ROI (and its children) when +# "remove" is selected from the context menu. +def remove(): + v4.removeItem(r4) +r4.sigRemoveRequested.connect(remove) + diff --git a/pyqtgraph/graphicsItems/ROI.py b/pyqtgraph/graphicsItems/ROI.py index 5494f3e3..179dafdc 100644 --- a/pyqtgraph/graphicsItems/ROI.py +++ b/pyqtgraph/graphicsItems/ROI.py @@ -665,9 +665,7 @@ class ROI(GraphicsObject): def removeClicked(self): ## Send remove event only after we have exited the menu event handler - self.removeTimer = QtCore.QTimer() - self.removeTimer.timeout.connect(lambda: self.sigRemoveRequested.emit(self)) - self.removeTimer.start(0) + QtCore.QTimer.singleShot(0, lambda: self.sigRemoveRequested.emit(self)) def mouseDragEvent(self, ev): if ev.isStart():