Beispiel #1
0
    def __init__(self, parent=None, flags=Qt.Qt.WindowFlags()):
        self.parent = parent
        # if parent==None or not isinstance(parent, TaurusPlotConfigCapable):
        #    raise NotImplementedError, "Parent object doesn't implement TaurusPlotConfigCapable class"
        # call qt designer generated functions to initialize GUI
        Qt.QDialog.__init__(self, parent, flags)
        self.loadUi()

        # insert the CurvesAppearanceWidget
        #(@TODO:must be changed to be done directly in the ui, but I couldn't make the widget available to TaurusDesigner)
        from curvesAppearanceChooserDlg import CurvesAppearanceChooser
        layout = Qt.QVBoxLayout()
        self.curvesAppearanceChooser = CurvesAppearanceChooser(None)
        layout.addWidget(self.curvesAppearanceChooser)
        self.ui.curveAppearanceGB.setLayout(layout)

        # set the values for the CurvesAppearanceChooser
        self.curvesAppearanceChooser.setCurves(
            self.parent.getCurveAppearancePropertiesDict())

        # insert valid values into mode combobox (linear or logarihtmic) and
        # set selected one in combobox
        self.ui.xModeComboBox.insertItem(0, "Linear")
        self.ui.xModeComboBox.insertItem(1, "Logarithmic")
        self.ui.y1ModeComboBox.insertItem(0, "Linear")
        self.ui.y1ModeComboBox.insertItem(1, "Logarithmic")
        self.ui.y2ModeComboBox.insertItem(0, "Linear")
        self.ui.y2ModeComboBox.insertItem(1, "Logarithmic")

        # insert valid values into peaks combobox (max, min or both) and set
        # selected one in combobox
        self.ui.peaksComboBox.insertItem(0, "Both")
        self.ui.peaksComboBox.insertItem(1, "Max")
        self.ui.peaksComboBox.insertItem(2, "Min")
        self.ui.peaksComboBox.insertItem(3, "None")

        # Init X axis group
        self.ui.xRangeCB.setVisible(False)
        self.ui.xLabelRange.setVisible(False)
        if self.parent.getXIsTime():
            # adapt the X axis group for time-based measurements
            self.ui.xRangeCB.addItems(
                ["", "1 m", "1 h", "1 d", "1 w", "30 d", "1 y"])
            self.ui.xGroupBox.setTitle("Time")
            self.ui.xLabelMin.setText("Start")
            self.ui.xLabelMax.setText("End")
            timetooltip = """It accepts both absolute data-times (e.g. "25/10/1917 21:45:01") \n"""\
                """or relative ones with format <+|-><number><s|m|h|d|w|y> (e.g. "-12h").\n"""\
                """The keyword "now" is also accepted."""
            self.ui.xEditMin.setToolTip(timetooltip)
            self.ui.xEditMax.setToolTip(timetooltip)
        else:
            # The default settings are ok for non-time plots
            self.ui.xEditMin.setValidator(Qt.QDoubleValidator(self))
            self.ui.xEditMax.setValidator(Qt.QDoubleValidator(self))
            self.ui.xRangeCB.setValidator(Qt.QDoubleValidator(self))
            self.ui.xRangeCB.addItems(
                ["", "10", "100", "1000", "10000", "100000", "1000000"])

        self.ui.xDynScaleCheckBox.setChecked(self.parent.getXDynScale())
        auto = self.parent.axisAutoScale(Qwt5.QwtPlot.xBottom)
        self.ui.xAutoGroupBox.setChecked(not auto)

        # this call already initialises the edit boxes of the X axis
        self.setXDynScale(self.parent.getXDynScale())
        self.ui.xDynScaleCheckBox.setVisible(
            self.parent.isXDynScaleSupported())

        # Init Y axes groups
        self._populateYAxisScales()
        self.ui.y1AutoGroupBox.setChecked(
            not self.parent.axisAutoScale(Qwt5.QwtPlot.yLeft))
        self.ui.y2AutoGroupBox.setChecked(
            not self.parent.axisAutoScale(Qwt5.QwtPlot.yRight))

        # set validators for Y min/max edits
        self.ui.y1EditMin.setValidator(Qt.QDoubleValidator(self))
        self.ui.y1EditMax.setValidator(Qt.QDoubleValidator(self))
        self.ui.y2EditMin.setValidator(Qt.QDoubleValidator(self))
        self.ui.y2EditMax.setValidator(Qt.QDoubleValidator(self))

        # populate initial axis mode (linear or logarithmic) values from plot. Warning!: we're using
        # qwt QwtPlot.axis enum type to relate our GUI combo name and qwt axis
        # name (enum type).
        axes = [
            self.ui.y1ModeComboBox, self.ui.y2ModeComboBox,
            self.ui.xModeComboBox
        ]
        for axis in range(len(axes)):
            scaleType = self.parent.getAxisTransformationType(axis)
            if scaleType == Qwt5.QwtScaleTransformation.Linear:
                axes[axis].setCurrentIndex(0)
            elif scaleType == Qwt5.QwtScaleTransformation.Log10:
                axes[axis].setCurrentIndex(1)
            else:
                raise TypeError, "TaurusPlotConfigDialog::__init__(): unexpected axis scale type (linear or logarihtmic expected)"
        self.ui.xModeComboBox.setEnabled(not self.parent.getXIsTime())

        # determine which axes are visible
        if not self.parent.axisEnabled(Qwt5.QwtPlot.xBottom):
            self.ui.xGroupBox.setVisible(False)

        # populate initial peaks from parent
        if self.parent._showMaxPeaks and self.parent._showMinPeaks:
            self.ui.peaksComboBox.setCurrentIndex(0)
        elif self.parent._showMaxPeaks:
            self.ui.peaksComboBox.setCurrentIndex(1)
        elif self.parent._showMinPeaks:
            self.ui.peaksComboBox.setCurrentIndex(2)
        else:
            self.ui.peaksComboBox.setCurrentIndex(3)

        # connect signals
        self.connect(self.ui.buttonBox.button(Qt.QDialogButtonBox.Close),
                     Qt.SIGNAL("clicked()"), self.hide)
        self.connect(self.ui.buttonBox.button(Qt.QDialogButtonBox.Apply),
                     Qt.SIGNAL("clicked()"), self.apply)
        self.connect(self.ui.xAutoGroupBox, Qt.SIGNAL("toggled (bool)"),
                     self.toggledAutoScale)
        self.connect(self.ui.y1AutoGroupBox, Qt.SIGNAL("toggled (bool)"),
                     self.toggledAutoScale)
        self.connect(self.ui.y2AutoGroupBox, Qt.SIGNAL("toggled (bool)"),
                     self.toggledAutoScale)
        #        self.connect(self.ui.xEditMin,  Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.xEditMax,  Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.y1EditMin, Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.y1EditMax, Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.y2EditMin, Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.y2EditMax, Qt.SIGNAL("returnPressed()"),self.apply)
        self.connect(self.ui.xModeComboBox,
                     Qt.SIGNAL("currentIndexChanged(const QString&)"),
                     self.modeComboChanged)
        self.connect(self.ui.xDynScaleCheckBox, Qt.SIGNAL("toggled (bool)"),
                     self.setXDynScale)
        #self.connect(self.ui.xRangeCB, Qt.SIGNAL("currentIndexChanged(const QString&)"),self.apply)
        self.connect(self.ui.y1ModeComboBox,
                     Qt.SIGNAL("currentIndexChanged(const QString&)"),
                     self.modeComboChanged)
        self.connect(self.ui.y2ModeComboBox,
                     Qt.SIGNAL("currentIndexChanged(const QString&)"),
                     self.modeComboChanged)
        self.connect(self.ui.peaksComboBox,
                     Qt.SIGNAL("currentIndexChanged(int)"),
                     self.peaksComboChanged)
        # self.connect(self.curvesAppearanceChooser,
        # Qt.SIGNAL("controlChanged"),self.apply) #"autoapply" mode for *all*
        # the curve appearance controls
        self.connect(self.curvesAppearanceChooser.assignToY1BT,
                     Qt.SIGNAL("clicked()"), self.setCurvesYAxis)
        self.connect(self.curvesAppearanceChooser.assignToY2BT,
                     Qt.SIGNAL("clicked()"), self.setCurvesYAxis)
        self.connect(self.curvesAppearanceChooser.bckgndBT,
                     Qt.SIGNAL("clicked()"), self.changeBackgroundColor)
        self.connect(self.curvesAppearanceChooser.changeTitlesBT,
                     Qt.SIGNAL("clicked()"), self.onChangeTitles)
        self.connect(self.curvesAppearanceChooser.curvesLW,
                     Qt.SIGNAL("CurveTitleEdited"), self.onCurveTitleEdited)

        # finally adjust size
        self.adjustSize()
