From f645f8894ce73432905985d15ba20cdfb2983bf1 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 29 May 2020 09:35:22 +0200 Subject: [PATCH 1/6] Do not display the center at creation --- silx/gui/plot/items/roi.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/silx/gui/plot/items/roi.py b/silx/gui/plot/items/roi.py index d2a2ef003a..2145f824cb 100644 --- a/silx/gui/plot/items/roi.py +++ b/silx/gui/plot/items/roi.py @@ -1836,6 +1836,9 @@ def creationStarted(self): color = self._computeHandleColor(rgba(self.getColor())) self._handleClose.setColor(color) + # Hide the center while creating the first shape + self._handleCenter.setSymbol("") + # In interaction replace the polygon by a line, to display something unclosed self.removeItem(self.__shape) self.__shape = self.__createShape(interaction=True) @@ -1851,6 +1854,8 @@ def creationFinalized(self): self.__shape = self.__createShape() self.__shape.setPoints(self._points) self.addItem(self.__shape) + # Hide the center while creating the first shape + self._handleCenter.setSymbol("+") def _updateText(self, text): self._handleLabel.setText(text) From e3887c5857e597f1fcdde3c84dd4d06e7ed6acab Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 29 May 2020 11:36:27 +0200 Subject: [PATCH 2/6] Call creationStarted before the first use of setFirstShapePoints --- silx/gui/plot/tools/roi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/silx/gui/plot/tools/roi.py b/silx/gui/plot/tools/roi.py index 44edf5cee0..b6640cf0c1 100644 --- a/silx/gui/plot/tools/roi.py +++ b/silx/gui/plot/tools/roi.py @@ -338,7 +338,6 @@ def _handleInteraction(self, event): # NOTE: Set something before createRoi, so isDrawing is True self._drawnROI = object() self._drawnROI = self.createRoi(roiClass, points=points) - self._drawnROI.creationStarted() else: self._drawnROI.setFirstShapePoints(points) @@ -469,6 +468,7 @@ def createRoi(self, roiClass, points, label=None, index=None): roi = roiClass(parent=None) if label is not None: roi.setName(str(label)) + roi.creationStarted() roi.setFirstShapePoints(points) self.addRoi(roi, index) From 4d047503eed99885bf4d1d478930cd8ec6606183 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 29 May 2020 11:39:13 +0200 Subject: [PATCH 3/6] Hide the handles at the creation --- silx/gui/plot/items/roi.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/silx/gui/plot/items/roi.py b/silx/gui/plot/items/roi.py index 2145f824cb..b08da02e2b 100644 --- a/silx/gui/plot/items/roi.py +++ b/silx/gui/plot/items/roi.py @@ -1845,6 +1845,10 @@ def creationStarted(self): self.__shape.setPoints(self._points) self.addItem(self.__shape) + def isBeingCreated(self): + """Returns true if the ROI is in creation step""" + return self._handleClose is not None + def creationFinalized(self): """"Called when the ROI creation interaction was finalized. """ @@ -1856,6 +1860,8 @@ def creationFinalized(self): self.addItem(self.__shape) # Hide the center while creating the first shape self._handleCenter.setSymbol("+") + for handle in self._handlePoints: + handle.setSymbol("s") def _updateText(self, text): self._handleLabel.setText(text) @@ -1884,6 +1890,8 @@ def setPoints(self, points): if len(self._handlePoints) < len(points): handle = self.addHandle() self._handlePoints.append(handle) + if self.isBeingCreated(): + handle.setSymbol("") else: handle = self._handlePoints.pop(-1) self.removeHandle(handle) From 605637236fb83a83882b0486bece854b49b86a8a Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 29 May 2020 11:51:16 +0200 Subject: [PATCH 4/6] Make createRoi private --- silx/gui/plot/tools/roi.py | 10 ++++++---- silx/gui/plot/tools/test/testROI.py | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/silx/gui/plot/tools/roi.py b/silx/gui/plot/tools/roi.py index b6640cf0c1..431ecb2226 100644 --- a/silx/gui/plot/tools/roi.py +++ b/silx/gui/plot/tools/roi.py @@ -326,7 +326,9 @@ def _handleInteraction(self, event): if event['event'] == 'mouseClicked' and event['button'] == 'left': points = numpy.array([(event['x'], event['y'])], dtype=numpy.float64) - roi = self.createRoi(roiClass, points=points) + # Not an interactive creation + roi = self._createInteractiveRoi(roiClass, points=points) + roi.creationFinalized() self.sigInteractiveRoiFinalized.emit(roi) else: # other shapes if (event['event'] in ('drawingProgress', 'drawingFinished') and @@ -337,7 +339,7 @@ def _handleInteraction(self, event): if self._drawnROI is None: # Create new ROI # NOTE: Set something before createRoi, so isDrawing is True self._drawnROI = object() - self._drawnROI = self.createRoi(roiClass, points=points) + self._drawnROI = self._createInteractiveRoi(roiClass, points=points) else: self._drawnROI.setFirstShapePoints(points) @@ -452,8 +454,8 @@ def _regionOfInterestChanged(self, event=None): """Handle ROI object changed""" self.sigRoiChanged.emit() - def createRoi(self, roiClass, points, label=None, index=None): - """Create a new ROI and add it to list of ROIs. + def _createInteractiveRoi(self, roiClass, points, label=None, index=None): + """Create a new ROI with interactive creation. :param class roiClass: The class of the ROI to create :param numpy.ndarray points: The first shape used to create the ROI diff --git a/silx/gui/plot/tools/test/testROI.py b/silx/gui/plot/tools/test/testROI.py index b526f4aafd..33a0000671 100644 --- a/silx/gui/plot/tools/test/testROI.py +++ b/silx/gui/plot/tools/test/testROI.py @@ -306,7 +306,9 @@ def test(self): manager.sigRoiChanged.connect(changedListener) # Add a point - manager.createRoi(roiClass, points[0]) + r = roiClass() + r.setFirstShapePoints(points[0]) + manager.addRoi(r) self.qapp.processEvents() self.assertTrue(len(manager.getRois()), 1) self.assertEqual(changedListener.callCount(), 1) @@ -317,9 +319,13 @@ def test(self): self.assertEqual(changedListener.callCount(), 2) # Add two point - manager.createRoi(roiClass, points[0]) + r = roiClass() + r.setFirstShapePoints(points[0]) + manager.addRoi(r) self.qapp.processEvents() - manager.createRoi(roiClass, points[1]) + r = roiClass() + r.setFirstShapePoints(points[1]) + manager.addRoi(r) self.qapp.processEvents() self.assertTrue(len(manager.getRois()), 2) self.assertEqual(changedListener.callCount(), 4) @@ -333,9 +339,13 @@ def test(self): changedListener.clear() # Add two point - manager.createRoi(roiClass, points[0]) + r = roiClass() + r.setFirstShapePoints(points[0]) + manager.addRoi(r) self.qapp.processEvents() - manager.createRoi(roiClass, points[1]) + r = roiClass() + r.setFirstShapePoints(points[1]) + manager.addRoi(r) self.qapp.processEvents() self.assertTrue(len(manager.getRois()), 2) self.assertEqual(changedListener.callCount(), 2) From 4ac8fd5e2e122d0159f0c1845c9e12abb984c532 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 29 May 2020 11:56:56 +0200 Subject: [PATCH 5/6] Fix handle close color --- silx/gui/plot/items/roi.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/silx/gui/plot/items/roi.py b/silx/gui/plot/items/roi.py index b08da02e2b..5bdc09c92f 100644 --- a/silx/gui/plot/items/roi.py +++ b/silx/gui/plot/items/roi.py @@ -1810,6 +1810,9 @@ def _updatedStyle(self, event, style): self.__shape.setColor(style.getColor()) self.__shape.setLineStyle(style.getLineStyle()) self.__shape.setLineWidth(style.getLineWidth()) + if self._handleClose is not None: + color = self._computeHandleColor(style.getColor()) + self._handleClose.setColor(color) def __createShape(self, interaction=False): kind = "polygon" if not interaction else "polylines" From e0522f8255d7e01222c54794b6ce7a49d8f06878 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 29 May 2020 12:01:17 +0200 Subject: [PATCH 6/6] Make sure the shape is hilighted at the end of the interaction --- silx/gui/plot/items/roi.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/silx/gui/plot/items/roi.py b/silx/gui/plot/items/roi.py index 5bdc09c92f..66554e4ecb 100644 --- a/silx/gui/plot/items/roi.py +++ b/silx/gui/plot/items/roi.py @@ -1820,9 +1820,10 @@ def __createShape(self, interaction=False): shape.setPoints([[0, 0], [0, 0]]) shape.setFill(False) shape.setOverlay(True) - shape.setLineStyle(self.getLineStyle()) - shape.setLineWidth(self.getLineWidth()) - shape.setColor(rgba(self.getColor())) + style = self.getCurrentStyle() + shape.setLineStyle(style.getLineStyle()) + shape.setLineWidth(style.getLineWidth()) + shape.setColor(rgba(style.getColor())) return shape def setFirstShapePoints(self, points):