def testActions(self): """Test the actions QToolButtons""" self.plot.setLimits(1, 100, 1, 100) checkList = [ # QAction, Plot state getter (self.plot.xAxisAutoScaleAction, self.plot.isXAxisAutoScale), (self.plot.yAxisAutoScaleAction, self.plot.isYAxisAutoScale), (self.plot.xAxisLogarithmicAction, self.plot.isXAxisLogarithmic), (self.plot.yAxisLogarithmicAction, self.plot.isYAxisLogarithmic), (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)
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)
def testClickOnDetailView(self): dialog = self.createDialog() dialog.show() self.qWaitForWindowExposed(dialog) action = utils.findChildren(dialog, qt.QAction, name="detailModeAction")[0] detailModeButton = utils.getQToolButtonFromAction(action) self.mouseClick(detailModeButton, qt.Qt.LeftButton) self.assertEqual(dialog.viewMode(), qt.QFileDialog.Detail) action = utils.findChildren(dialog, qt.QAction, name="listModeAction")[0] listModeButton = utils.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 = utils.findChildren(dialog, qt.QLineEdit, name="url")[0] forwardAction = utils.findChildren(dialog, qt.QAction, name="forwardAction")[0] backwardAction = utils.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 = utils.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 = utils.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 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)
def testAlignedProfile(self): """Test horizontal and vertical profile, without and with image""" # Use Plot backend widget to submit mouse events widget = self.plot.getWidgetHandle() # 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)
def testDiagonalProfile(self): """Test diagonal profile, without and with image""" # Use Plot backend widget to submit mouse events widget = self.plot.getWidgetHandle() # 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 # 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) for image in (False, True): with self.subTest(image=image): if image: self.plot.addImage( numpy.arange(100 * 100).reshape(100, -1)) 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) self.plot.clear()
def testClickOnBackToDirectoryTool(self): if h5py is None: self.skipTest("h5py is missing") dialog = self.createDialog() dialog.show() self.qWaitForWindowExposed(dialog) url = utils.findChildren(dialog, qt.QLineEdit, name="url")[0] action = utils.findChildren(dialog, qt.QAction, name="toDirectoryAction")[0] button = utils.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
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]])))
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)))
def testClickOnBackToParentTool(self): if h5py is None: self.skipTest("h5py is missing") dialog = self.createDialog() dialog.show() self.qWaitForWindowExposed(dialog) url = utils.findChildren(dialog, qt.QLineEdit, name="url")[0] action = utils.findChildren(dialog, qt.QAction, name="toParentAction")[0] toParentButton = utils.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) # 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) self.mouseClick(toParentButton, qt.Qt.LeftButton) self.qWaitForPendingActions(dialog) self.assertSamePath(url.text(), os.path.dirname(_tmpDirectory))
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)))
def testClickOnBackToRootTool(self): if h5py is None: self.skipTest("h5py is missing") dialog = self.createDialog() dialog.show() self.qWaitForWindowExposed(dialog) url = utils.findChildren(dialog, qt.QLineEdit, name="url")[0] action = utils.findChildren(dialog, qt.QAction, name="toRootFileAction")[0] button = utils.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)
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)))
def testDiagonalProfile(self): """Test diagonal profile, without and with image""" # Use Plot backend widget to submit mouse events widget = self.plot.getWidgetHandle() # 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 # 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) for image in (False, True): with self.subTest(image=image): if image: self.plot.addImage(numpy.arange(100 * 100).reshape(100, -1)) 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) self.plot.clear()
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])))
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')
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()
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())
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)
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()
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()
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(10) 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()