Beispiel #2
0
    def __init__(self, parent=None, flags=Qt.Qt.WindowFlags()):
        self.parent = parent
        # if parent==None or not isinstance(parent, TaurusPlotConfigCapable):
        #    raise NotImplementedError, "Parent object doesn't implement TaurusPlotConfigCapable class"
        # call qt designer generated functions to initialize GUI
        Qt.QDialog.__init__(self, parent, flags)
        self.loadUi()

        # insert the CurvesAppearanceWidget
        #(@TODO:must be changed to be done directly in the ui, but I couldn't make the widget available to TaurusDesigner)
        from curvesAppearanceChooserDlg import CurvesAppearanceChooser
        layout = Qt.QVBoxLayout()
        self.curvesAppearanceChooser = CurvesAppearanceChooser(None)
        layout.addWidget(self.curvesAppearanceChooser)
        self.ui.curveAppearanceGB.setLayout(layout)

        # set the values for the CurvesAppearanceChooser
        self.curvesAppearanceChooser.setCurves(
            self.parent.getCurveAppearancePropertiesDict())

        # insert valid values into mode combobox (linear or logarihtmic) and
        # set selected one in combobox
        self.ui.xModeComboBox.insertItem(0, "Linear")
        self.ui.xModeComboBox.insertItem(1, "Logarithmic")
        self.ui.y1ModeComboBox.insertItem(0, "Linear")
        self.ui.y1ModeComboBox.insertItem(1, "Logarithmic")
        self.ui.y2ModeComboBox.insertItem(0, "Linear")
        self.ui.y2ModeComboBox.insertItem(1, "Logarithmic")

        # insert valid values into peaks combobox (max, min or both) and set
        # selected one in combobox
        self.ui.peaksComboBox.insertItem(0, "Both")
        self.ui.peaksComboBox.insertItem(1, "Max")
        self.ui.peaksComboBox.insertItem(2, "Min")
        self.ui.peaksComboBox.insertItem(3, "None")

        # Init X axis group
        self.ui.xRangeCB.setVisible(False)
        self.ui.xLabelRange.setVisible(False)
        if self.parent.getXIsTime():
            # adapt the X axis group for time-based measurements
            self.ui.xRangeCB.addItems(["",
                                       "1 m",
                                       "1 h",
                                       "1 d",
                                       "1 w",
                                       "30 d",
                                       "1 y"])
            self.ui.xGroupBox.setTitle("Time")
            self.ui.xLabelMin.setText("Start")
            self.ui.xLabelMax.setText("End")
            timetooltip = """It accepts both absolute data-times (e.g. "25/10/1917 21:45:01") \n"""\
                """or relative ones with format <+|-><number><s|m|h|d|w|y> (e.g. "-12h").\n"""\
                """The keyword "now" is also accepted."""
            self.ui.xEditMin.setToolTip(timetooltip)
            self.ui.xEditMax.setToolTip(timetooltip)
        else:
            # The default settings are ok for non-time plots
            self.ui.xEditMin.setValidator(Qt.QDoubleValidator(self))
            self.ui.xEditMax.setValidator(Qt.QDoubleValidator(self))
            self.ui.xRangeCB.setValidator(Qt.QDoubleValidator(self))
            self.ui.xRangeCB.addItems(["",
                                       "10",
                                       "100",
                                       "1000",
                                       "10000",
                                       "100000",
                                       "1000000"])

        self.ui.xDynScaleCheckBox.setChecked(self.parent.getXDynScale())
        auto = self.parent.axisAutoScale(Qwt5.QwtPlot.xBottom)
        self.ui.xAutoGroupBox.setChecked(not auto)

        # this call already initialises the edit boxes of the X axis
        self.setXDynScale(self.parent.getXDynScale())
        self.ui.xDynScaleCheckBox.setVisible(
            self.parent.isXDynScaleSupported())

        # Init Y axes groups
        self._populateYAxisScales()
        self.ui.y1AutoGroupBox.setChecked(
            not self.parent.axisAutoScale(Qwt5.QwtPlot.yLeft))
        self.ui.y2AutoGroupBox.setChecked(
            not self.parent.axisAutoScale(Qwt5.QwtPlot.yRight))

        # set validators for Y min/max edits
        self.ui.y1EditMin.setValidator(Qt.QDoubleValidator(self))
        self.ui.y1EditMax.setValidator(Qt.QDoubleValidator(self))
        self.ui.y2EditMin.setValidator(Qt.QDoubleValidator(self))
        self.ui.y2EditMax.setValidator(Qt.QDoubleValidator(self))

        # populate initial axis mode (linear or logarithmic) values from plot. Warning!: we're using
        # qwt QwtPlot.axis enum type to relate our GUI combo name and qwt axis
        # name (enum type).
        axes = [self.ui.y1ModeComboBox,
                self.ui.y2ModeComboBox, self.ui.xModeComboBox]
        for axis in range(len(axes)):
            scaleType = self.parent.getAxisTransformationType(axis)
            if scaleType == Qwt5.QwtScaleTransformation.Linear:
                axes[axis].setCurrentIndex(0)
            elif scaleType == Qwt5.QwtScaleTransformation.Log10:
                axes[axis].setCurrentIndex(1)
            else:
                raise TypeError, "TaurusPlotConfigDialog::__init__(): unexpected axis scale type (linear or logarihtmic expected)"
        self.ui.xModeComboBox.setEnabled(not self.parent.getXIsTime())

        # determine which axes are visible
        if not self.parent.axisEnabled(Qwt5.QwtPlot.xBottom):
            self.ui.xGroupBox.setVisible(False)

        # populate initial peaks from parent
        if self.parent._showMaxPeaks and self.parent._showMinPeaks:
            self.ui.peaksComboBox.setCurrentIndex(0)
        elif self.parent._showMaxPeaks:
            self.ui.peaksComboBox.setCurrentIndex(1)
        elif self.parent._showMinPeaks:
            self.ui.peaksComboBox.setCurrentIndex(2)
        else:
            self.ui.peaksComboBox.setCurrentIndex(3)

        # connect signals
        self.ui.buttonBox.button(
            Qt.QDialogButtonBox.Close).clicked.connect(self.hide)
        self.ui.buttonBox.button(
            Qt.QDialogButtonBox.Apply).clicked.connect(self.apply)
        self.ui.xAutoGroupBox.toggled.connect(self.toggledAutoScale)
        self.ui.y1AutoGroupBox.toggled.connect(self.toggledAutoScale)
        self.ui.y2AutoGroupBox.toggled.connect(self.toggledAutoScale)
