Skip to content

Commit

Permalink
Merge pull request #2469 from payno/fix_2468
Browse files Browse the repository at this point in the history
closes #2468
  • Loading branch information
vasole committed Feb 21, 2019
2 parents 39390f6 + 8bbaed2 commit bfdbf9f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
46 changes: 30 additions & 16 deletions silx/gui/plot/CurvesROIWidget.py
Expand Up @@ -153,18 +153,22 @@ def __init__(self, parent=None, name=None, plot=None):

layout.addWidget(hbox)

# Signal / Slot connections
self.addButton.clicked.connect(self._add)
self.delButton.clicked.connect(self._del)
self.resetButton.clicked.connect(self._reset)

self.loadButton.clicked.connect(self._load)
self.saveButton.clicked.connect(self._save)

self.roiTable.activeROIChanged.connect(self._emitCurrentROISignal)

self._isConnected = False # True if connected to plot signals
self._isInit = False

# expose API
self.getROIListAndDict = self.roiTable.getROIListAndDict

def getPlotWidget(self):
"""Returns the associated PlotWidget or None
Expand All @@ -175,7 +179,6 @@ def getPlotWidget(self):
def showEvent(self, event):
self._visibilityChangedHandler(visible=True)
qt.QWidget.showEvent(self, event)
self.roiTable.activeROIChanged.connect(self._emitCurrentROISignal)

@property
def roiFileDir(self):
Expand Down Expand Up @@ -655,19 +658,26 @@ def signalChanged(roi):
value = float(item.text())
except ValueError:
value = 0
changed = False
if item.column() == self.COLUMNS_INDEX['To']:
roi.setTo(value)
if value != roi.getTo():
roi.setTo(value)
changed = True
else:
assert(item.column() == self.COLUMNS_INDEX['From'])
roi.setFrom(value)
self._updateMarker(roi.getName())
signalChanged(roi)
if value != roi.getFrom():
roi.setFrom(value)
changed = True
if changed:
self._updateMarker(roi.getName())
signalChanged(roi)

if item.column() is self.COLUMNS_INDEX['ROI']:
roi = getRoi()
roi.setName(item.text())
self._markersHandler.getMarkerHandler(roi.getID()).updateTexts()
signalChanged(roi)
if roi.getName() != item.text():
roi.setName(item.text())
self._markersHandler.getMarkerHandler(roi.getID()).updateTexts()
signalChanged(roi)

self._userIsEditingRoi = False

Expand Down Expand Up @@ -1057,8 +1067,9 @@ def setType(self, type_):
:param str type_:
"""
self._type = type_
self.sigChanged.emit()
if self._type != type_:
self._type = type_
self.sigChanged.emit()

def getType(self):
"""
Expand All @@ -1073,8 +1084,9 @@ def setName(self, name):
:param str name:
"""
self._name = name
self.sigChanged.emit()
if self._name != name:
self._name = name
self.sigChanged.emit()

def getName(self):
"""
Expand All @@ -1088,8 +1100,9 @@ def setFrom(self, frm):
:param frm: set x coordinate of the left limit
"""
self._fromdata = frm
self.sigChanged.emit()
if self._fromdata != frm:
self._fromdata = frm
self.sigChanged.emit()

def getFrom(self):
"""
Expand All @@ -1103,8 +1116,9 @@ def setTo(self, to):
:param to: x coordinate of the right limit
"""
self._todata = to
self.sigChanged.emit()
if self._todata != to:
self._todata = to
self.sigChanged.emit()

def getTo(self):
"""
Expand Down
24 changes: 23 additions & 1 deletion silx/gui/plot/test/testCurvesROIWidget.py
Expand Up @@ -36,7 +36,7 @@
import numpy
from silx.gui import qt
from silx.test.utils import temp_dir
from silx.gui.utils.testutils import TestCaseQt
from silx.gui.utils.testutils import TestCaseQt, SignalListener
from silx.gui.plot import PlotWindow, CurvesROIWidget


Expand Down Expand Up @@ -129,6 +129,7 @@ def testMiddleMarker(self):
self.assertAlmostEqual(xMiddleMarker, thValue)

def testAreaCalculation(self):
"""Test result of area calculation"""
x = numpy.arange(100.)
y = numpy.arange(100.)

Expand Down Expand Up @@ -161,6 +162,7 @@ def testAreaCalculation(self):
((-150.0), 0.0))

def testCountsCalculation(self):
"""Test result of count calculation"""
x = numpy.arange(100.)
y = numpy.arange(100.)

Expand Down Expand Up @@ -192,6 +194,7 @@ def testCountsCalculation(self):
(y[10:21].sum(), 0.0))

def testDeferedInit(self):
"""Test behavior of the deferedInit"""
x = numpy.arange(100.)
y = numpy.arange(100.)
self.plot.addCurve(x=x, y=y, legend="name", replace="True")
Expand All @@ -216,6 +219,7 @@ def testDictCompatibility(self):
self.assertTrue(roi.toDict() == roiDict)

def testShowAllROI(self):
"""Test the show allROI action"""
x = numpy.arange(100.)
y = numpy.arange(100.)
self.plot.addCurve(x=x, y=y, legend="name", replace="True")
Expand Down Expand Up @@ -292,6 +296,7 @@ def testRoiEdition(self):
self.assertTrue(itemRawArea.text() == '2.0')

def testRemoveActiveROI(self):
"""Test widget behavior when removing the active ROI"""
roi = CurvesROIWidget.ROI(name='linear', fromdata=0, todata=5)
self.widget.roiWidget.setRois((roi,))

Expand All @@ -301,6 +306,23 @@ def testRemoveActiveROI(self):
self.plot.setActiveCurve(legend='linearCurve')
self.widget.calculateROIs()

def testEmitCurrentROI(self):
"""Test behavior of the CurvesROIWidget.sigROISignal"""
roi = CurvesROIWidget.ROI(name='linear', fromdata=0, todata=5)
self.widget.roiWidget.setRois((roi,))
signalListener = SignalListener()
self.widget.roiWidget.sigROISignal.connect(signalListener.partial())
self.widget.show()
self.qapp.processEvents()
self.assertTrue(signalListener.callCount() is 0)
self.assertTrue(self.widget.roiWidget.roiTable.activeRoi is roi)
roi.setFrom(0.0)
self.qapp.processEvents()
self.assertTrue(signalListener.callCount() is 0)
roi.setFrom(0.3)
self.qapp.processEvents()
self.assertTrue(signalListener.callCount() is 1)


def suite():
test_suite = unittest.TestSuite()
Expand Down

0 comments on commit bfdbf9f

Please sign in to comment.