Exemplo n.º 1
0
 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()
Exemplo n.º 2
0
 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()
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
 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 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()
Exemplo n.º 6
0
 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()
Exemplo n.º 7
0
    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()
Exemplo n.º 8
0
    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()