summaryrefslogtreecommitdiff
path: root/src/silx/gui/data/_RecordPlot.py
blob: b994a6eb528b9b29951ceb9cb5aba4b6f977f818 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from silx.gui.plot.PlotWindow import PlotWindow
from silx.gui.plot.PlotWidget import PlotWidget
from .. import qt


class RecordPlot(PlotWindow):
    def __init__(self, parent=None, backend=None):
        super(RecordPlot, self).__init__(
            parent=parent,
            backend=backend,
            resetzoom=True,
            autoScale=True,
            logScale=True,
            grid=True,
            curveStyle=True,
            colormap=False,
            aspectRatio=False,
            yInverted=False,
            copy=True,
            save=True,
            print_=True,
            control=True,
            position=True,
            roi=True,
            mask=False,
            fit=True,
        )
        if parent is None:
            self.setWindowTitle("RecordPlot")
        self._axesSelectionToolBar = AxesSelectionToolBar(parent=self, plot=self)
        self.addToolBar(qt.Qt.BottomToolBarArea, self._axesSelectionToolBar)

    def setXAxisFieldName(self, value):
        """Set the current selected field for the X axis.

        :param Union[str,None] value:
        """
        label = "" if value is None else value
        index = self._axesSelectionToolBar.getXAxisDropDown().findData(value)

        if index >= 0:
            self.getXAxis().setLabel(label)
            self._axesSelectionToolBar.getXAxisDropDown().setCurrentIndex(index)

    def getXAxisFieldName(self):
        """Returns currently selected field for the X axis or None.

        rtype: Union[str,None]
        """
        return self._axesSelectionToolBar.getXAxisDropDown().currentData()

    def setYAxisFieldName(self, value):
        self.getYAxis().setLabel(value)
        index = self._axesSelectionToolBar.getYAxisDropDown().findText(value)
        if index >= 0:
            self._axesSelectionToolBar.getYAxisDropDown().setCurrentIndex(index)

    def getYAxisFieldName(self):
        return self._axesSelectionToolBar.getYAxisDropDown().currentText()

    def setSelectableXAxisFieldNames(self, fieldNames):
        """Add list of field names to X axis

        :param List[str] fieldNames:
        """
        comboBox = self._axesSelectionToolBar.getXAxisDropDown()
        comboBox.clear()
        comboBox.addItem("-", None)
        comboBox.insertSeparator(1)
        for name in fieldNames:
            comboBox.addItem(name, name)

    def setSelectableYAxisFieldNames(self, fieldNames):
        self._axesSelectionToolBar.getYAxisDropDown().clear()
        self._axesSelectionToolBar.getYAxisDropDown().addItems(fieldNames)

    def getAxesSelectionToolBar(self):
        return self._axesSelectionToolBar


class AxesSelectionToolBar(qt.QToolBar):
    def __init__(self, parent=None, plot=None, title="Plot Axes Selection"):
        super(AxesSelectionToolBar, self).__init__(title, parent)

        assert isinstance(plot, PlotWidget)

        self.addWidget(qt.QLabel("Field selection: "))

        self._labelXAxis = qt.QLabel(" X: ")
        self.addWidget(self._labelXAxis)

        self._selectXAxisDropDown = qt.QComboBox()
        self.addWidget(self._selectXAxisDropDown)

        self._labelYAxis = qt.QLabel(" Y: ")
        self.addWidget(self._labelYAxis)

        self._selectYAxisDropDown = qt.QComboBox()
        self.addWidget(self._selectYAxisDropDown)

    def getXAxisDropDown(self):
        return self._selectXAxisDropDown

    def getYAxisDropDown(self):
        return self._selectYAxisDropDown