Beispiel #1
0
class TestSaveAction(unittest.TestCase):
    def setUp(self):
        self.plot = PlotWidget(backend='none')
        self.saveAction = SaveAction(plot=self.plot)

        self.tempdir = tempfile.mkdtemp()
        self.out_fname = os.path.join(self.tempdir, "out.dat")

    def tearDown(self):
        os.unlink(self.out_fname)
        os.rmdir(self.tempdir)

    def testSaveMultipleCurvesAsSpec(self):
        """Test that labels are properly used."""
        self.plot.setGraphXLabel("graph x label")
        self.plot.setGraphYLabel("graph y label")

        self.plot.addCurve([0, 1], [1, 2],
                           "curve with labels",
                           xlabel="curve0 X",
                           ylabel="curve0 Y")
        self.plot.addCurve([-1, 3], [-6, 2],
                           "curve with X label",
                           xlabel="curve1 X")
        self.plot.addCurve([-2, 0], [8, 12],
                           "curve with Y label",
                           ylabel="curve2 Y")
        self.plot.addCurve([3, 1], [7, 6], "curve with no labels")

        self.saveAction._saveCurves(self.out_fname,
                                    SaveAction.ALL_CURVES_FILTERS[0]
                                    )  # "All curves as SpecFile (*.dat)"

        with open(self.out_fname, "rb") as f:
            file_content = f.read()
            if hasattr(file_content, "decode"):
                file_content = file_content.decode()

            # case with all curve labels specified
            self.assertIn("#S 1 curve0 Y", file_content)
            self.assertIn("#L curve0 X  curve0 Y", file_content)

            # graph X&Y labels are used when no curve label is specified
            self.assertIn("#S 2 graph y label", file_content)
            self.assertIn("#L curve1 X  graph y label", file_content)

            self.assertIn("#S 3 curve2 Y", file_content)
            self.assertIn("#L graph x label  curve2 Y", file_content)

            self.assertIn("#S 4 graph y label", file_content)
            self.assertIn("#L graph x label  graph y label", file_content)
Beispiel #2
0
class TestSaveActionSaveCurvesAsSpec(unittest.TestCase):

    def setUp(self):
        self.plot = PlotWidget(backend='none')
        self.saveAction = SaveAction(plot=self.plot)

        self.tempdir = tempfile.mkdtemp()
        self.out_fname = os.path.join(self.tempdir, "out.dat")

    def tearDown(self):
        os.unlink(self.out_fname)
        os.rmdir(self.tempdir)

    def testSaveMultipleCurvesAsSpec(self):
        """Test that labels are properly used."""
        self.plot.setGraphXLabel("graph x label")
        self.plot.setGraphYLabel("graph y label")

        self.plot.addCurve([0, 1], [1, 2], "curve with labels",
                           xlabel="curve0 X", ylabel="curve0 Y")
        self.plot.addCurve([-1, 3], [-6, 2], "curve with X label",
                           xlabel="curve1 X")
        self.plot.addCurve([-2, 0], [8, 12], "curve with Y label",
                           ylabel="curve2 Y")
        self.plot.addCurve([3, 1], [7, 6], "curve with no labels")

        self.saveAction._saveCurves(self.plot,
                                    self.out_fname,
                                    SaveAction.DEFAULT_ALL_CURVES_FILTERS[0])  # "All curves as SpecFile (*.dat)"

        with open(self.out_fname, "rb") as f:
            file_content = f.read()
            if hasattr(file_content, "decode"):
                file_content = file_content.decode()

            # case with all curve labels specified
            self.assertIn("#S 1 curve0 Y", file_content)
            self.assertIn("#L curve0 X  curve0 Y", file_content)

            # graph X&Y labels are used when no curve label is specified
            self.assertIn("#S 2 graph y label", file_content)
            self.assertIn("#L curve1 X  graph y label", file_content)

            self.assertIn("#S 3 curve2 Y", file_content)
            self.assertIn("#L graph x label  curve2 Y", file_content)

            self.assertIn("#S 4 graph y label", file_content)
            self.assertIn("#L graph x label  graph y label", file_content)
Beispiel #3
0
    def addOutputToolBar(self):
        self.outputToolBar = QToolBar("IO", parent=self)

        self.copyAction = CopyAction(plot=self, parent=self.outputToolBar)
        self.saveAction = SaveAction(plot=self, parent=self.outputToolBar)

        self.outputToolBar.addAction(self.copyAction)
        self.outputToolBar.addAction(self.saveAction)

        self.addToolBar(self.outputToolBar)