#        self.connect(self.ui.xEditMin,  Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.xEditMax,  Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.y1EditMin, Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.y1EditMax, Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.y2EditMin, Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.y2EditMax, Qt.SIGNAL("returnPressed()"),self.apply)
        self.ui.xModeComboBox.currentIndexChanged.connect(self.modeComboChanged)
        self.ui.xDynScaleCheckBox.toggled.connect(self.setXDynScale)
        #self.connect(self.ui.xRangeCB, Qt.SIGNAL("currentIndexChanged(const QString&)"),self.apply)
        self.ui.y1ModeComboBox.currentIndexChanged.connect(self.modeComboChanged)
        self.ui.y2ModeComboBox.currentIndexChanged.connect(self.modeComboChanged)
        self.ui.peaksComboBox.currentIndexChanged.connect(self.peaksComboChanged)
        # self.connect(self.curvesAppearanceChooser,
        # Qt.SIGNAL("controlChanged"),self.apply) #"autoapply" mode for *all*
        # the curve appearance controls
        self.curvesAppearanceChooser.assignToY1BT.clicked[()].connect(self.setCurvesYAxis)
        self.curvesAppearanceChooser.assignToY2BT.clicked[()].connect(self.setCurvesYAxis)
        self.curvesAppearanceChooser.bckgndBT.clicked.connect(self.changeBackgroundColor)
        self.curvesAppearanceChooser.changeTitlesBT.clicked.connect(self.onChangeTitles)
        self.curvesAppearanceChooser.CurveTitleEdited.connect(self.onCurveTitleEdited)

        # finally adjust size
        self.adjustSize()
