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), (self.plot.keepDataAspectRatioAction, self.plot.isKeepDataAspectRatio), (self.plot.yAxisInvertedAction, self.plot.isYAxisInverted), ] 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 testLoadSave(self): """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: success = self.maskWidget.save( os.path.join(tmp, 'mask.npy'), 'npy') self.assertTrue(success) self.maskWidget.resetSelectionMask() self.assertTrue( numpy.all(numpy.equal(self.maskWidget.getSelectionMask(), 0))) result = self.maskWidget.load(os.path.join(tmp, 'mask.npy')) self.assertTrue(result) 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 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 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() self.plot.addImage(numpy.arange(1024**2).reshape(1024, 1024), legend='test') 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)