Esempio n. 1
0
    def testActions(self):
        """Test the actions QToolButtons"""
        self.plot.setLimits(1, 100, 1, 100)

        checkList = [  # QAction, Plot state getter
            (self.plot.xAxisAutoScaleAction, self.plot.getXAxis().isAutoScale),
            (self.plot.yAxisAutoScaleAction, self.plot.getYAxis().isAutoScale),
            (self.plot.xAxisLogarithmicAction, self.plot.getXAxis()._isLogarithmic),
            (self.plot.yAxisLogarithmicAction, self.plot.getYAxis()._isLogarithmic),
            (self.plot.gridAction, self.plot.getGraphGrid),
        ]

        for action, getter in checkList:
            self.mouseMove(self.plot)
            initialState = getter()
            toolButton = getQToolButtonFromAction(action)
            self.assertIsNot(toolButton, None)
            self.mouseClick(toolButton, qt.Qt.LeftButton)
            self.assertNotEqual(getter(), initialState,
                                msg='"%s" state not changed' % action.text())

            self.mouseClick(toolButton, qt.Qt.LeftButton)
            self.assertEqual(getter(), initialState,
                             msg='"%s" state not changed' % action.text())

        # Trigger a zoom reset
        self.mouseMove(self.plot)
        resetZoomAction = self.plot.resetZoomAction
        toolButton = getQToolButtonFromAction(resetZoomAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
Esempio n. 2
0
    def testActions(self):
        """Test the actions QToolButtons"""
        self.plot.setLimits(1, 100, 1, 100)

        checkList = [  # QAction, Plot state getter
            (self.plot.xAxisAutoScaleAction, self.plot.getXAxis().isAutoScale),
            (self.plot.yAxisAutoScaleAction, self.plot.getYAxis().isAutoScale),
            (self.plot.xAxisLogarithmicAction,
             self.plot.getXAxis()._isLogarithmic),
            (self.plot.yAxisLogarithmicAction,
             self.plot.getYAxis()._isLogarithmic),
            (self.plot.gridAction, self.plot.getGraphGrid),
        ]

        for action, getter in checkList:
            self.mouseMove(self.plot)
            initialState = getter()
            toolButton = getQToolButtonFromAction(action)
            self.assertIsNot(toolButton, None)
            self.mouseClick(toolButton, qt.Qt.LeftButton)
            self.assertNotEqual(getter(),
                                initialState,
                                msg='"%s" state not changed' % action.text())

            self.mouseClick(toolButton, qt.Qt.LeftButton)
            self.assertEqual(getter(),
                             initialState,
                             msg='"%s" state not changed' % action.text())

        # Trigger a zoom reset
        self.mouseMove(self.plot)
        resetZoomAction = self.plot.resetZoomAction
        toolButton = getQToolButtonFromAction(resetZoomAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
Esempio n. 3
0
    def testClickOnDetailView(self):
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        action = testutils.findChildren(dialog, qt.QAction, name="detailModeAction")[0]
        detailModeButton = testutils.getQToolButtonFromAction(action)
        self.mouseClick(detailModeButton, qt.Qt.LeftButton)
        self.assertEqual(dialog.viewMode(), qt.QFileDialog.Detail)

        action = testutils.findChildren(dialog, qt.QAction, name="listModeAction")[0]
        listModeButton = testutils.getQToolButtonFromAction(action)
        self.mouseClick(listModeButton, qt.Qt.LeftButton)
        self.assertEqual(dialog.viewMode(), qt.QFileDialog.List)
Esempio n. 4
0
    def testClickOnDetailView(self):
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        action = testutils.findChildren(dialog, qt.QAction, name="detailModeAction")[0]
        detailModeButton = testutils.getQToolButtonFromAction(action)
        self.mouseClick(detailModeButton, qt.Qt.LeftButton)
        self.assertEqual(dialog.viewMode(), qt.QFileDialog.Detail)

        action = testutils.findChildren(dialog, qt.QAction, name="listModeAction")[0]
        listModeButton = testutils.getQToolButtonFromAction(action)
        self.mouseClick(listModeButton, qt.Qt.LeftButton)
        self.assertEqual(dialog.viewMode(), qt.QFileDialog.List)
    def testClickOnHistoryTools(self):
        if h5py is None:
            self.skipTest("h5py is missing")
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        url = testutils.findChildren(dialog, qt.QLineEdit, name="url")[0]
        forwardAction = testutils.findChildren(dialog,
                                               qt.QAction,
                                               name="forwardAction")[0]
        backwardAction = testutils.findChildren(dialog,
                                                qt.QAction,
                                                name="backwardAction")[0]
        filename = _tmpDirectory + "/data.h5"

        dialog.setDirectory(_tmpDirectory)
        self.qWaitForPendingActions(dialog)
        # No way to use QTest.mouseDClick with QListView, QListWidget
        # Then we feed the history using selectPath
        dialog.selectUrl(filename)
        self.qWaitForPendingActions(dialog)
        path2 = silx.io.url.DataUrl(scheme="silx",
                                    file_path=filename,
                                    data_path="/").path()
        dialog.selectUrl(path2)
        self.qWaitForPendingActions(dialog)
        path3 = silx.io.url.DataUrl(scheme="silx",
                                    file_path=filename,
                                    data_path="/group").path()
        dialog.selectUrl(path3)
        self.qWaitForPendingActions(dialog)
        self.assertFalse(forwardAction.isEnabled())
        self.assertTrue(backwardAction.isEnabled())

        button = testutils.getQToolButtonFromAction(backwardAction)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertTrue(forwardAction.isEnabled())
        self.assertTrue(backwardAction.isEnabled())
        self.assertSamePath(url.text(), path2)

        button = testutils.getQToolButtonFromAction(forwardAction)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertFalse(forwardAction.isEnabled())
        self.assertTrue(backwardAction.isEnabled())
        self.assertSamePath(url.text(), path3)
Esempio n. 6
0
    def __loadSave(self, file_format):
        """Plot with an image: test MaskToolsWidget operations"""
        self.plot.addImage(numpy.arange(1024**2).reshape(1024, 1024),
                           legend='test')
        self.qapp.processEvents()

        # Draw a polygon mask
        toolButton = getQToolButtonFromAction(self.maskWidget.polygonAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        self._drawPolygon()

        ref_mask = self.maskWidget.getSelectionMask()
        self.assertFalse(numpy.all(numpy.equal(ref_mask, 0)))

        with temp_dir() as tmp:
            mask_filename = os.path.join(tmp, 'mask.' + file_format)
            self.maskWidget.save(mask_filename, file_format)

            self.maskWidget.resetSelectionMask()
            self.assertTrue(
                numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

            self.maskWidget.load(mask_filename)
            self.assertTrue(numpy.all(numpy.equal(
                self.maskWidget.getSelectionMask(), ref_mask)))
Esempio n. 7
0
    def __loadSave(self, file_format):
        self.plot.addScatter(
                x=numpy.arange(256),
                y=25 * (numpy.arange(256) % 10),
                value=numpy.random.random(256),
                legend='test')
        self.plot._setActiveItem(kind="scatter", legend="test")
        self.plot.resetZoom()
        self.qapp.processEvents()

        # Draw a polygon mask
        toolButton = getQToolButtonFromAction(self.maskWidget.polygonAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        self._drawPolygon()

        ref_mask = self.maskWidget.getSelectionMask()
        self.assertFalse(numpy.all(numpy.equal(ref_mask, 0)))

        with temp_dir() as tmp:
            mask_filename = os.path.join(tmp, 'mask.' + file_format)
            self.maskWidget.save(mask_filename, file_format)

            self.maskWidget.resetSelectionMask()
            self.assertTrue(
                numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

            self.maskWidget.load(mask_filename)
            self.assertTrue(numpy.all(numpy.equal(
                self.maskWidget.getSelectionMask(), ref_mask)))
Esempio n. 8
0
    def testMethodSumLine(self):
        """Simple interaction test to make sure the sum is correctly computed
        """
        _3DProfileToolbar = self.plot.getProfileToolbar()
        _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
        self.plot.getProfileToolbar().setProfileMethod('sum')
        self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
        self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'sum')

        # check 2D 'mean' profile
        _3DProfileToolbar.profile3dAction.computeProfileIn2D()
        toolButton = getQToolButtonFromAction(_3DProfileToolbar.lineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot2D = self.plot.getPlot().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.2
        pos2 = plot2D.width() * 0.5, plot2D.height() * 0.8

        self.mouseMove(plot2D, pos=pos1)
        self.mousePress(plot2D, qt.Qt.LeftButton, pos=pos1)
        self.mouseMove(plot2D, pos=pos2)
        self.mouseRelease(plot2D, qt.Qt.LeftButton, pos=pos2)
        self.assertTrue(numpy.array_equal(
            _2DProfilePlot.getActiveImage().getData(),
            numpy.array([[3, 12], [21, 30], [39, 48]])
        ))
Esempio n. 9
0
    def testClickOnBackToDirectoryTool(self):
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        url = testutils.findChildren(dialog, qt.QLineEdit, name="url")[0]
        action = testutils.findChildren(dialog, qt.QAction, name="toDirectoryAction")[0]
        button = testutils.getQToolButtonFromAction(action)
        filename = _tmpDirectory + "/data.h5"

        # init state
        path = silx.io.url.DataUrl(file_path=filename, data_path="/group/image").path()
        dialog.selectUrl(path)
        self.qWaitForPendingActions(dialog)
        path = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/group/image").path()
        self.assertSamePath(url.text(), path)
        self.assertTrue(button.isEnabled())
        # test
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertSamePath(url.text(), _tmpDirectory)
        self.assertFalse(button.isEnabled())

        # FIXME: There is an unreleased qt.QWidget without nameObject
        # No idea where it come from.
        self.allowedLeakingWidgets = 1
Esempio n. 10
0
    def testClickOnBackToParentTool(self):
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        url = testutils.findChildren(dialog, qt.QLineEdit, name="url")[0]
        action = testutils.findChildren(dialog, qt.QAction, name="toParentAction")[0]
        toParentButton = testutils.getQToolButtonFromAction(action)
        filename = _tmpDirectory + "/data/data.h5"

        # init state
        path = silx.io.url.DataUrl(file_path=filename, data_path="/group/image").path()
        dialog.selectUrl(path)
        self.qWaitForPendingActions(dialog)
        path = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/group/image").path()
        self.assertSamePath(url.text(), path)
        # test
        self.mouseClick(toParentButton, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        path = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/").path()
        self.assertSamePath(url.text(), path)

        self.mouseClick(toParentButton, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertSamePath(url.text(), _tmpDirectory + "/data")

        self.mouseClick(toParentButton, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertSamePath(url.text(), _tmpDirectory)
    def testClickOnBackToRootTool(self):
        if h5py is None:
            self.skipTest("h5py is missing")
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        url = testutils.findChildren(dialog, qt.QLineEdit, name="url")[0]
        action = testutils.findChildren(dialog,
                                        qt.QAction,
                                        name="toRootFileAction")[0]
        button = testutils.getQToolButtonFromAction(action)
        filename = _tmpDirectory + "/data.h5"

        # init state
        path = silx.io.url.DataUrl(scheme="silx",
                                   file_path=filename,
                                   data_path="/group/image").path()
        dialog.selectUrl(path)
        self.qWaitForPendingActions(dialog)
        self.assertSamePath(url.text(), path)
        self.assertTrue(button.isEnabled())
        # test
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        path = silx.io.url.DataUrl(scheme="silx",
                                   file_path=filename,
                                   data_path="/").path()
        self.assertSamePath(url.text(), path)
Esempio n. 12
0
    def testClickOnBackToDirectoryTool(self):
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        url = testutils.findChildren(dialog, qt.QLineEdit, name="url")[0]
        action = testutils.findChildren(dialog, qt.QAction, name="toDirectoryAction")[0]
        button = testutils.getQToolButtonFromAction(action)
        filename = _tmpDirectory + "/data.h5"

        # init state
        path = silx.io.url.DataUrl(file_path=filename, data_path="/group/image").path()
        dialog.selectUrl(path)
        self.qWaitForPendingActions(dialog)
        path = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/group/image").path()
        self.assertSamePath(url.text(), path)
        self.assertTrue(button.isEnabled())
        # test
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertSamePath(url.text(), _tmpDirectory)
        self.assertFalse(button.isEnabled())

        # FIXME: There is an unreleased qt.QWidget without nameObject
        # No idea where it come from.
        self.allowedLeakingWidgets = 1
Esempio n. 13
0
    def testClickOnBackToParentTool(self):
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        url = testutils.findChildren(dialog, qt.QLineEdit, name="url")[0]
        action = testutils.findChildren(dialog, qt.QAction, name="toParentAction")[0]
        toParentButton = testutils.getQToolButtonFromAction(action)
        filename = _tmpDirectory + "/data/data.h5"

        # init state
        path = silx.io.url.DataUrl(file_path=filename, data_path="/group/image").path()
        dialog.selectUrl(path)
        self.qWaitForPendingActions(dialog)
        path = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/group/image").path()
        self.assertSamePath(url.text(), path)
        # test
        self.mouseClick(toParentButton, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        path = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/").path()
        self.assertSamePath(url.text(), path)

        self.mouseClick(toParentButton, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertSamePath(url.text(), _tmpDirectory + "/data")

        self.mouseClick(toParentButton, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertSamePath(url.text(), _tmpDirectory)
Esempio n. 14
0
    def testChangeItem(self):
        """Test that histogram changes it the item changes"""
        xx = numpy.arange(10)
        yy = numpy.arange(10)
        value = numpy.sin(xx)
        self.plotImage.addScatter(xx, yy, value)
        self.plotImage.show()

        histoAction = self.plotImage.getIntensityHistogramAction()

        # test the pixel intensity diagram is showing
        button = getQToolButtonFromAction(histoAction)
        self.assertIsNot(button, None)
        self.mouseMove(button)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qapp.processEvents()

        # Reach histogram from the first item
        plot = histoAction.getHistogramPlotWidget()
        self.assertTrue(plot.isVisible())
        items = plot.getItems()
        data1 = items[0].getValueData(copy=False)

        # Set another item to the plot
        self.plotImage.addImage(self.image, origin=(0, 0), legend='sino')
        self.qapp.processEvents()
        data2 = items[0].getValueData(copy=False)

        # Histogram is not the same
        self.assertFalse(numpy.array_equal(data1, data2))
Esempio n. 15
0
    def testSigMaskChangedEmitted(self):
        self.qapp.processEvents()
        self.plot.addScatter(x=numpy.arange(1000),
                             y=1000 * (numpy.arange(1000) % 20),
                             value=numpy.ones((1000, )),
                             legend='test')
        self.plot._setActiveItem(kind="scatter", legend="test")
        self.plot.resetZoom()
        self.qapp.processEvents()

        self.plot.remove('test', kind='scatter')
        self.qapp.processEvents()

        self.plot.addScatter(x=numpy.arange(1000),
                             y=1000 * (numpy.arange(1000) % 20),
                             value=numpy.random.random(1000),
                             legend='test')

        l = []

        def slot():
            l.append(1)

        self.maskWidget.sigMaskChanged.connect(slot)

        # rectangle mask
        toolButton = getQToolButtonFromAction(self.maskWidget.rectAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drag()

        self.assertGreater(len(l), 0)
Esempio n. 16
0
    def __loadSave(self, file_format):
        self.plot.addScatter(x=numpy.arange(256),
                             y=25 * (numpy.arange(256) % 10),
                             value=numpy.random.random(256),
                             legend='test')
        self.plot._setActiveItem(kind="scatter", legend="test")
        self.plot.resetZoom()
        self.qapp.processEvents()

        # Draw a polygon mask
        toolButton = getQToolButtonFromAction(self.maskWidget.polygonAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        self._drawPolygon()

        ref_mask = self.maskWidget.getSelectionMask()
        self.assertFalse(numpy.all(numpy.equal(ref_mask, 0)))

        with temp_dir() as tmp:
            mask_filename = os.path.join(tmp, 'mask.' + file_format)
            self.maskWidget.save(mask_filename, file_format)

            self.maskWidget.resetSelectionMask()
            self.assertTrue(
                numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

            self.maskWidget.load(mask_filename)
            self.assertTrue(
                numpy.all(
                    numpy.equal(self.maskWidget.getSelectionMask(), ref_mask)))
Esempio n. 17
0
    def testAlignedProfile(self):
        """Test horizontal and vertical profile, without and with image"""
        # Use Plot backend widget to submit mouse events
        widget = self.plot.getWidgetHandle()
        for method in ('sum', 'mean'):
            with self.subTest(method=method):
                # 2 positions to use for mouse events
                pos1 = widget.width() * 0.4, widget.height() * 0.4
                pos2 = widget.width() * 0.6, widget.height() * 0.6

                for action in (self.toolBar.hLineAction, self.toolBar.vLineAction):
                    with self.subTest(mode=action.text()):
                        # Trigger tool button for mode
                        toolButton = getQToolButtonFromAction(action)
                        self.assertIsNot(toolButton, None)
                        self.mouseMove(toolButton)
                        self.mouseClick(toolButton, qt.Qt.LeftButton)

                        # Without image
                        self.mouseMove(widget, pos=pos1)
                        self.mouseClick(widget, qt.Qt.LeftButton, pos=pos1)

                        # with image
                        self.plot.addImage(
                            numpy.arange(100 * 100).reshape(100, -1))
                        self.mousePress(widget, qt.Qt.LeftButton, pos=pos1)
                        self.mouseMove(widget, pos=pos2)
                        self.mouseRelease(widget, qt.Qt.LeftButton, pos=pos2)

                        self.mouseMove(widget)
                        self.mouseClick(widget, qt.Qt.LeftButton)
Esempio n. 18
0
    def testMethodSumLine(self):
        """Simple interaction test to make sure the sum is correctly computed
        """
        _3DProfileToolbar = self.plot.getProfileToolbar()
        _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
        self.plot.getProfileToolbar().setProfileMethod('sum')
        self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
        self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'sum')

        # check 2D 'mean' profile
        _3DProfileToolbar.profile3dAction.computeProfileIn2D()
        toolButton = getQToolButtonFromAction(_3DProfileToolbar.lineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot2D = self.plot.getPlot().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.2
        pos2 = plot2D.width() * 0.5, plot2D.height() * 0.8

        self.mouseMove(plot2D, pos=pos1)
        self.mousePress(plot2D, qt.Qt.LeftButton, pos=pos1)
        self.mouseMove(plot2D, pos=pos2)
        self.mouseRelease(plot2D, qt.Qt.LeftButton, pos=pos2)
        self.assertTrue(numpy.array_equal(
            _2DProfilePlot.getActiveImage().getData(),
            numpy.array([[3, 12], [21, 30], [39, 48]])
        ))
Esempio n. 19
0
    def testAlignedProfile(self):
        """Test horizontal and vertical profile, without and with image"""
        # Use Plot backend widget to submit mouse events
        widget = self.plot.getWidgetHandle()
        for method in ('sum', 'mean'):
            with self.subTest(method=method):
                # 2 positions to use for mouse events
                pos1 = widget.width() * 0.4, widget.height() * 0.4
                pos2 = widget.width() * 0.6, widget.height() * 0.6

                for action in (self.toolBar.hLineAction, self.toolBar.vLineAction):
                    with self.subTest(mode=action.text()):
                        # Trigger tool button for mode
                        toolButton = getQToolButtonFromAction(action)
                        self.assertIsNot(toolButton, None)
                        self.mouseMove(toolButton)
                        self.mouseClick(toolButton, qt.Qt.LeftButton)

                        # Without image
                        self.mouseMove(widget, pos=pos1)
                        self.mouseClick(widget, qt.Qt.LeftButton, pos=pos1)

                        # with image
                        self.plot.addImage(
                            numpy.arange(100 * 100).reshape(100, -1))
                        self.mousePress(widget, qt.Qt.LeftButton, pos=pos1)
                        self.mouseMove(widget, pos=pos2)
                        self.mouseRelease(widget, qt.Qt.LeftButton, pos=pos2)

                        self.mouseMove(widget)
                        self.mouseClick(widget, qt.Qt.LeftButton)
Esempio n. 20
0
    def __loadSave(self, file_format):
        """Plot with an image: test MaskToolsWidget operations"""
        self.plot.addImage(numpy.arange(1024**2).reshape(1024, 1024),
                           legend='test')
        self.qapp.processEvents()

        # Draw a polygon mask
        toolButton = getQToolButtonFromAction(self.maskWidget.polygonAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        self._drawPolygon()

        ref_mask = self.maskWidget.getSelectionMask()
        self.assertFalse(numpy.all(numpy.equal(ref_mask, 0)))

        with temp_dir() as tmp:
            mask_filename = os.path.join(tmp, 'mask.' + file_format)
            self.maskWidget.save(mask_filename, file_format)

            self.maskWidget.resetSelectionMask()
            self.assertTrue(
                numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

            self.maskWidget.load(mask_filename)
            self.assertTrue(
                numpy.all(
                    numpy.equal(self.maskWidget.getSelectionMask(), ref_mask)))
Esempio n. 21
0
    def testMethodProfile1DAnd2D(self):
        """Test that the profile can have a different method if we want to
        compute then in 1D or in 2D"""

        _3DProfileToolbar = self.plot.getProfileToolbar()
        _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
        self.plot.getProfileToolbar().setProfileMethod('mean')
        self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
        self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'mean')

        # check 2D 'mean' profile
        _3DProfileToolbar.profile3dAction.computeProfileIn2D()
        toolButton = getQToolButtonFromAction(_3DProfileToolbar.vLineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot2D = self.plot.getPlot().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.5
        self.mouseClick(plot2D, qt.Qt.LeftButton, pos=pos1)
        self.assertTrue(numpy.array_equal(
            _2DProfilePlot.getActiveImage().getData(),
            numpy.array([[1, 4], [7, 10], [13, 16]])
        ))

        # check 1D 'sum' profile
        _2DProfileToolbar = _2DProfilePlot.getProfileToolbar()
        _2DProfileToolbar.setProfileMethod('sum')
        self.assertTrue(_2DProfileToolbar.getProfileMethod() == 'sum')
        _1DProfilePlot = _2DProfileToolbar.getProfilePlot()

        _2DProfileToolbar.lineWidthSpinBox.setValue(3)
        toolButton = getQToolButtonFromAction(_2DProfileToolbar.vLineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot1D = _2DProfilePlot.getWidgetHandle()
        pos1 = plot1D.width() * 0.5, plot1D.height() * 0.5
        self.mouseClick(plot1D, qt.Qt.LeftButton, pos=pos1)
        self.assertTrue(numpy.array_equal(
            _1DProfilePlot.getAllCurves()[0].getData()[1],
            numpy.array([5, 17, 29])
        ))
Esempio n. 22
0
    def testMethodProfile1DAnd2D(self):
        """Test that the profile can have a different method if we want to
        compute then in 1D or in 2D"""

        _3DProfileToolbar = self.plot.getProfileToolbar()
        _2DProfilePlot = _3DProfileToolbar.getProfilePlot()
        self.plot.getProfileToolbar().setProfileMethod('mean')
        self.plot.getProfileToolbar().lineWidthSpinBox.setValue(3)
        self.assertTrue(_3DProfileToolbar.getProfileMethod() == 'mean')

        # check 2D 'mean' profile
        _3DProfileToolbar.profile3dAction.computeProfileIn2D()
        toolButton = getQToolButtonFromAction(_3DProfileToolbar.vLineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot2D = self.plot.getPlot().getWidgetHandle()
        pos1 = plot2D.width() * 0.5, plot2D.height() * 0.5
        self.mouseClick(plot2D, qt.Qt.LeftButton, pos=pos1)
        self.assertTrue(numpy.array_equal(
            _2DProfilePlot.getActiveImage().getData(),
            numpy.array([[1, 4], [7, 10], [13, 16]])
        ))

        # check 1D 'sum' profile
        _2DProfileToolbar = _2DProfilePlot.getProfileToolbar()
        _2DProfileToolbar.setProfileMethod('sum')
        self.assertTrue(_2DProfileToolbar.getProfileMethod() == 'sum')
        _1DProfilePlot = _2DProfileToolbar.getProfilePlot()

        _2DProfileToolbar.lineWidthSpinBox.setValue(3)
        toolButton = getQToolButtonFromAction(_2DProfileToolbar.vLineAction)
        self.assertIsNot(toolButton, None)
        self.mouseMove(toolButton)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        plot1D = _2DProfilePlot.getWidgetHandle()
        pos1 = plot1D.width() * 0.5, plot1D.height() * 0.5
        self.mouseClick(plot1D, qt.Qt.LeftButton, pos=pos1)
        self.assertTrue(numpy.array_equal(
            _1DProfilePlot.getAllCurves()[0].getData()[1],
            numpy.array([5, 17, 29])
        ))
Esempio n. 23
0
    def testClickOnHistoryTools(self):
        if h5py is None:
            self.skipTest("h5py is missing")
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        url = testutils.findChildren(dialog, qt.QLineEdit, name="url")[0]
        forwardAction = testutils.findChildren(dialog, qt.QAction, name="forwardAction")[0]
        backwardAction = testutils.findChildren(dialog, qt.QAction, name="backwardAction")[0]
        filename = _tmpDirectory + "/data.h5"

        dialog.setDirectory(_tmpDirectory)
        self.qWaitForPendingActions(dialog)
        # No way to use QTest.mouseDClick with QListView, QListWidget
        # Then we feed the history using selectPath
        dialog.selectUrl(filename)
        self.qWaitForPendingActions(dialog)
        path2 = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/").path()
        dialog.selectUrl(path2)
        self.qWaitForPendingActions(dialog)
        path3 = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/group").path()
        dialog.selectUrl(path3)
        self.qWaitForPendingActions(dialog)
        self.assertFalse(forwardAction.isEnabled())
        self.assertTrue(backwardAction.isEnabled())

        button = testutils.getQToolButtonFromAction(backwardAction)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertTrue(forwardAction.isEnabled())
        self.assertTrue(backwardAction.isEnabled())
        self.assertSamePath(url.text(), path2)

        button = testutils.getQToolButtonFromAction(forwardAction)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        self.assertFalse(forwardAction.isEnabled())
        self.assertTrue(backwardAction.isEnabled())
        self.assertSamePath(url.text(), path3)
 def testImageFormatInput(self):
     """Test multiple type as image input"""
     typesToTest = [numpy.uint8, numpy.int8, numpy.int16, numpy.int32,
                    numpy.float32, numpy.float64]
     self.plotImage.addImage(self.image, origin=(0, 0), legend='sino')
     self.plotImage.show()
     button = getQToolButtonFromAction(
         self.plotImage.getIntensityHistogramAction())
     self.mouseMove(button)
     self.mouseClick(button, qt.Qt.LeftButton)
     self.qapp.processEvents()
     for typeToTest in typesToTest:
         with self.subTest(typeToTest=typeToTest):
             self.plotImage.addImage(self.image.astype(typeToTest),
                                     origin=(0, 0), legend='sino')
Esempio n. 25
0
    def setUp(self):
        self.plot = Plot1D()
        x = range(20)
        y = range(20)
        self.plot.addCurve(x, y, legend='curve0')
        self.listener = SignalListener()
        self.curves_roi_widget = self.plot.getCurvesRoiWidget()
        self.curves_roi_widget.sigROISignal.connect(self.listener)
        assert self.curves_roi_widget.isVisible() is False
        assert self.listener.callCount() == 0
        self.plot.show()
        self.qWaitForWindowExposed(self.plot)

        toolButton = getQToolButtonFromAction(self.plot.getRoiAction())
        self.mouseClick(widget=toolButton, button=qt.Qt.LeftButton)

        self.curves_roi_widget.show()
        self.qWaitForWindowExposed(self.curves_roi_widget)
    def testDiagonalProfile(self):
        """Test diagonal profile, without and with image"""
        # Use Plot backend widget to submit mouse events
        widget = self.plot.getWidgetHandle()

        for method in ('sum', 'mean'):
            with self.subTest(method=method):
                self.toolBar.setProfileMethod(method)

                # 2 positions to use for mouse events
                pos1 = widget.width() * 0.4, widget.height() * 0.4
                pos2 = widget.width() * 0.6, widget.height() * 0.6

                for image in (False, True):
                    with self.subTest(image=image):
                        if image:
                            self.plot.addImage(
                                numpy.arange(100 * 100).reshape(100, -1))

                        # Trigger tool button for diagonal profile mode
                        toolButton = getQToolButtonFromAction(
                            self.toolBar.lineAction)
                        self.assertIsNot(toolButton, None)
                        self.mouseMove(toolButton)
                        self.mouseClick(toolButton, qt.Qt.LeftButton)
                        self.toolBar.lineWidthSpinBox.setValue(3)

                        # draw profile line
                        self.mouseMove(widget, pos=pos1)
                        self.mousePress(widget, qt.Qt.LeftButton, pos=pos1)
                        self.mouseMove(widget, pos=pos2)
                        self.mouseRelease(widget, qt.Qt.LeftButton, pos=pos2)

                        if image is True:
                            profileCurve = self.toolBar.getProfilePlot(
                            ).getAllCurves()[0]
                            if method == 'sum':
                                self.assertTrue(
                                    profileCurve.getData()[1].max() > 10000)
                            elif method == 'mean':
                                self.assertTrue(
                                    profileCurve.getData()[1].max() < 10000)
                        self.plot.clear()
Esempio n. 27
0
    def testScatter(self):
        """Test that an histogram from a scatter is displayed"""
        xx = numpy.arange(10)
        yy = numpy.arange(10)
        value = numpy.sin(xx)
        self.plotImage.addScatter(xx, yy, value)
        self.plotImage.show()

        histoAction = self.plotImage.getIntensityHistogramAction()

        # test the pixel intensity diagram is showing
        button = getQToolButtonFromAction(histoAction)
        self.assertIsNot(button, None)
        self.mouseMove(button)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qapp.processEvents()

        plot = histoAction.getHistogramPlotWidget()
        self.assertTrue(plot.isVisible())
        items = plot.getItems()
        self.assertEqual(len(items), 1)
Esempio n. 28
0
    def testDiagonalProfile(self):
        """Test diagonal profile, without and with image"""
        # Use Plot backend widget to submit mouse events
        widget = self.plot.getWidgetHandle()

        for method in ('sum', 'mean'):
            with self.subTest(method=method):
                self.toolBar.setProfileMethod(method)

                # 2 positions to use for mouse events
                pos1 = widget.width() * 0.4, widget.height() * 0.4
                pos2 = widget.width() * 0.6, widget.height() * 0.6

                for image in (False, True):
                    with self.subTest(image=image):
                        if image:
                            self.plot.addImage(
                                numpy.arange(100 * 100).reshape(100, -1))

                        # Trigger tool button for diagonal profile mode
                        toolButton = getQToolButtonFromAction(
                            self.toolBar.lineAction)
                        self.assertIsNot(toolButton, None)
                        self.mouseMove(toolButton)
                        self.mouseClick(toolButton, qt.Qt.LeftButton)
                        self.toolBar.lineWidthSpinBox.setValue(3)

                        # draw profile line
                        self.mouseMove(widget, pos=pos1)
                        self.mousePress(widget, qt.Qt.LeftButton, pos=pos1)
                        self.mouseMove(widget, pos=pos2)
                        self.mouseRelease(widget, qt.Qt.LeftButton, pos=pos2)

                        if image is True:
                            profileCurve = self.toolBar.getProfilePlot().getAllCurves()[0]
                            if method == 'sum':
                                self.assertTrue(profileCurve.getData()[1].max() > 10000)
                            elif method == 'mean':
                                self.assertTrue(profileCurve.getData()[1].max() < 10000)
                        self.plot.clear()
Esempio n. 29
0
    def testSigMaskChangedEmitted(self):
        self.plot.addImage(numpy.arange(512**2).reshape(512, 512),
                           legend='test')
        self.plot.resetZoom()
        self.qapp.processEvents()

        l = []

        def slot():
            l.append(1)

        self.maskWidget.sigMaskChanged.connect(slot)

        # rectangle mask
        toolButton = getQToolButtonFromAction(self.maskWidget.rectAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drag()

        self.assertGreater(len(l), 0)
Esempio n. 30
0
    def testSigMaskChangedEmitted(self):
        self.plot.addImage(numpy.arange(512**2).reshape(512, 512),
                           legend='test')
        self.plot.resetZoom()
        self.qapp.processEvents()

        l = []

        def slot():
            l.append(1)

        self.maskWidget.sigMaskChanged.connect(slot)

        # rectangle mask
        toolButton = getQToolButtonFromAction(self.maskWidget.rectAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drag()

        self.assertGreater(len(l), 0)
    def testShowAndHide(self):
        """Simple test that the plot is showing and hiding when activating the
        action"""
        self.plotImage.addImage(self.image, origin=(0, 0), legend='sino')
        self.plotImage.show()

        histoAction = self.plotImage.getIntensityHistogramAction()

        # test the pixel intensity diagram is showing
        button = getQToolButtonFromAction(histoAction)
        self.assertIsNot(button, None)
        self.mouseMove(button)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qapp.processEvents()
        self.assertTrue(histoAction.getHistogramPlotWidget().isVisible())

        # test the pixel intensity diagram is hiding
        self.qapp.setActiveWindow(self.plotImage)
        self.qapp.processEvents()
        self.mouseMove(button)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qapp.processEvents()
        self.assertFalse(histoAction.getHistogramPlotWidget().isVisible())
Esempio n. 32
0
    def testClickOnBackToRootTool(self):
        if h5py is None:
            self.skipTest("h5py is missing")
        dialog = self.createDialog()
        dialog.show()
        self.qWaitForWindowExposed(dialog)

        url = testutils.findChildren(dialog, qt.QLineEdit, name="url")[0]
        action = testutils.findChildren(dialog, qt.QAction, name="toRootFileAction")[0]
        button = testutils.getQToolButtonFromAction(action)
        filename = _tmpDirectory + "/data.h5"

        # init state
        path = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/group/image").path()
        dialog.selectUrl(path)
        self.qWaitForPendingActions(dialog)
        self.assertSamePath(url.text(), path)
        self.assertTrue(button.isEnabled())
        # test
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qWaitForPendingActions(dialog)
        path = silx.io.url.DataUrl(scheme="silx", file_path=filename, data_path="/").path()
        self.assertSamePath(url.text(), path)
Esempio n. 33
0
    def testShowAndHide(self):
        """Simple test that the plot is showing and hiding when activating the
        action"""
        self.plotImage.addImage(self.image, origin=(0, 0), legend='sino')
        self.plotImage.show()

        histoAction = self.plotImage.getIntensityHistogramAction()

        # test the pixel intensity diagram is showing
        button = getQToolButtonFromAction(histoAction)
        self.assertIsNot(button, None)
        self.mouseMove(button)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qapp.processEvents()
        self.assertTrue(histoAction.getHistogramPlotWidget().isVisible())

        # test the pixel intensity diagram is hiding
        self.qapp.setActiveWindow(self.plotImage)
        self.qapp.processEvents()
        self.mouseMove(button)
        self.mouseClick(button, qt.Qt.LeftButton)
        self.qapp.processEvents()
        self.assertFalse(histoAction.getHistogramPlotWidget().isVisible())
Esempio n. 34
0
    def testSigMaskChangedEmitted(self):
        self.qapp.processEvents()
        self.plot.addScatter(
                x=numpy.arange(1000),
                y=1000 * (numpy.arange(1000) % 20),
                value=numpy.ones((1000,)),
                legend='test')
        self.plot._setActiveItem(kind="scatter", legend="test")
        self.plot.resetZoom()
        self.qapp.processEvents()

        self.plot.remove('test', kind='scatter')
        self.qapp.processEvents()

        self.plot.addScatter(
                x=numpy.arange(1000),
                y=1000 * (numpy.arange(1000) % 20),
                value=numpy.random.random(1000),
                legend='test')

        l = []

        def slot():
            l.append(1)

        self.maskWidget.sigMaskChanged.connect(slot)

        # rectangle mask
        toolButton = getQToolButtonFromAction(self.maskWidget.rectAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drag()

        self.assertGreater(len(l), 0)
Esempio n. 35
0
    def testWithAnImage(self):
        """Plot with an image: test MaskToolsWidget interactions"""

        # Add and remove a image (this should enable/disable GUI + change mask)
        self.plot.addImage(numpy.random.random(1024**2).reshape(1024, 1024),
                           legend='test')
        self.qapp.processEvents()

        self.plot.remove('test', kind='image')
        self.qapp.processEvents()

        tests = [((0, 0), (1, 1)),
                 ((1000, 1000), (1, 1)),
                 ((0, 0), (-1, -1)),
                 ((1000, 1000), (-1, -1))]

        for origin, scale in tests:
            with self.subTest(origin=origin, scale=scale):
                self.plot.addImage(numpy.arange(1024**2).reshape(1024, 1024),
                                   legend='test',
                                   origin=origin,
                                   scale=scale)
                self.qapp.processEvents()

                # Test draw rectangle #
                toolButton = getQToolButtonFromAction(self.maskWidget.rectAction)
                self.assertIsNot(toolButton, None)
                self.mouseClick(toolButton, qt.Qt.LeftButton)

                # mask
                self.maskWidget.maskStateGroup.button(1).click()
                self.qapp.processEvents()
                self._drag()
                self.assertFalse(
                    numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # unmask same region
                self.maskWidget.maskStateGroup.button(0).click()
                self.qapp.processEvents()
                self._drag()
                self.assertTrue(
                    numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # Test draw polygon #
                toolButton = getQToolButtonFromAction(self.maskWidget.polygonAction)
                self.assertIsNot(toolButton, None)
                self.mouseClick(toolButton, qt.Qt.LeftButton)

                # mask
                self.maskWidget.maskStateGroup.button(1).click()
                self.qapp.processEvents()
                self._drawPolygon()
                self.assertFalse(
                    numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # unmask same region
                self.maskWidget.maskStateGroup.button(0).click()
                self.qapp.processEvents()
                self._drawPolygon()
                self.assertTrue(
                    numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # Test draw pencil #
                toolButton = getQToolButtonFromAction(self.maskWidget.pencilAction)
                self.assertIsNot(toolButton, None)
                self.mouseClick(toolButton, qt.Qt.LeftButton)

                self.maskWidget.pencilSpinBox.setValue(30)
                self.qapp.processEvents()

                # mask
                self.maskWidget.maskStateGroup.button(1).click()
                self.qapp.processEvents()
                self._drawPencil()
                self.assertFalse(
                    numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # unmask same region
                self.maskWidget.maskStateGroup.button(0).click()
                self.qapp.processEvents()
                self._drawPencil()
                self.assertTrue(
                    numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # Test no draw tool #
                toolButton = getQToolButtonFromAction(self.maskWidget.browseAction)
                self.assertIsNot(toolButton, None)
                self.mouseClick(toolButton, qt.Qt.LeftButton)

                self.plot.clear()
Esempio n. 36
0
    def testWithAScatter(self):
        """Plot with a Scatter: test MaskToolsWidget interactions"""

        # Add and remove a scatter (this should enable/disable GUI + change mask)
        self.plot.addScatter(
                x=numpy.arange(256),
                y=numpy.arange(256),
                value=numpy.random.random(256),
                legend='test')
        self.plot._setActiveItem(kind="scatter", legend="test")
        self.qapp.processEvents()

        self.plot.remove('test', kind='scatter')
        self.qapp.processEvents()

        self.plot.addScatter(
                x=numpy.arange(1000),
                y=1000 * (numpy.arange(1000) % 20),
                value=numpy.random.random(1000),
                legend='test')
        self.plot._setActiveItem(kind="scatter", legend="test")
        self.plot.resetZoom()
        self.qapp.processEvents()

        # Test draw rectangle #
        toolButton = getQToolButtonFromAction(self.maskWidget.rectAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)

        # mask
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drag()

        self.assertFalse(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # unmask same region
        self.maskWidget.maskStateGroup.button(0).click()
        self.qapp.processEvents()
        self._drag()
        self.assertTrue(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # Test draw polygon #
        toolButton = getQToolButtonFromAction(self.maskWidget.polygonAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)

        # mask
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drawPolygon()
        self.assertFalse(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # unmask same region
        self.maskWidget.maskStateGroup.button(0).click()
        self.qapp.processEvents()
        self._drawPolygon()
        self.assertTrue(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # Test draw pencil #
        toolButton = getQToolButtonFromAction(self.maskWidget.pencilAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)

        self.maskWidget.pencilSpinBox.setValue(30)
        self.qapp.processEvents()

        # mask
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drawPencil()
        self.assertFalse(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # unmask same region
        self.maskWidget.maskStateGroup.button(0).click()
        self.qapp.processEvents()
        self._drawPencil()
        self.assertTrue(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # Test no draw tool #
        toolButton = getQToolButtonFromAction(self.maskWidget.browseAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)

        self.plot.clear()
Esempio n. 37
0
    def testWithAScatter(self):
        """Plot with a Scatter: test MaskToolsWidget interactions"""

        # Add and remove a scatter (this should enable/disable GUI + change mask)
        self.plot.addScatter(x=numpy.arange(256),
                             y=numpy.arange(256),
                             value=numpy.random.random(256),
                             legend='test')
        self.plot._setActiveItem(kind="scatter", legend="test")
        self.qapp.processEvents()

        self.plot.remove('test', kind='scatter')
        self.qapp.processEvents()

        self.plot.addScatter(x=numpy.arange(1000),
                             y=1000 * (numpy.arange(1000) % 20),
                             value=numpy.random.random(1000),
                             legend='test')
        self.plot._setActiveItem(kind="scatter", legend="test")
        self.plot.resetZoom()
        self.qapp.processEvents()

        # Test draw rectangle #
        toolButton = getQToolButtonFromAction(self.maskWidget.rectAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)

        # mask
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drag()

        self.assertFalse(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # unmask same region
        self.maskWidget.maskStateGroup.button(0).click()
        self.qapp.processEvents()
        self._drag()
        self.assertTrue(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # Test draw polygon #
        toolButton = getQToolButtonFromAction(self.maskWidget.polygonAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)

        # mask
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drawPolygon()
        self.assertFalse(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # unmask same region
        self.maskWidget.maskStateGroup.button(0).click()
        self.qapp.processEvents()
        self._drawPolygon()
        self.assertTrue(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # Test draw pencil #
        toolButton = getQToolButtonFromAction(self.maskWidget.pencilAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)

        self.maskWidget.pencilSpinBox.setValue(30)
        self.qapp.processEvents()

        # mask
        self.maskWidget.maskStateGroup.button(1).click()
        self.qapp.processEvents()
        self._drawPencil()
        self.assertFalse(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # unmask same region
        self.maskWidget.maskStateGroup.button(0).click()
        self.qapp.processEvents()
        self._drawPencil()
        self.assertTrue(
            numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0)))

        # Test no draw tool #
        toolButton = getQToolButtonFromAction(self.maskWidget.browseAction)
        self.assertIsNot(toolButton, None)
        self.mouseClick(toolButton, qt.Qt.LeftButton)

        self.plot.clear()
Esempio n. 38
0
    def testWithAnImage(self):
        """Plot with an image: test MaskToolsWidget interactions"""

        # Add and remove a image (this should enable/disable GUI + change mask)
        self.plot.addImage(numpy.random.random(1024**2).reshape(1024, 1024),
                           legend='test')
        self.qapp.processEvents()

        self.plot.remove('test', kind='image')
        self.qapp.processEvents()

        tests = [((0, 0), (1, 1)), ((1000, 1000), (1, 1)), ((0, 0), (-1, -1)),
                 ((1000, 1000), (-1, -1))]

        for origin, scale in tests:
            with self.subTest(origin=origin, scale=scale):
                self.plot.addImage(numpy.arange(1024**2).reshape(1024, 1024),
                                   legend='test',
                                   origin=origin,
                                   scale=scale)
                self.qapp.processEvents()

                # Test draw rectangle #
                toolButton = getQToolButtonFromAction(
                    self.maskWidget.rectAction)
                self.assertIsNot(toolButton, None)
                self.mouseClick(toolButton, qt.Qt.LeftButton)

                # mask
                self.maskWidget.maskStateGroup.button(1).click()
                self.qapp.processEvents()
                self._drag()
                self.assertFalse(
                    numpy.all(
                        numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # unmask same region
                self.maskWidget.maskStateGroup.button(0).click()
                self.qapp.processEvents()
                self._drag()
                self.assertTrue(
                    numpy.all(
                        numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # Test draw polygon #
                toolButton = getQToolButtonFromAction(
                    self.maskWidget.polygonAction)
                self.assertIsNot(toolButton, None)
                self.mouseClick(toolButton, qt.Qt.LeftButton)

                # mask
                self.maskWidget.maskStateGroup.button(1).click()
                self.qapp.processEvents()
                self._drawPolygon()
                self.assertFalse(
                    numpy.all(
                        numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # unmask same region
                self.maskWidget.maskStateGroup.button(0).click()
                self.qapp.processEvents()
                self._drawPolygon()
                self.assertTrue(
                    numpy.all(
                        numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # Test draw pencil #
                toolButton = getQToolButtonFromAction(
                    self.maskWidget.pencilAction)
                self.assertIsNot(toolButton, None)
                self.mouseClick(toolButton, qt.Qt.LeftButton)

                self.maskWidget.pencilSpinBox.setValue(30)
                self.qapp.processEvents()

                # mask
                self.maskWidget.maskStateGroup.button(1).click()
                self.qapp.processEvents()
                self._drawPencil()
                self.assertFalse(
                    numpy.all(
                        numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # unmask same region
                self.maskWidget.maskStateGroup.button(0).click()
                self.qapp.processEvents()
                self._drawPencil()
                self.assertTrue(
                    numpy.all(
                        numpy.equal(self.maskWidget.getSelectionMask(), 0)))

                # Test no draw tool #
                toolButton = getQToolButtonFromAction(
                    self.maskWidget.browseAction)
                self.assertIsNot(toolButton, None)
                self.mouseClick(toolButton, qt.Qt.LeftButton)

                self.plot.clear()