當前位置: 首頁>>代碼示例>>Python>>正文


Python PlotWindow.addToolBar方法代碼示例

本文整理匯總了Python中silx.gui.plot.PlotWindow.addToolBar方法的典型用法代碼示例。如果您正苦於以下問題:Python PlotWindow.addToolBar方法的具體用法?Python PlotWindow.addToolBar怎麽用?Python PlotWindow.addToolBar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在silx.gui.plot.PlotWindow的用法示例。


在下文中一共展示了PlotWindow.addToolBar方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestProfileToolBar

# 需要導入模塊: from silx.gui.plot import PlotWindow [as 別名]
# 或者: from silx.gui.plot.PlotWindow import addToolBar [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()
開發者ID:dnaudet,項目名稱:silx,代碼行數:102,代碼來源:testProfile.py

示例2: PlotWindow

# 需要導入模塊: from silx.gui.plot import PlotWindow [as 別名]
# 或者: from silx.gui.plot.PlotWindow import addToolBar [as 別名]
            y1 = y0 + 1.0

            # Set the active curve data with the shifted y values
            activeCurve.setData(x0, y1)


# creating QApplication is mandatory in order to use qt widget
app = qt.QApplication([])

sys.excepthook = qt.exceptionHandler

# create a PlotWindow
plotwin = PlotWindow()
# Add a new toolbar
toolbar = qt.QToolBar("My toolbar")
plotwin.addToolBar(toolbar)
# Get a reference to the PlotWindow's menu bar, add a menu
menubar = plotwin.menuBar()
actions_menu = menubar.addMenu("Custom actions")

# Initialize our action, give it plotwin as a parameter
myaction = ShiftUpAction(plotwin)
# Add action to the menubar and toolbar
toolbar.addAction(myaction)
actions_menu.addAction(myaction)

# Plot a couple of curves with synthetic data
x = [0, 1, 2, 3, 4, 5, 6]
y1 = [0, 1, 0, 1, 0, 1, 0]
y2 = [0, 1, 2, 3, 4, 5, 6]
plotwin.addCurve(x, y1, legend="triangle shaped curve")
開發者ID:dnaudet,項目名稱:silx,代碼行數:33,代碼來源:shiftPlotAction.py

示例3: TestPositionInfo

# 需要導入模塊: from silx.gui.plot import PlotWindow [as 別名]
# 或者: from silx.gui.plot.PlotWindow import addToolBar [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)
開發者ID:silx-kit,項目名稱:silx,代碼行數:67,代碼來源:testPlotTools.py

示例4: TestScatterProfileToolBar

# 需要導入模塊: from silx.gui.plot import PlotWindow [as 別名]
# 或者: from silx.gui.plot.PlotWindow import addToolBar [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
#.........這裏部分代碼省略.........
開發者ID:dnaudet,項目名稱:silx,代碼行數:103,代碼來源:testScatterProfileToolBar.py


注:本文中的silx.gui.plot.PlotWindow.addToolBar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。