本文整理汇总了Python中silx.gui.plot.PlotWindow.close方法的典型用法代码示例。如果您正苦于以下问题:Python PlotWindow.close方法的具体用法?Python PlotWindow.close怎么用?Python PlotWindow.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类silx.gui.plot.PlotWindow
的用法示例。
在下文中一共展示了PlotWindow.close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPlotWindow
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestPlotWindow(TestCaseQt):
"""Base class for tests of PlotWindow."""
def setUp(self):
super(TestPlotWindow, self).setUp()
self.plot = PlotWindow()
self.plot.show()
self.qWaitForWindowExposed(self.plot)
def tearDown(self):
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
super(TestPlotWindow, self).tearDown()
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 testToolAspectRatio(self):
self.plot.toolBar()
self.plot.keepDataAspectRatioButton.keepDataAspectRatio()
self.assertTrue(self.plot.isKeepDataAspectRatio())
self.plot.keepDataAspectRatioButton.dontKeepDataAspectRatio()
self.assertFalse(self.plot.isKeepDataAspectRatio())
def testToolYAxisOrigin(self):
self.plot.toolBar()
self.plot.yAxisInvertedButton.setYAxisUpward()
self.assertFalse(self.plot.getYAxis().isInverted())
self.plot.yAxisInvertedButton.setYAxisDownward()
self.assertTrue(self.plot.getYAxis().isInverted())
示例2: TestCurvesROIWidget
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestCurvesROIWidget(TestCaseQt):
"""Basic test for CurvesROIWidget"""
def setUp(self):
super(TestCurvesROIWidget, self).setUp()
self.plot = PlotWindow()
self.plot.show()
self.qWaitForWindowExposed(self.plot)
self.widget = CurvesROIWidget.CurvesROIDockWidget(plot=self.plot, name='TEST')
self.widget.show()
self.qWaitForWindowExposed(self.widget)
def tearDown(self):
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
self.widget.setAttribute(qt.Qt.WA_DeleteOnClose)
self.widget.close()
del self.widget
super(TestCurvesROIWidget, self).tearDown()
def testEmptyPlot(self):
"""Empty plot, display ROI widget"""
pass
def testWithCurves(self):
"""Plot with curves: test all ROI widget buttons"""
for offset in range(2):
self.plot.addCurve(numpy.arange(1000),
offset + numpy.random.random(1000),
legend=str(offset))
# Add two ROI
self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)
self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)
# Change active curve
self.plot.setActiveCurve(str(1))
# Delete a ROI
self.mouseClick(self.widget.roiWidget.delButton, qt.Qt.LeftButton)
with temp_dir() as tmpDir:
self.tmpFile = os.path.join(tmpDir, 'test.ini')
# Save ROIs
self.widget.roiWidget.save(self.tmpFile)
self.assertTrue(os.path.isfile(self.tmpFile))
# Reset ROIs
self.mouseClick(self.widget.roiWidget.resetButton,
qt.Qt.LeftButton)
# Load ROIs
self.widget.roiWidget.load(self.tmpFile)
del self.tmpFile
示例3: TestMaskToolsWidget
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestMaskToolsWidget(TestCaseQt):
"""Basic test for MaskToolsWidget"""
def setUp(self):
super(TestMaskToolsWidget, self).setUp()
self.plot = PlotWindow()
self.widget = MaskToolsWidget.MaskToolsDockWidget(self.plot, 'TEST')
self.plot.addDockWidget(qt.Qt.BottomDockWidgetArea, self.widget)
self.plot.show()
self.qWaitForWindowExposed(self.plot)
self.maskWidget = self.widget.widget()
def tearDown(self):
del self.maskWidget
del self.widget
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
super(TestMaskToolsWidget, self).tearDown()
def testEmptyPlot(self):
"""Empty plot, display MaskToolsDockWidget, toggle multiple masks"""
self.maskWidget.setMultipleMasks('single')
self.qapp.processEvents()
self.maskWidget.setMultipleMasks('exclusive')
self.qapp.processEvents()
def _drag(self):
"""Drag from plot center to offset position"""
plot = self.plot.centralWidget()
xCenter, yCenter = plot.width() // 2, plot.height() // 2
offset = min(plot.width(), plot.height()) // 10
pos0 = xCenter, yCenter
pos1 = xCenter + offset, yCenter + offset
self.mouseMove(plot, pos=pos0)
self.mousePress(plot, qt.Qt.LeftButton, pos=pos0)
self.mouseMove(plot, pos=pos1)
self.mouseRelease(plot, qt.Qt.LeftButton, pos=pos1)
def _drawPolygon(self):
"""Draw a star polygon in the plot"""
plot = self.plot.centralWidget()
x, y = plot.width() // 2, plot.height() // 2
offset = min(plot.width(), plot.height()) // 10
star = [(x, y + offset),
(x - offset, y - offset),
(x + offset, y),
(x - offset, y),
(x + offset, y - offset)]
for pos in star:
self.mouseMove(plot, pos=pos)
btn = qt.Qt.LeftButton if pos != star[-1] else qt.Qt.RightButton
self.mouseClick(plot, btn, pos=pos)
def _drawPencil(self):
"""Draw a star polygon in the plot"""
plot = self.plot.centralWidget()
x, y = plot.width() // 2, plot.height() // 2
offset = min(plot.width(), plot.height()) // 10
star = [(x, y + offset),
(x - offset, y - offset),
(x + offset, y),
(x - offset, y),
(x + offset, y - offset)]
self.mouseMove(plot, pos=star[0])
self.mousePress(plot, qt.Qt.LeftButton, pos=star[0])
for pos in star:
self.mouseMove(plot, pos=pos)
self.mouseRelease(
plot, qt.Qt.LeftButton, pos=star[-1])
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)
#.........这里部分代码省略.........
示例4: TestCurvesROIWidget
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestCurvesROIWidget(TestCaseQt):
"""Basic test for CurvesROIWidget"""
def setUp(self):
super(TestCurvesROIWidget, self).setUp()
self.plot = PlotWindow()
self.plot.show()
self.qWaitForWindowExposed(self.plot)
self.widget = self.plot.getCurvesRoiDockWidget()
self.widget.show()
self.qWaitForWindowExposed(self.widget)
def tearDown(self):
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
self.widget.setAttribute(qt.Qt.WA_DeleteOnClose)
self.widget.close()
del self.widget
super(TestCurvesROIWidget, self).tearDown()
def testWithCurves(self):
"""Plot with curves: test all ROI widget buttons"""
for offset in range(2):
self.plot.addCurve(numpy.arange(1000),
offset + numpy.random.random(1000),
legend=str(offset))
# Add two ROI
self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)
self.qWait(200)
self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)
self.qWait(200)
# Change active curve
self.plot.setActiveCurve(str(1))
# Delete a ROI
self.mouseClick(self.widget.roiWidget.delButton, qt.Qt.LeftButton)
self.qWait(200)
with temp_dir() as tmpDir:
self.tmpFile = os.path.join(tmpDir, 'test.ini')
# Save ROIs
self.widget.roiWidget.save(self.tmpFile)
self.assertTrue(os.path.isfile(self.tmpFile))
self.assertTrue(len(self.widget.getRois()) is 2)
# Reset ROIs
self.mouseClick(self.widget.roiWidget.resetButton,
qt.Qt.LeftButton)
self.qWait(200)
rois = self.widget.getRois()
self.assertTrue(len(rois) is 1)
print(rois)
roiID = list(rois.keys())[0]
self.assertTrue(rois[roiID].getName() == 'ICR')
# Load ROIs
self.widget.roiWidget.load(self.tmpFile)
self.assertTrue(len(self.widget.getRois()) is 2)
del self.tmpFile
def testMiddleMarker(self):
"""Test with middle marker enabled"""
self.widget.roiWidget.roiTable.setMiddleROIMarkerFlag(True)
# Add a ROI
self.mouseClick(self.widget.roiWidget.addButton, qt.Qt.LeftButton)
for roiID in self.widget.roiWidget.roiTable._markersHandler._roiMarkerHandlers:
handler = self.widget.roiWidget.roiTable._markersHandler._roiMarkerHandlers[roiID]
assert handler.getMarker('min')
xleftMarker = handler.getMarker('min').getXPosition()
xMiddleMarker = handler.getMarker('middle').getXPosition()
xRightMarker = handler.getMarker('max').getXPosition()
thValue = xleftMarker + (xRightMarker - xleftMarker) / 2.
self.assertAlmostEqual(xMiddleMarker, thValue)
def testAreaCalculation(self):
"""Test result of area calculation"""
x = numpy.arange(100.)
y = numpy.arange(100.)
# Add two curves
self.plot.addCurve(x, y, legend="positive")
self.plot.addCurve(-x, y, legend="negative")
# Make sure there is an active curve and it is the positive one
self.plot.setActiveCurve("positive")
# Add two ROIs
roi_neg = CurvesROIWidget.ROI(name='negative', fromdata=-20,
todata=-10, type_='X')
#.........这里部分代码省略.........
示例5: TestProfileToolBar
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestProfileToolBar(TestCaseQt, ParametricTestCase):
"""Tests for ProfileToolBar widget."""
def setUp(self):
super(TestProfileToolBar, self).setUp()
profileWindow = PlotWindow()
self.plot = PlotWindow()
self.toolBar = Profile.ProfileToolBar(
plot=self.plot, profileWindow=profileWindow)
self.plot.addToolBar(self.toolBar)
self.plot.show()
self.qWaitForWindowExposed(self.plot)
profileWindow.show()
self.qWaitForWindowExposed(profileWindow)
self.mouseMove(self.plot) # Move to center
self.qapp.processEvents()
def tearDown(self):
self.qapp.processEvents()
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
del self.toolBar
super(TestProfileToolBar, self).tearDown()
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)
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()
示例6: TestPositionInfo
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestPositionInfo(TestCaseQt):
"""Tests for PositionInfo widget."""
def setUp(self):
super(TestPositionInfo, self).setUp()
self.plot = PlotWindow()
self.plot.show()
self.qWaitForWindowExposed(self.plot)
self.mouseMove(self.plot, pos=(1, 1))
self.qapp.processEvents()
self.qWait(100)
def tearDown(self):
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
super(TestPositionInfo, self).tearDown()
def _test(self, positionWidget, converterNames, **kwargs):
"""General test of PositionInfo.
- Add it to a toolbar and
- Move mouse around the center of the PlotWindow.
"""
toolBar = qt.QToolBar()
self.plot.addToolBar(qt.Qt.BottomToolBarArea, toolBar)
toolBar.addWidget(positionWidget)
converters = positionWidget.getConverters()
self.assertEqual(len(converters), len(converterNames))
for index, name in enumerate(converterNames):
self.assertEqual(converters[index][0], name)
with TestLogging(PlotTools.__name__, **kwargs):
# Move mouse to center
self.mouseMove(self.plot)
self.qapp.processEvents()
self.qWait(100)
def testDefaultConverters(self):
"""Test PositionInfo with default converters"""
positionWidget = PlotTools.PositionInfo(plot=self.plot)
self._test(positionWidget, ('X', 'Y'))
def testCustomConverters(self):
"""Test PositionInfo with custom converters"""
converters = [
('Coords', lambda x, y: (int(x), int(y))),
('Radius', lambda x, y: numpy.sqrt(x * x + y * y)),
('Angle', lambda x, y: numpy.degrees(numpy.arctan2(y, x)))
]
positionWidget = PlotTools.PositionInfo(plot=self.plot, converters=converters)
self._test(positionWidget, ('Coords', 'Radius', 'Angle'))
def testFailingConverters(self):
"""Test PositionInfo with failing custom converters"""
def raiseException(x, y):
raise RuntimeError()
positionWidget = PlotTools.PositionInfo(
plot=self.plot,
converters=[('Exception', raiseException)])
self._test(positionWidget, ['Exception'], error=2)
示例7: TestRegionOfInterestManager
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestRegionOfInterestManager(TestCaseQt, ParametricTestCase):
"""Tests for RegionOfInterestManager class"""
def setUp(self):
super(TestRegionOfInterestManager, self).setUp()
self.plot = PlotWindow()
self.roiTableWidget = roi.RegionOfInterestTableWidget()
dock = qt.QDockWidget()
dock.setWidget(self.roiTableWidget)
self.plot.addDockWidget(qt.Qt.BottomDockWidgetArea, dock)
self.plot.show()
self.qWaitForWindowExposed(self.plot)
def tearDown(self):
del self.roiTableWidget
self.qapp.processEvents()
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
super(TestRegionOfInterestManager, self).tearDown()
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)
#.........这里部分代码省略.........
示例8: TestRegionOfInterestManager
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestRegionOfInterestManager(TestCaseQt, ParametricTestCase):
"""Tests for RegionOfInterestManager class"""
def setUp(self):
super(TestRegionOfInterestManager, self).setUp()
self.plot = PlotWindow()
self.roiTableWidget = roi.RegionOfInterestTableWidget()
dock = qt.QDockWidget()
dock.setWidget(self.roiTableWidget)
self.plot.addDockWidget(qt.Qt.BottomDockWidgetArea, dock)
self.plot.show()
self.qWaitForWindowExposed(self.plot)
def tearDown(self):
del self.roiTableWidget
self.qapp.processEvents()
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
super(TestRegionOfInterestManager, self).tearDown()
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]))))
#.........这里部分代码省略.........
示例9: TestCurveLegendsWidget
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestCurveLegendsWidget(TestCaseQt, ParametricTestCase):
"""Tests for CurveLegendsWidget class"""
def setUp(self):
super(TestCurveLegendsWidget, self).setUp()
self.plot = PlotWindow()
self.legends = CurveLegendsWidget.CurveLegendsWidget()
self.legends.setPlotWidget(self.plot)
dock = qt.QDockWidget()
dock.setWindowTitle('Curve Legends')
dock.setWidget(self.legends)
self.plot.addTabbedDockWidget(dock)
self.plot.show()
self.qWaitForWindowExposed(self.plot)
def tearDown(self):
del self.legends
self.qapp.processEvents()
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
super(TestCurveLegendsWidget, self).tearDown()
def _assertNbLegends(self, count):
"""Check the number of legends in the CurveLegendsWidget"""
children = self.legends.findChildren(CurveLegendsWidget._LegendWidget)
self.assertEqual(len(children), count)
def testAddRemoveCurves(self):
"""Test CurveLegendsWidget while adding/removing curves"""
self.plot.addCurve((0, 1), (1, 2), legend='a')
self._assertNbLegends(1)
self.plot.addCurve((0, 1), (2, 3), legend='b')
self._assertNbLegends(2)
# Detached/attach
self.legends.setPlotWidget(None)
self._assertNbLegends(0)
self.legends.setPlotWidget(self.plot)
self._assertNbLegends(2)
self.plot.clear()
self._assertNbLegends(0)
def testUpdateCurves(self):
"""Test CurveLegendsWidget while updating curves """
self.plot.addCurve((0, 1), (1, 2), legend='a')
self._assertNbLegends(1)
self.plot.addCurve((0, 1), (2, 3), legend='b')
self._assertNbLegends(2)
# Activate curve
self.plot.setActiveCurve('a')
self.qapp.processEvents()
self.plot.setActiveCurve('b')
self.qapp.processEvents()
# Change curve style
curve = self.plot.getCurve('a')
curve.setLineWidth(2)
for linestyle in (':', '', '--', '-'):
with self.subTest(linestyle=linestyle):
curve.setLineStyle(linestyle)
self.qapp.processEvents()
self.qWait(1000)
for symbol in ('o', 'd', '', 's'):
with self.subTest(symbol=symbol):
curve.setSymbol(symbol)
self.qapp.processEvents()
self.qWait(1000)
示例10: TestScatterProfileToolBar
# 需要导入模块: from silx.gui.plot import PlotWindow [as 别名]
# 或者: from silx.gui.plot.PlotWindow import close [as 别名]
class TestScatterProfileToolBar(TestCaseQt, ParametricTestCase):
"""Tests for ScatterProfileToolBar class"""
def setUp(self):
super(TestScatterProfileToolBar, self).setUp()
self.plot = PlotWindow()
self.profile = profile.ScatterProfileToolBar(plot=self.plot)
self.plot.addToolBar(self.profile)
self.plot.show()
self.qWaitForWindowExposed(self.plot)
def tearDown(self):
del self.profile
self.qapp.processEvents()
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
super(TestScatterProfileToolBar, self).tearDown()
def testNoProfile(self):
"""Test ScatterProfileToolBar without profile"""
self.assertEqual(self.profile.getPlotWidget(), self.plot)
# Add a scatter plot
self.plot.addScatter(
x=(0., 1., 1., 0.), y=(0., 0., 1., 1.), value=(0., 1., 2., 3.))
self.plot.resetZoom(dataMargins=(.1, .1, .1, .1))
self.qapp.processEvents()
# Check that there is no profile
self.assertIsNone(self.profile.getProfileValues())
self.assertIsNone(self.profile.getProfilePoints())
def testHorizontalProfile(self):
"""Test ScatterProfileToolBar horizontal profile"""
nPoints = 8
self.profile.setNPoints(nPoints)
self.assertEqual(self.profile.getNPoints(), nPoints)
# Add a scatter plot
self.plot.addScatter(
x=(0., 1., 1., 0.), y=(0., 0., 1., 1.), value=(0., 1., 2., 3.))
self.plot.resetZoom(dataMargins=(.1, .1, .1, .1))
self.qapp.processEvents()
# Activate Horizontal profile
hlineAction = self.profile.actions()[0]
hlineAction.trigger()
self.qapp.processEvents()
# Set a ROI profile
roi = roi_items.HorizontalLineROI()
roi.setPosition(0.5)
self.profile._getRoiManager().addRoi(roi)
# Wait for async interpolator init
for _ in range(20):
self.qWait(200)
if not self.profile.hasPendingOperations():
break
self.assertIsNotNone(self.profile.getProfileValues())
points = self.profile.getProfilePoints()
self.assertEqual(len(points), nPoints)
# Check that profile has same limits than Plot
xLimits = self.plot.getXAxis().getLimits()
self.assertEqual(points[0, 0], xLimits[0])
self.assertEqual(points[-1, 0], xLimits[1])
# Clear the profile
clearAction = self.profile.actions()[-1]
clearAction.trigger()
self.qapp.processEvents()
self.assertIsNone(self.profile.getProfileValues())
self.assertIsNone(self.profile.getProfilePoints())
self.assertEqual(self.profile.getProfileTitle(), '')
def testVerticalProfile(self):
"""Test ScatterProfileToolBar vertical profile"""
nPoints = 8
self.profile.setNPoints(nPoints)
self.assertEqual(self.profile.getNPoints(), nPoints)
# Add a scatter plot
self.plot.addScatter(
x=(0., 1., 1., 0.), y=(0., 0., 1., 1.), value=(0., 1., 2., 3.))
self.plot.resetZoom(dataMargins=(.1, .1, .1, .1))
self.qapp.processEvents()
# Activate vertical profile
vlineAction = self.profile.actions()[1]
vlineAction.trigger()
self.qapp.processEvents()
# Set a ROI profile
#.........这里部分代码省略.........