Beispiel #3
0
class TaurusPlotConfigDialog(Qt.QDialog):
    """This class is used to build and manage the plot configuration dialog. It
    has been designed using the qt designer application, and then loaded to this
    widget. Hence, if you need to modify the dialog, you can use the
    TaurusPlotConfigDialog.ui file (under ui directory) to make it easier."""
    def __init__(self, parent=None, flags=Qt.Qt.WindowFlags()):
        self.parent = parent
        # if parent==None or not isinstance(parent, TaurusPlotConfigCapable):
        #    raise NotImplementedError, "Parent object doesn't implement TaurusPlotConfigCapable class"
        # call qt designer generated functions to initialize GUI
        Qt.QDialog.__init__(self, parent, flags)
        self.loadUi()

        # insert the CurvesAppearanceWidget
        #(@TODO:must be changed to be done directly in the ui, but I couldn't make the widget available to TaurusDesigner)
        from curvesAppearanceChooserDlg import CurvesAppearanceChooser
        layout = Qt.QVBoxLayout()
        self.curvesAppearanceChooser = CurvesAppearanceChooser(None)
        layout.addWidget(self.curvesAppearanceChooser)
        self.ui.curveAppearanceGB.setLayout(layout)

        # set the values for the CurvesAppearanceChooser
        self.curvesAppearanceChooser.setCurves(
            self.parent.getCurveAppearancePropertiesDict())

        # insert valid values into mode combobox (linear or logarihtmic) and
        # set selected one in combobox
        self.ui.xModeComboBox.insertItem(0, "Linear")
        self.ui.xModeComboBox.insertItem(1, "Logarithmic")
        self.ui.y1ModeComboBox.insertItem(0, "Linear")
        self.ui.y1ModeComboBox.insertItem(1, "Logarithmic")
        self.ui.y2ModeComboBox.insertItem(0, "Linear")
        self.ui.y2ModeComboBox.insertItem(1, "Logarithmic")

        # insert valid values into peaks combobox (max, min or both) and set
        # selected one in combobox
        self.ui.peaksComboBox.insertItem(0, "Both")
        self.ui.peaksComboBox.insertItem(1, "Max")
        self.ui.peaksComboBox.insertItem(2, "Min")
        self.ui.peaksComboBox.insertItem(3, "None")

        # Init X axis group
        self.ui.xRangeCB.setVisible(False)
        self.ui.xLabelRange.setVisible(False)
        if self.parent.getXIsTime():
            # adapt the X axis group for time-based measurements
            self.ui.xRangeCB.addItems(
                ["", "1 m", "1 h", "1 d", "1 w", "30 d", "1 y"])
            self.ui.xGroupBox.setTitle("Time")
            self.ui.xLabelMin.setText("Start")
            self.ui.xLabelMax.setText("End")
            timetooltip = """It accepts both absolute data-times (e.g. "25/10/1917 21:45:01") \n"""\
                """or relative ones with format <+|-><number><s|m|h|d|w|y> (e.g. "-12h").\n"""\
                """The keyword "now" is also accepted."""
            self.ui.xEditMin.setToolTip(timetooltip)
            self.ui.xEditMax.setToolTip(timetooltip)
        else:
            # The default settings are ok for non-time plots
            self.ui.xEditMin.setValidator(Qt.QDoubleValidator(self))
            self.ui.xEditMax.setValidator(Qt.QDoubleValidator(self))
            self.ui.xRangeCB.setValidator(Qt.QDoubleValidator(self))
            self.ui.xRangeCB.addItems(
                ["", "10", "100", "1000", "10000", "100000", "1000000"])

        self.ui.xDynScaleCheckBox.setChecked(self.parent.getXDynScale())
        auto = self.parent.axisAutoScale(Qwt5.QwtPlot.xBottom)
        self.ui.xAutoGroupBox.setChecked(not auto)

        # this call already initialises the edit boxes of the X axis
        self.setXDynScale(self.parent.getXDynScale())
        self.ui.xDynScaleCheckBox.setVisible(
            self.parent.isXDynScaleSupported())

        # Init Y axes groups
        self._populateYAxisScales()
        self.ui.y1AutoGroupBox.setChecked(
            not self.parent.axisAutoScale(Qwt5.QwtPlot.yLeft))
        self.ui.y2AutoGroupBox.setChecked(
            not self.parent.axisAutoScale(Qwt5.QwtPlot.yRight))

        # set validators for Y min/max edits
        self.ui.y1EditMin.setValidator(Qt.QDoubleValidator(self))
        self.ui.y1EditMax.setValidator(Qt.QDoubleValidator(self))
        self.ui.y2EditMin.setValidator(Qt.QDoubleValidator(self))
        self.ui.y2EditMax.setValidator(Qt.QDoubleValidator(self))

        # populate initial axis mode (linear or logarithmic) values from plot. Warning!: we're using
        # qwt QwtPlot.axis enum type to relate our GUI combo name and qwt axis
        # name (enum type).
        axes = [
            self.ui.y1ModeComboBox, self.ui.y2ModeComboBox,
            self.ui.xModeComboBox
        ]
        for axis in range(len(axes)):
            scaleType = self.parent.getAxisTransformationType(axis)
            if scaleType == Qwt5.QwtScaleTransformation.Linear:
                axes[axis].setCurrentIndex(0)
            elif scaleType == Qwt5.QwtScaleTransformation.Log10:
                axes[axis].setCurrentIndex(1)
            else:
                raise TypeError, "TaurusPlotConfigDialog::__init__(): unexpected axis scale type (linear or logarihtmic expected)"
        self.ui.xModeComboBox.setEnabled(not self.parent.getXIsTime())

        # determine which axes are visible
        if not self.parent.axisEnabled(Qwt5.QwtPlot.xBottom):
            self.ui.xGroupBox.setVisible(False)

        # populate initial peaks from parent
        if self.parent._showMaxPeaks and self.parent._showMinPeaks:
            self.ui.peaksComboBox.setCurrentIndex(0)
        elif self.parent._showMaxPeaks:
            self.ui.peaksComboBox.setCurrentIndex(1)
        elif self.parent._showMinPeaks:
            self.ui.peaksComboBox.setCurrentIndex(2)
        else:
            self.ui.peaksComboBox.setCurrentIndex(3)

        # connect signals
        self.connect(self.ui.buttonBox.button(Qt.QDialogButtonBox.Close),
                     Qt.SIGNAL("clicked()"), self.hide)
        self.connect(self.ui.buttonBox.button(Qt.QDialogButtonBox.Apply),
                     Qt.SIGNAL("clicked()"), self.apply)
        self.connect(self.ui.xAutoGroupBox, Qt.SIGNAL("toggled (bool)"),
                     self.toggledAutoScale)
        self.connect(self.ui.y1AutoGroupBox, Qt.SIGNAL("toggled (bool)"),
                     self.toggledAutoScale)
        self.connect(self.ui.y2AutoGroupBox, Qt.SIGNAL("toggled (bool)"),
                     self.toggledAutoScale)
        #        self.connect(self.ui.xEditMin,  Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.xEditMax,  Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.y1EditMin, Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.y1EditMax, Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.y2EditMin, Qt.SIGNAL("returnPressed()"),self.apply)
        #        self.connect(self.ui.y2EditMax, Qt.SIGNAL("returnPressed()"),self.apply)
        self.connect(self.ui.xModeComboBox,
                     Qt.SIGNAL("currentIndexChanged(const QString&)"),
                     self.modeComboChanged)
        self.connect(self.ui.xDynScaleCheckBox, Qt.SIGNAL("toggled (bool)"),
                     self.setXDynScale)
        #self.connect(self.ui.xRangeCB, Qt.SIGNAL("currentIndexChanged(const QString&)"),self.apply)
        self.connect(self.ui.y1ModeComboBox,
                     Qt.SIGNAL("currentIndexChanged(const QString&)"),
                     self.modeComboChanged)
        self.connect(self.ui.y2ModeComboBox,
                     Qt.SIGNAL("currentIndexChanged(const QString&)"),
                     self.modeComboChanged)
        self.connect(self.ui.peaksComboBox,
                     Qt.SIGNAL("currentIndexChanged(int)"),
                     self.peaksComboChanged)
        # self.connect(self.curvesAppearanceChooser,
        # Qt.SIGNAL("controlChanged"),self.apply) #"autoapply" mode for *all*
        # the curve appearance controls
        self.connect(self.curvesAppearanceChooser.assignToY1BT,
                     Qt.SIGNAL("clicked()"), self.setCurvesYAxis)
        self.connect(self.curvesAppearanceChooser.assignToY2BT,
                     Qt.SIGNAL("clicked()"), self.setCurvesYAxis)
        self.connect(self.curvesAppearanceChooser.bckgndBT,
                     Qt.SIGNAL("clicked()"), self.changeBackgroundColor)
        self.connect(self.curvesAppearanceChooser.changeTitlesBT,
                     Qt.SIGNAL("clicked()"), self.onChangeTitles)
        self.connect(self.curvesAppearanceChooser.curvesLW,
                     Qt.SIGNAL("CurveTitleEdited"), self.onCurveTitleEdited)

        # finally adjust size
        self.adjustSize()

    def _populateXAxisScales(self):
        xMin = self.parent.axisScaleDiv(Qwt5.QwtPlot.xBottom).lowerBound()
        xMax = self.parent.axisScaleDiv(Qwt5.QwtPlot.xBottom).upperBound()
        if self.parent.getXIsTime():
            self.ui.xEditMin.setText(
                time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(int(xMin))))
            self.ui.xEditMax.setText(
                time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(int(xMax))))
        else:
            self.ui.xEditMin.setText(str(xMin))
            self.ui.xEditMax.setText(str(xMax))

    def _populateYAxisScales(self, axis=None):
        if axis is None or axis == Qwt5.QwtPlot.yLeft:
            self.ui.y1EditMin.setText(
                str(self.parent.axisScaleDiv(Qwt5.QwtPlot.yLeft).lowerBound()))
            self.ui.y1EditMax.setText(
                str(self.parent.axisScaleDiv(Qwt5.QwtPlot.yLeft).upperBound()))
        if axis is None or axis == Qwt5.QwtPlot.yRight:
            self.ui.y2EditMin.setText(
                str(
                    self.parent.axisScaleDiv(
                        Qwt5.QwtPlot.yRight).lowerBound()))
            self.ui.y2EditMax.setText(
                str(
                    self.parent.axisScaleDiv(
                        Qwt5.QwtPlot.yRight).upperBound()))

    def deltatime2str(self, dt, fuzzy=False):
        '''converts a time diff in secs to a string.
        If fuzzy=True it returns an approx time diff in s, min, hours or days'''
        dt = float(dt)
        if not fuzzy:
            return "%g s" % dt
        if dt < 2:
            return "%3.3g s" % dt
        elif dt < 120:
            return "%g s" % round(dt, 0)
        elif dt < 7200:
            return "%g m" % round(dt / 60, 0)
        elif dt < 172800:
            return "%g h" % round(dt / 3600, 0)
        else:
            return "%g d" % round(dt / 86400, 0)

    def str2deltatime(self, strtime):
        '''Translates a time string to seconds
        examples of valid relative times are: "now", "NOW", "Now", "-1d", "3w", "- 3.6e3 s",...
        examples of non-valid relative times:, "now + 2h", "-5", "3H" (unit names are case-sensitive)
        '''
        strtime = str(strtime).strip()
        timeunits = {
            's': 1,
            'm': 60,
            'h': 3600,
            'd': 3600 * 24,
            'w': 3600 * 24 * 7,
            'y': 3600 * 24 * 365
        }
        if strtime.lower() == "now":
            return time.time()
        if strtime[-1] in timeunits.keys():
            try:
                return float(strtime[:-1]) * timeunits[strtime[-1]]
            except Exception, e:
                print '[str2deltatime] No format could be applied to "%s"' % strtime
                return None
        else:
