def test_data_event(self): listener = SignalListener() widget = self.create_widget() widget.dataChanged.connect(listener) widget.setData(10) widget.setData(None) self.assertEquals(listener.callCount(), 2)
def testImageDataChanged(self): """Test sigItemChanged for ImageData""" self.plot.addImage(numpy.arange(100).reshape(10, 10), legend='test') image = self.plot.getImage('test') listener = SignalListener() image.sigItemChanged.connect(listener) # ColormapMixIn colormap = self.plot.getDefaultColormap().copy() image.setColormap(colormap) image.getColormap().setName('viridis') # Test of signals in ImageBase class image.setOrigin(10) image.setScale(2) # Test of signals in ImageData class image.setData(numpy.ones((10, 10))) self.assertEqual(listener.arguments(argumentIndex=0), [ ItemChangedType.COLORMAP, ItemChangedType.COLORMAP, ItemChangedType.POSITION, ItemChangedType.SCALE, ItemChangedType.DATA ])
def testImageDataChanged(self): """Test sigItemChanged for ImageData""" self.plot.addImage(numpy.arange(100).reshape(10, 10), legend='test') image = self.plot.getImage('test') listener = SignalListener() image.sigItemChanged.connect(listener) # ColormapMixIn colormap = self.plot.getDefaultColormap().copy() image.setColormap(colormap) image.getColormap().setName('viridis') # Test of signals in ImageBase class image.setOrigin(10) image.setScale(2) # Test of signals in ImageData class image.setData(numpy.ones((10, 10))) self.assertEqual(listener.arguments(argumentIndex=0), [ItemChangedType.COLORMAP, ItemChangedType.COLORMAP, ItemChangedType.POSITION, ItemChangedType.SCALE, ItemChangedType.DATA])
def test_data_event(self): data = numpy.arange(3 * 3 * 3) widget = NumpyAxesSelector() listener = SignalListener() widget.dataChanged.connect(listener) widget.setData(data) widget.setData(None) self.assertEqual(listener.callCount(), 2)
def test_display_mode_event(self): listener = SignalListener() widget = self.create_widget() widget.displayedViewChanged.connect(listener) widget.setData(10) widget.setData(None) modes = [v.modeId() for v in listener.arguments(argumentIndex=0)] self.assertEquals(modes, [DataViews.RAW_MODE, DataViews.EMPTY_MODE]) listener.clear()
def test_event(self): listener = SignalListener() formatter = TextFormatter() formatter.formatChanged.connect(listener) formatter.setFloatFormat("%.3f") formatter.setIntegerFormat("%03i") formatter.setUseQuoteForText(False) formatter.setImaginaryUnit("z") self.assertEquals(listener.callCount(), 4)
def test_display_mode_event(self): listener = SignalListener() widget = self.create_widget() widget.displayedViewChanged.connect(listener) widget.setData(10) widget.setData(None) modes = [v.modeId() for v in listener.arguments(argumentIndex=0)] self.assertEquals(modes, [DataViewer.RAW_MODE, DataViewer.EMPTY_MODE]) listener.clear()
def testStackFrameNumber(self): self.stackview.setStack(self.mystack) self.assertEqual(self.stackview.getFrameNumber(), 0) listener = SignalListener() self.stackview.sigFrameChanged.connect(listener) self.stackview.setFrameNumber(1) self.assertEqual(self.stackview.getFrameNumber(), 1) self.assertEqual(listener.arguments(), [(1, )])
def testStackFrameNumber(self): self.stackview.setStack(self.mystack) self.assertEqual(self.stackview.getFrameNumber(), 0) listener = SignalListener() self.stackview.sigFrameChanged.connect(listener) self.stackview.setFrameNumber(1) self.assertEqual(self.stackview.getFrameNumber(), 1) self.assertEqual(listener.arguments(), [(1,)])
def testMarkerChanged(self): """Test sigItemChanged for markers""" self.plot.addMarker(10, 20, legend='test') marker = self.plot._getMarker('test') listener = SignalListener() marker.sigItemChanged.connect(listener) # Test signals in _BaseMarker marker.setPosition(10, 10) marker.setPosition(10, 10) # Not sending event marker.setText('toto') self.assertEqual(listener.arguments(argumentIndex=0), [ItemChangedType.POSITION, ItemChangedType.TEXT]) # XMarker self.plot.addXMarker(10, legend='x') marker = self.plot._getMarker('x') listener = SignalListener() marker.sigItemChanged.connect(listener) marker.setPosition(20, 20) self.assertEqual(listener.arguments(argumentIndex=0), [ItemChangedType.POSITION]) # YMarker self.plot.addYMarker(10, legend='x') marker = self.plot._getMarker('x') listener = SignalListener() marker.sigItemChanged.connect(listener) marker.setPosition(20, 20) self.assertEqual(listener.arguments(argumentIndex=0), [ItemChangedType.POSITION])
def test_selected_data_event(self): data = numpy.arange(3 * 3 * 3) data.shape = 3, 3, 3 widget = NumpyAxesSelector() listener = SignalListener() widget.selectionChanged.connect(listener) widget.setData(data) widget.setAxisNames(["x"]) widget.setData(None) self.assertEqual(listener.callCount(), 3) listener.clear()
def testHistogramChanged(self): """Test sigItemChanged for Histogram""" self.plot.addHistogram( numpy.arange(10), edges=numpy.arange(11), legend='test') histogram = self.plot.getHistogram('test') listener = SignalListener() histogram.sigItemChanged.connect(listener) # Test signals in Histogram class histogram.setData(numpy.zeros(10), numpy.arange(11)) self.assertEqual(listener.arguments(argumentIndex=0), [ItemChangedType.DATA])
def testImageRgbaChanged(self): """Test sigItemChanged for ImageRgba""" self.plot.addImage(numpy.ones((10, 10, 3)), legend='rgb') image = self.plot.getImage('rgb') listener = SignalListener() image.sigItemChanged.connect(listener) # Test of signals in ImageRgba class image.setData(numpy.zeros((10, 10, 3))) self.assertEqual(listener.arguments(argumentIndex=0), [ItemChangedType.DATA])
def testHistogramChanged(self): """Test sigItemChanged for Histogram""" self.plot.addHistogram(numpy.arange(10), edges=numpy.arange(11), legend='test') histogram = self.plot.getHistogram('test') listener = SignalListener() histogram.sigItemChanged.connect(listener) # Test signals in Histogram class histogram.setData(numpy.zeros(10), numpy.arange(11)) self.assertEqual(listener.arguments(argumentIndex=0), [ItemChangedType.DATA])
def setUp(self): TestCaseQt.setUp(self) self.model = hdf5.Hdf5TreeModel() filename = _tmpDirectory + "/data.h5" self.h5 = h5py.File(filename) self.model.insertH5pyObject(self.h5) self.listener = SignalListener() self.model.sigH5pyObjectLoaded.connect( self.listener.partial(signal="loaded")) self.model.sigH5pyObjectRemoved.connect( self.listener.partial(signal="removed")) self.model.sigH5pyObjectSynchronized.connect( self.listener.partial(signal="synchronized"))
def testShapeChanged(self): """Test sigItemChanged for shape""" data = numpy.array((1., 10.)) self.plot.addItem(data, data, legend='test', shape='rectangle') shape = self.plot._getItem(kind='item', legend='test') listener = SignalListener() shape.sigItemChanged.connect(listener) shape.setOverlay(True) shape.setPoints(((2., 2.), (3., 3.))) self.assertEqual(listener.arguments(), [(ItemChangedType.OVERLAY, ), (ItemChangedType.DATA, )])
def testCurveChanged(self): """Test sigItemChanged for curve""" self.plot.addCurve(numpy.arange(10), numpy.arange(10), legend='test') curve = self.plot.getCurve('test') listener = SignalListener() curve.sigItemChanged.connect(listener) # Test for signal in Item class curve.setVisible(False) curve.setVisible(True) curve.setZValue(100) # Test for signals in Points class curve.setData(numpy.arange(100), numpy.arange(100)) # SymbolMixIn curve.setSymbol('Circle') curve.setSymbol('d') curve.setSymbolSize(20) # AlphaMixIn curve.setAlpha(0.5) # Test for signals in Curve class # ColorMixIn curve.setColor('yellow') # YAxisMixIn curve.setYAxis('right') # FillMixIn curve.setFill(True) # LineMixIn curve.setLineStyle(':') curve.setLineStyle(':') # Not sending event curve.setLineWidth(2) self.assertEqual(listener.arguments(argumentIndex=0), [ItemChangedType.VISIBLE, ItemChangedType.VISIBLE, ItemChangedType.ZVALUE, ItemChangedType.DATA, ItemChangedType.SYMBOL, ItemChangedType.SYMBOL, ItemChangedType.SYMBOL_SIZE, ItemChangedType.ALPHA, ItemChangedType.COLOR, ItemChangedType.YAXIS, ItemChangedType.FILL, ItemChangedType.LINE_STYLE, ItemChangedType.LINE_WIDTH])
def testShapeChanged(self): """Test sigItemChanged for shape""" data = numpy.array((1., 10.)) self.plot.addItem(data, data, legend='test', shape='rectangle') shape = self.plot._getItem(kind='item', legend='test') listener = SignalListener() shape.sigItemChanged.connect(listener) shape.setOverlay(True) shape.setPoints(((2., 2.), (3., 3.))) self.assertEqual(listener.arguments(), [(ItemChangedType.OVERLAY,), (ItemChangedType.DATA,)])
def testFail(self): listener = SignalListener() button = ThreadPoolPushButton() button.setCallable(self._computeFail) button.beforeExecuting.connect(listener.partial(test="be")) button.started.connect(listener.partial(test="s")) button.succeeded.connect(listener.partial(test="Unexpected success")) button.failed.connect(listener.partial(test="exception")) button.finished.connect(listener.partial(test="f")) with TestLogging('silx.gui.widgets.ThreadPoolPushButton', error=1): button.executeCallable() self.qapp.processEvents() time.sleep(0.1) self.qapp.processEvents() result = listener.karguments(argumentName="test") self.assertListEqual(result, ["be", "s", "exception", "f"]) listener.clear()
def testMaxROI(self): """Test Max ROI""" kind = 'rectangle' points = numpy.array((((1., 10.), (11., 20.)), ((2., 3.), (12., 13.)))) manager = roi.InteractiveRegionOfInterestManager(self.plot) self.roiTableWidget.setRegionOfInterestManager(manager) self.assertEqual(manager.getRegionOfInterests(), ()) changedListener = SignalListener() manager.sigRegionOfInterestChanged.connect(changedListener) # Add two point manager.createRegionOfInterest(kind, points[0]) manager.createRegionOfInterest(kind, points[1]) self.qapp.processEvents() self.assertTrue(numpy.all(numpy.equal( manager.getRegionOfInterestPoints(), (points[0], points[1])))) self.assertEqual(changedListener.callCount(), 2) # Try to set max ROI to 1 while there is 2 ROIs with self.assertRaises(ValueError): manager.setMaxRegionOfInterests(1) manager.clearRegionOfInterests() self.assertEqual(manager.getRegionOfInterests(), ()) self.assertEqual(changedListener.callCount(), 3) # Set max limit to 1 manager.setMaxRegionOfInterests(1) # Add a point manager.createRegionOfInterest(kind, points[0]) self.qapp.processEvents() self.assertTrue(numpy.all(numpy.equal( manager.getRegionOfInterestPoints(), (points[0],)))) self.assertEqual(changedListener.callCount(), 4) # Add a 2nd point while max ROI is 1 manager.createRegionOfInterest(kind, points[1]) self.qapp.processEvents() self.assertTrue(numpy.all(numpy.equal( manager.getRegionOfInterestPoints(), (points[1],)))) self.assertEqual(changedListener.callCount(), 6)
def testScatterChanged(self): """Test sigItemChanged for scatter""" data = numpy.arange(10) self.plot.addScatter(data, data, data, legend='test') scatter = self.plot.getScatter('test') listener = SignalListener() scatter.sigItemChanged.connect(listener) # ColormapMixIn scatter.getColormap().setName('viridis') data2 = data + 10 # Test of signals in Scatter class scatter.setData(data2, data2, data2) self.assertEqual(listener.arguments(), [(ItemChangedType.COLORMAP, ), (ItemChangedType.DATA, )])
def testCurveChanged(self): """Test sigItemChanged for curve""" self.plot.addCurve(numpy.arange(10), numpy.arange(10), legend='test') curve = self.plot.getCurve('test') listener = SignalListener() curve.sigItemChanged.connect(listener) # Test for signal in Item class curve.setVisible(False) curve.setVisible(True) curve.setZValue(100) # Test for signals in Points class curve.setData(numpy.arange(100), numpy.arange(100)) # SymbolMixIn curve.setSymbol('o') curve.setSymbol('d') curve.setSymbolSize(20) # AlphaMixIn curve.setAlpha(0.5) # Test for signals in Curve class # ColorMixIn curve.setColor('yellow') # YAxisMixIn curve.setYAxis('right') # FillMixIn curve.setFill(True) # LineMixIn curve.setLineStyle(':') curve.setLineStyle(':') # Not sending event curve.setLineWidth(2) self.assertEqual(listener.arguments(argumentIndex=0), [ ItemChangedType.VISIBLE, ItemChangedType.VISIBLE, ItemChangedType.ZVALUE, ItemChangedType.DATA, ItemChangedType.SYMBOL, ItemChangedType.SYMBOL, ItemChangedType.SYMBOL_SIZE, ItemChangedType.ALPHA, ItemChangedType.COLOR, ItemChangedType.YAXIS, ItemChangedType.FILL, ItemChangedType.LINE_STYLE, ItemChangedType.LINE_WIDTH ])
def testScatterChanged(self): """Test sigItemChanged for scatter""" data = numpy.arange(10) self.plot.addScatter(data, data, data, legend='test') scatter = self.plot.getScatter('test') listener = SignalListener() scatter.sigItemChanged.connect(listener) # ColormapMixIn scatter.getColormap().setName('viridis') data2 = data + 10 # Test of signals in Scatter class scatter.setData(data2, data2, data2) self.assertEqual(listener.arguments(), [(ItemChangedType.COLORMAP,), (ItemChangedType.DATA,)])
def setUp(self): TestCaseQt.setUp(self) self.model = hdf5.Hdf5TreeModel() filename = _tmpDirectory + "/data.h5" self.h5 = h5py.File(filename) self.model.insertH5pyObject(self.h5) self.listener = SignalListener() self.model.sigH5pyObjectLoaded.connect(self.listener.partial(signal="loaded")) self.model.sigH5pyObjectRemoved.connect(self.listener.partial(signal="removed")) self.model.sigH5pyObjectSynchronized.connect(self.listener.partial(signal="synchronized"))
def testSuccess(self): listener = SignalListener() button = ThreadPoolPushButton() button.setCallable(self._compute) button.beforeExecuting.connect(listener.partial(test="be")) button.started.connect(listener.partial(test="s")) button.succeeded.connect(listener.partial(test="result")) button.failed.connect(listener.partial(test="Unexpected exception")) button.finished.connect(listener.partial(test="f")) button.executeCallable() self.qapp.processEvents() time.sleep(0.1) self.qapp.processEvents() result = listener.karguments(argumentName="test") self.assertListEqual(result, ["be", "s", "result", "f"])
def testMaxROI(self): """Test Max ROI""" origin1 = numpy.array([1., 10.]) size1 = numpy.array([10., 10.]) origin2 = numpy.array([2., 3.]) size2 = numpy.array([10., 10.]) manager = roi.InteractiveRegionOfInterestManager(self.plot) self.roiTableWidget.setRegionOfInterestManager(manager) self.assertEqual(manager.getRois(), ()) changedListener = SignalListener() manager.sigRoiChanged.connect(changedListener) # Add two point item = roi_items.RectangleROI() item.setGeometry(origin=origin1, size=size1) manager.addRoi(item) item = roi_items.RectangleROI() item.setGeometry(origin=origin2, size=size2) manager.addRoi(item) self.qapp.processEvents() self.assertEqual(changedListener.callCount(), 2) self.assertEqual(len(manager.getRois()), 2) # Try to set max ROI to 1 while there is 2 ROIs with self.assertRaises(ValueError): manager.setMaxRois(1) manager.clear() self.assertEqual(len(manager.getRois()), 0) self.assertEqual(changedListener.callCount(), 3) # Set max limit to 1 manager.setMaxRois(1) # Add a point item = roi_items.RectangleROI() item.setGeometry(origin=origin1, size=size1) manager.addRoi(item) self.qapp.processEvents() self.assertEqual(changedListener.callCount(), 4) # Add a 2nd point while max ROI is 1 item = roi_items.RectangleROI() item.setGeometry(origin=origin1, size=size1) manager.addRoi(item) self.qapp.processEvents() self.assertEqual(changedListener.callCount(), 6) self.assertEqual(len(manager.getRois()), 1)
class TestHdf5TreeModelSignals(TestCaseQt): def setUp(self): TestCaseQt.setUp(self) self.model = hdf5.Hdf5TreeModel() filename = _tmpDirectory + "/data.h5" self.h5 = h5py.File(filename) self.model.insertH5pyObject(self.h5) self.listener = SignalListener() self.model.sigH5pyObjectLoaded.connect( self.listener.partial(signal="loaded")) self.model.sigH5pyObjectRemoved.connect( self.listener.partial(signal="removed")) self.model.sigH5pyObjectSynchronized.connect( self.listener.partial(signal="synchronized")) def tearDown(self): self.signals = None ref = weakref.ref(self.model) self.model = None self.qWaitForDestroy(ref) self.h5.close() self.h5 = None TestCaseQt.tearDown(self) def waitForPendingOperations(self, model): for _ in range(10): if not model.hasPendingOperations(): break self.qWait(10) else: raise RuntimeError("Still waiting for a pending operation") def testInsert(self): filename = _tmpDirectory + "/data.h5" h5 = h5py.File(filename) self.model.insertH5pyObject(h5) self.assertEquals(self.listener.callCount(), 0) def testLoaded(self): filename = _tmpDirectory + "/data.h5" self.model.insertFile(filename) self.assertEquals(self.listener.callCount(), 1) self.assertEquals( self.listener.karguments(argumentName="signal")[0], "loaded") self.assertIsNot(self.listener.arguments(callIndex=0)[0], self.h5) self.assertEquals( self.listener.arguments(callIndex=0)[0].filename, filename) def testRemoved(self): self.model.removeH5pyObject(self.h5) self.assertEquals(self.listener.callCount(), 1) self.assertEquals( self.listener.karguments(argumentName="signal")[0], "removed") self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5) def testSynchonized(self): self.model.synchronizeH5pyObject(self.h5) self.waitForPendingOperations(self.model) self.assertEquals(self.listener.callCount(), 1) self.assertEquals( self.listener.karguments(argumentName="signal")[0], "synchronized") self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5) self.assertIsNot(self.listener.arguments(callIndex=0)[1], self.h5)
class TestHdf5TreeModelSignals(TestCaseQt): def setUp(self): TestCaseQt.setUp(self) self.model = hdf5.Hdf5TreeModel() filename = _tmpDirectory + "/data.h5" self.h5 = h5py.File(filename) self.model.insertH5pyObject(self.h5) self.listener = SignalListener() self.model.sigH5pyObjectLoaded.connect(self.listener.partial(signal="loaded")) self.model.sigH5pyObjectRemoved.connect(self.listener.partial(signal="removed")) self.model.sigH5pyObjectSynchronized.connect(self.listener.partial(signal="synchronized")) def tearDown(self): self.signals = None ref = weakref.ref(self.model) self.model = None self.qWaitForDestroy(ref) self.h5.close() self.h5 = None TestCaseQt.tearDown(self) def waitForPendingOperations(self, model): for _ in range(10): if not model.hasPendingOperations(): break self.qWait(10) else: raise RuntimeError("Still waiting for a pending operation") def testInsert(self): filename = _tmpDirectory + "/data.h5" h5 = h5py.File(filename) self.model.insertH5pyObject(h5) self.assertEquals(self.listener.callCount(), 0) def testLoaded(self): filename = _tmpDirectory + "/data.h5" self.model.insertFile(filename) self.assertEquals(self.listener.callCount(), 1) self.assertEquals(self.listener.karguments(argumentName="signal")[0], "loaded") self.assertIsNot(self.listener.arguments(callIndex=0)[0], self.h5) self.assertEquals(self.listener.arguments(callIndex=0)[0].filename, filename) def testRemoved(self): self.model.removeH5pyObject(self.h5) self.assertEquals(self.listener.callCount(), 1) self.assertEquals(self.listener.karguments(argumentName="signal")[0], "removed") self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5) def testSynchonized(self): self.model.synchronizeH5pyObject(self.h5) self.waitForPendingOperations(self.model) self.assertEquals(self.listener.callCount(), 1) self.assertEquals(self.listener.karguments(argumentName="signal")[0], "synchronized") self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5) self.assertIsNot(self.listener.arguments(callIndex=0)[1], self.h5)
def test(self): """Test ROI of different shapes""" tests = ( # shape, points=[list of (x, y), list of (x, y)] ('point', numpy.array(([(10., 15.)], [(20., 25.)]))), ('rectangle', numpy.array((((1., 10.), (11., 20.)), ((2., 3.), (12., 13.))))), ('polygon', numpy.array((((0., 1.), (0., 10.), (10., 0.)), ((5., 6.), (5., 16.), (15., 6.))))), ('line', numpy.array((((10., 20.), (10., 30.)), ((30., 40.), (30., 50.))))), ('hline', numpy.array((((10., 20.), (10., 30.)), ((30., 40.), (30., 50.))))), ('vline', numpy.array((((10., 20.), (10., 30.)), ((30., 40.), (30., 50.))))), ) for kind, points in tests: with self.subTest(kind=kind): manager = roi.RegionOfInterestManager(self.plot) self.roiTableWidget.setRegionOfInterestManager(manager) manager.start(kind) self.assertEqual(manager.getRegionOfInterests(), ()) finishListener = SignalListener() manager.sigInteractiveModeFinished.connect(finishListener) changedListener = SignalListener() manager.sigRegionOfInterestChanged.connect(changedListener) # Add a point manager.createRegionOfInterest(kind, points[0]) self.qapp.processEvents() self.assertTrue(numpy.all(numpy.equal( manager.getRegionOfInterestPoints(), (points[0],)))) self.assertEqual(changedListener.callCount(), 1) # Remove it manager.removeRegionOfInterest(manager.getRegionOfInterests()[0]) self.assertEqual(manager.getRegionOfInterests(), ()) self.assertEqual(changedListener.callCount(), 2) # Add two point manager.createRegionOfInterest(kind, points[0]) self.qapp.processEvents() manager.createRegionOfInterest(kind, points[1]) self.qapp.processEvents() self.assertTrue(numpy.all(numpy.equal( manager.getRegionOfInterestPoints(), (points[0], points[1])))) self.assertEqual(changedListener.callCount(), 4) # Reset it result = manager.clearRegionOfInterests() self.assertTrue(result) self.assertEqual(manager.getRegionOfInterests(), ()) self.assertEqual(changedListener.callCount(), 5) changedListener.clear() # Add two point manager.createRegionOfInterest(kind, points[0]) self.qapp.processEvents() manager.createRegionOfInterest(kind, points[1]) self.qapp.processEvents() self.assertTrue(numpy.all(numpy.equal( manager.getRegionOfInterestPoints(), (points[0], points[1])))) self.assertEqual(changedListener.callCount(), 2) # stop result = manager.stop() self.assertTrue(result) self.assertTrue(numpy.all(numpy.equal( manager.getRegionOfInterestPoints(), (points[0], points[1])))) self.qapp.processEvents() self.assertEqual(finishListener.callCount(), 1) manager.clearRegionOfInterests()
def test(self): """Test ROI of different shapes""" tests = ( # shape, points=[list of (x, y), list of (x, y)] (roi_items.PointROI, numpy.array(([(10., 15.)], [(20., 25.)]))), (roi_items.RectangleROI, numpy.array((((1., 10.), (11., 20.)), ((2., 3.), (12., 13.))))), (roi_items.PolygonROI, numpy.array((((0., 1.), (0., 10.), (10., 0.)), ((5., 6.), (5., 16.), (15., 6.))))), (roi_items.LineROI, numpy.array((((10., 20.), (10., 30.)), ((30., 40.), (30., 50.))))), (roi_items.HorizontalLineROI, numpy.array((((10., 20.), (10., 30.)), ((30., 40.), (30., 50.))))), (roi_items.VerticalLineROI, numpy.array((((10., 20.), (10., 30.)), ((30., 40.), (30., 50.))))), ) for roiClass, points in tests: with self.subTest(roiClass=roiClass): manager = roi.RegionOfInterestManager(self.plot) self.roiTableWidget.setRegionOfInterestManager(manager) manager.start(roiClass) self.assertEqual(manager.getRois(), ()) finishListener = SignalListener() manager.sigInteractiveModeFinished.connect(finishListener) changedListener = SignalListener() manager.sigRoiChanged.connect(changedListener) # Add a point manager.createRoi(roiClass, points[0]) self.qapp.processEvents() self.assertTrue(len(manager.getRois()), 1) self.assertEqual(changedListener.callCount(), 1) # Remove it manager.removeRoi(manager.getRois()[0]) self.assertEqual(manager.getRois(), ()) self.assertEqual(changedListener.callCount(), 2) # Add two point manager.createRoi(roiClass, points[0]) self.qapp.processEvents() manager.createRoi(roiClass, points[1]) self.qapp.processEvents() self.assertTrue(len(manager.getRois()), 2) self.assertEqual(changedListener.callCount(), 4) # Reset it result = manager.clear() self.assertTrue(result) self.assertEqual(manager.getRois(), ()) self.assertEqual(changedListener.callCount(), 5) changedListener.clear() # Add two point manager.createRoi(roiClass, points[0]) self.qapp.processEvents() manager.createRoi(roiClass, points[1]) self.qapp.processEvents() self.assertTrue(len(manager.getRois()), 2) self.assertEqual(changedListener.callCount(), 2) # stop result = manager.stop() self.assertTrue(result) self.assertTrue(len(manager.getRois()), 1) self.qapp.processEvents() self.assertEqual(finishListener.callCount(), 1) manager.clear()