Beispiel #4
0
    def testFileFilterAPI(self):
        """Test addition/update of a file filter"""
        saveAction = SaveAction(plot=self.plot, parent=self.plot)

        # Add a new file filter
        nameFilter = 'Dummy file (*.dummy)'
        saveAction.setFileFilter('all', nameFilter, self._dummySaveFunction)
        self.assertTrue(nameFilter in saveAction.getFileFilters('all'))
        self.assertEqual(
            saveAction.getFileFilters('all')[nameFilter],
            self._dummySaveFunction)

        # Update an existing file filter
        nameFilter = SaveAction.IMAGE_FILTER_EDF
        saveAction.setFileFilter('image', nameFilter, self._dummySaveFunction)
        self.assertEqual(
            saveAction.getFileFilters('image')[nameFilter],
            self._dummySaveFunction)
Beispiel #5
0
    def testFileFilterAPI(self):
        """Test addition/update of a file filter"""
        saveAction = SaveAction(plot=self.plot, parent=self.plot)

        # Add a new file filter
        nameFilter = 'Dummy file (*.dummy)'
        saveAction.setFileFilter('all', nameFilter, self._dummySaveFunction)
        self.assertTrue(nameFilter in saveAction.getFileFilters('all'))
        self.assertEqual(saveAction.getFileFilters('all')[nameFilter],
                         self._dummySaveFunction)

        # Update an existing file filter
        nameFilter = SaveAction.IMAGE_FILTER_EDF
        saveAction.setFileFilter('image', nameFilter, self._dummySaveFunction)
        self.assertEqual(saveAction.getFileFilters('image')[nameFilter],
                         self._dummySaveFunction)
    def __init__(self, *args, **kwargs):
        super(PlotWidgetWithContextMenu, self).__init__(*args, **kwargs)
        self.setWindowTitle('PlotWidget with a context menu')
        self.setGraphTitle('Right-click on the plot to access context menu')

        # Create QAction for the context menu once for all
        self._zoomBackAction = ZoomBackAction(plot=self, parent=self)
        self._crosshairAction = CrosshairAction(plot=self, parent=self)
        self._saveAction = SaveAction(plot=self, parent=self)
        self._printAction = PrintAction(plot=self, parent=self)

        # Retrieve PlotWidget's plot area widget
        plotArea = self.getWidgetHandle()

        # Set plot area custom context menu
        plotArea.setContextMenuPolicy(qt.Qt.CustomContextMenu)
        plotArea.customContextMenuRequested.connect(self._contextMenu)
Beispiel #7
0
    def setUp(self):
        self.plot = PlotWidget(backend='none')
        self.saveAction = SaveAction(plot=self.plot)

        self.tempdir = tempfile.mkdtemp()
        self.out_fname = os.path.join(self.tempdir, "out.dat")
Beispiel #8
0
    def setUp(self):
        self.plot = PlotWidget(backend='none')
        self.saveAction = SaveAction(plot=self.plot)

        self.tempdir = tempfile.mkdtemp()
        self.out_fname = os.path.join(self.tempdir, "out.dat")
    def testFileFilterAPI(self):
        """Test addition/update of a file filter"""
        saveAction = SaveAction(plot=self.plot, parent=self.plot)

        # Add a new file filter
        nameFilter = 'Dummy file (*.dummy)'
        saveAction.setFileFilter('all', nameFilter, self._dummySaveFunction)
        self.assertTrue(nameFilter in saveAction.getFileFilters('all'))
        self.assertEqual(
            saveAction.getFileFilters('all')[nameFilter],
            self._dummySaveFunction)

        # Add a new file filter at a particular position
        nameFilter = 'Dummy file2 (*.dummy)'
        saveAction.setFileFilter('all',
                                 nameFilter,
                                 self._dummySaveFunction,
                                 index=3)
        self.assertTrue(nameFilter in saveAction.getFileFilters('all'))
        filters = saveAction.getFileFilters('all')
        self.assertEqual(filters[nameFilter], self._dummySaveFunction)
        self.assertEqual(list(filters.keys()).index(nameFilter), 3)

        # Update an existing file filter
        nameFilter = SaveAction.IMAGE_FILTER_EDF
        saveAction.setFileFilter('image', nameFilter, self._dummySaveFunction)
        self.assertEqual(
            saveAction.getFileFilters('image')[nameFilter],
            self._dummySaveFunction)

        # Change the position of an existing file filter
        nameFilter = 'Dummy file2 (*.dummy)'
        oldIndex = list(saveAction.getFileFilters('all')).index(nameFilter)
        newIndex = oldIndex - 1
        saveAction.setFileFilter('all',
                                 nameFilter,
                                 self._dummySaveFunction,
                                 index=newIndex)
        filters = saveAction.getFileFilters('all')
        self.assertEqual(filters[nameFilter], self._dummySaveFunction)
        self.assertEqual(list(filters.keys()).index(nameFilter), newIndex)