Beispiel #4
0
class TaurusPlotConfigDialog(Qt.QDialog):
    """This class is used to build and manage the plot configuration dialog. It
    has been designed using the qt designer application, and then loaded to this
    widget. Hence, if you need to modify the dialog, you can use the
    TaurusPlotConfigDialog.ui file (under ui directory) to make it easier."""

    def __init__(self, parent=None, flags=Qt.Qt.WindowFlags()):
        self.parent = parent
        # if parent==None or not isinstance(parent, TaurusPlotConfigCapable):
        #    raise NotImplementedError, "Parent object doesn't implement TaurusPlotConfigCapable class"
        # call qt designer generated functions to initialize GUI
        Qt.QDialog.__init__(self, parent, flags)
        self.loadUi()

        # insert the CurvesAppearanceWidget
        #(@TODO:must be changed to be done directly in the ui, but I couldn't make the widget available to TaurusDesigner)
        from curvesAppearanceChooserDlg import CurvesAppearanceChooser
        layout = Qt.QVBoxLayout()
        self.curvesAppearanceChooser = CurvesAppearanceChooser(None)
        layout.addWidget(self.curvesAppearanceChooser)
        self.ui.curveAppearanceGB.setLayout(layout)

        # set the values for the CurvesAppearanceChooser
        self.curvesAppearanceChooser.setCurves(
            self.parent.getCurveAppearancePropertiesDict())

        # insert valid values into mode combobox (linear or logarihtmic) and
        # set selected one in combobox
        self.ui.xModeComboBox.insertItem(0, "Linear")
        self.ui.xModeComboBox.insertItem(1, "Logarithmic")
        self.ui.y1ModeComboBox.insertItem(0, "Linear")
        self.ui.y1ModeComboBox.insertItem(1, "Logarithmic")
        self.ui.y2ModeComboBox.insertItem(0, "Linear")
        self.ui.y2ModeComboBox.insertItem(1, "Logarithmic")

        # insert valid values into peaks combobox (max, min or both) and set
        # selected one in combobox
        self.ui.peaksComboBox.insertItem(0, "Both")
        self.ui.peaksComboBox.insertItem(1, "Max")
        self.ui.peaksComboBox.insertItem(2, "Min")
        self.ui.peaksComboBox.insertItem(3, "None")

        # Init X axis group
        self.ui.xRangeCB.setVisible(False)
        self.ui.xLabelRange.setVisible(False)
        if self.parent.getXIsTime():
            # adapt the X axis group for time-based measurements
            self.ui.xRangeCB.addItems(["",
                                       "1 m",
                                       "1 h",
                                       "1 d",
                                       "1 w",
                                       "30 d",
                                       "1 y"])
            self.ui.xGroupBox.setTitle("Time")
            self.ui.xLabelMin.setText("Start")
            self.ui.xLabelMax.setText("End")
            timetooltip = """It accepts both absolute data-times (e.g. "25/10/1917 21:45:01") \n"""\
                """or relative ones with format <+|-><number><s|m|h|d|w|y> (e.g. "-12h").\n"""\
                """The keyword "now" is also accepted."""
            self.ui.xEditMin.setToolTip(timetooltip)
            self.ui.xEditMax.setToolTip(timetooltip)
        else:
            # The default settings are ok for non-time plots
            self.ui.xEditMin.setValidator(Qt.QDoubleValidator(self))
            self.ui.xEditMax.setValidator(Qt.QDoubleValidator(self))
            self.ui.xRangeCB.setValidator(Qt.QDoubleValidator(self))
            self.ui.xRangeCB.addItems(["",
                                       "10",
                                       "100",
                                       "1000",
                                       "10000",
                                       "100000",
                                       "1000000"])

        self.ui.xDynScaleCheckBox.setChecked(self.parent.getXDynScale())
        auto = self.parent.axisAutoScale(Qwt5.QwtPlot.xBottom)
        self.ui.xAutoGroupBox.setChecked(not auto)

        # this call already initialises the edit boxes of the X axis
        self.setXDynScale(self.parent.getXDynScale())
        self.ui.xDynScaleCheckBox.setVisible(
            self.parent.isXDynScaleSupported())

        # Init Y axes groups
        self._populateYAxisScales()
        self.ui.y1AutoGroupBox.setChecked(
            not self.parent.axisAutoScale(Qwt5.QwtPlot.yLeft))
        self.ui.y2AutoGroupBox.setChecked(
            not self.parent.axisAutoScale(Qwt5.QwtPlot.yRight))

        # set validators for Y min/max edits
        self.ui.y1EditMin.setValidator(Qt.QDoubleValidator(self))
        self.ui.y1EditMax.setValidator(Qt.QDoubleValidator(self))
        self.ui.y2EditMin.setValidator(Qt.QDoubleValidator(self))
        self.ui.y2EditMax.setValidator(Qt.QDoubleValidator(self))

        # populate initial axis mode (linear or logarithmic) values from plot. Warning!: we're using
        # qwt QwtPlot.axis enum type to relate our GUI combo name and qwt axis
        # name (enum type).
        axes = [self.ui.y1ModeComboBox,
                self.ui.y2ModeComboBox, self.ui.xModeComboBox]
        for axis in range(len(axes)):
            scaleType = self.parent.getAxisTransformationType(axis)
            if scaleType == Qwt5.QwtScaleTransformation.Linear:
                axes[axis].setCurrentIndex(0)
            elif scaleType == Qwt5.QwtScaleTransformation.Log10:
                axes[axis].setCurrentIndex(1)
            else:
                raise TypeError, "TaurusPlotConfigDialog::__init__(): unexpected axis scale type (linear or logarihtmic expected)"
        self.ui.xModeComboBox.setEnabled(not self.parent.getXIsTime())

        # determine which axes are visible
        if not self.parent.axisEnabled(Qwt5.QwtPlot.xBottom):
            self.ui.xGroupBox.setVisible(False)

        # populate initial peaks from parent
        if self.parent._showMaxPeaks and self.parent._showMinPeaks:
            self.ui.peaksComboBox.setCurrentIndex(0)
        elif self.parent._showMaxPeaks:
            self.ui.peaksComboBox.setCurrentIndex(1)
        elif self.parent._showMinPeaks:
            self.ui.peaksComboBox.setCurrentIndex(2)
        else:
            self.ui.peaksComboBox.setCurrentIndex(3)

        # connect signals
        self.ui.buttonBox.button(
            Qt.QDialogButtonBox.Close).clicked.connect(self.hide)
        self.ui.buttonBox.button(
            Qt.QDialogButtonBox.Apply).clicked.connect(self.apply)
        self.ui.xAutoGroupBox.toggled.connect(self.toggledAutoScale)
        self.ui.y1AutoGroupBox.toggled.connect(self.toggledAutoScale)
        self.ui.y2AutoGroupBox.toggled.connect(self.toggledAutoScale)
#        self.connect(self.ui.xEditMin,  Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.xEditMax,  Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.y1EditMin, Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.y1EditMax, Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.y2EditMin, Qt.SIGNAL("returnPressed()"),self.apply)
#        self.connect(self.ui.y2EditMax, Qt.SIGNAL("returnPressed()"),self.apply)
        self.ui.xModeComboBox.currentIndexChanged.connect(self.modeComboChanged)
        self.ui.xDynScaleCheckBox.toggled.connect(self.setXDynScale)
        #self.connect(self.ui.xRangeCB, Qt.SIGNAL("currentIndexChanged(const QString&)"),self.apply)
        self.ui.y1ModeComboBox.currentIndexChanged.connect(self.modeComboChanged)
        self.ui.y2ModeComboBox.currentIndexChanged.connect(self.modeComboChanged)
        self.ui.peaksComboBox.currentIndexChanged.connect(self.peaksComboChanged)
        # self.connect(self.curvesAppearanceChooser,
        # Qt.SIGNAL("controlChanged"),self.apply) #"autoapply" mode for *all*
        # the curve appearance controls
        self.curvesAppearanceChooser.assignToY1BT.clicked[()].connect(self.setCurvesYAxis)
        self.curvesAppearanceChooser.assignToY2BT.clicked[()].connect(self.setCurvesYAxis)
        self.curvesAppearanceChooser.bckgndBT.clicked.connect(self.changeBackgroundColor)
        self.curvesAppearanceChooser.changeTitlesBT.clicked.connect(self.onChangeTitles)
        self.curvesAppearanceChooser.CurveTitleEdited.connect(self.onCurveTitleEdited)

        # finally adjust size
        self.adjustSize()

    def _populateXAxisScales(self):
        xMin = self.parent.axisScaleDiv(Qwt5.QwtPlot.xBottom).lowerBound()
        xMax = self.parent.axisScaleDiv(Qwt5.QwtPlot.xBottom).upperBound()
        if self.parent.getXIsTime():
            self.ui.xEditMin.setText(time.strftime(
                '%Y/%m/%d %H:%M:%S', time.localtime(int(xMin))))
            self.ui.xEditMax.setText(time.strftime(
                '%Y/%m/%d %H:%M:%S', time.localtime(int(xMax))))
        else:
            self.ui.xEditMin.setText(str(xMin))
            self.ui.xEditMax.setText(str(xMax))

    def _populateYAxisScales(self, axis=None):
        if axis is None or axis == Qwt5.QwtPlot.yLeft:
            self.ui.y1EditMin.setText(
                str(self.parent.axisScaleDiv(Qwt5.QwtPlot.yLeft).lowerBound()))
            self.ui.y1EditMax.setText(
                str(self.parent.axisScaleDiv(Qwt5.QwtPlot.yLeft).upperBound()))
        if axis is None or axis == Qwt5.QwtPlot.yRight:
            self.ui.y2EditMin.setText(
                str(self.parent.axisScaleDiv(Qwt5.QwtPlot.yRight).lowerBound()))
            self.ui.y2EditMax.setText(
                str(self.parent.axisScaleDiv(Qwt5.QwtPlot.yRight).upperBound()))

    def deltatime2str(self, dt, fuzzy=False):
        '''converts a time diff in secs to a string.
        If fuzzy=True it returns an approx time diff in s, min, hours or days'''
        dt = float(dt)
        if not fuzzy:
            return "%g s" % dt
        if dt < 2:
            return "%3.3g s" % dt
        elif dt < 120:
            return "%g s" % round(dt, 0)
        elif dt < 7200:
            return "%g m" % round(dt / 60, 0)
        elif dt < 172800:
            return "%g h" % round(dt / 3600, 0)
        else:
            return "%g d" % round(dt / 86400, 0)

    def str2deltatime(self, strtime):
        '''Translates a time string to seconds
        examples of valid relative times are: "now", "NOW", "Now", "-1d", "3w", "- 3.6e3 s",...
        examples of non-valid relative times:, "now + 2h", "-5", "3H" (unit names are case-sensitive)
        '''
        strtime = str(strtime).strip()
        timeunits = {'s': 1, 'm': 60, 'h': 3600, 'd': 3600 *
                     24, 'w': 3600 * 24 * 7, 'y': 3600 * 24 * 365}
        if strtime.lower() == "now":
            return time.time()
        if strtime[-1] in timeunits.keys():
            try:
                return float(strtime[:-1]) * timeunits[strtime[-1]]
            except Exception, e:
                print '[str2deltatime] No format could be applied to "%s"' % strtime
                return None
        else: