예제 #1
0
class QTangoReadAttributeBoolean(QTangoAttributeBase):
    def __init__(self, sizes=None, colors=None, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.setupLayout()

    def setupLayout(self):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.valueBoolean = QTangoBooleanLabel(self.sizes, self.attrColors)

        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(self.sizes.barWidth / 3)

        self.layoutGrid = QtWidgets.QGridLayout()
        self.layoutGrid.setContentsMargins(0, 0, 0, 0)
        self.layoutGrid.addWidget(
            self.nameLabel,
            0,
            0,
        )
        self.layoutGrid.addWidget(self.valueBoolean, 0, 1)
        self.layoutGrid.setHorizontalSpacing(self.sizes.barWidth / 4)
        self.layoutGrid.setVerticalSpacing(0)

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(self.layoutGrid)
        self.layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setMaximumHeight(self.sizes.barHeight)
        self.setMinimumHeight(self.sizes.barHeight)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def attributeName(self):
        return str(self.nameLabel.text())

    # @QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, a_name):
        self.nameLabel.setText(a_name)
        self.update()

    def setAttributeValue(self, value):
        if type(value) == pt.DeviceAttribute:
            self.startLabel.setQuality(value.quality)
            self.endLabel.setQuality(value.quality)
            if value.dim_x > 1:
                val = value.value[0]
            else:
                val = value.value
        else:
            val = value

        self.valueBoolean.setBooleanState(val)
        self.update()
예제 #2
0
class QTangoReadAttributeImage(QTangoAttributeBase):
    def __init__(self, sizes=None, colors=None, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.setupLayout()

    def setupLayout(self):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.imageWidget = QTangoImageBase(self.sizes, self.attrColors)

        self.layout = QtWidgets.QHBoxLayout(self)
        margin = int(self.sizes.barHeight / 10)
        self.layout.setContentsMargins(margin, margin, margin, margin)
        self.layout.setSpacing(self.sizes.barWidth / 3)

        self.layoutGrid = QtWidgets.QGridLayout()
        self.layoutGrid.setContentsMargins(0, 0, 0, 0)
        self.layoutGrid.addWidget(self.nameLabel, 0, 0)
        self.layoutGrid.addWidget(self.imageWidget, 1, 0, 1, 2)
        self.layoutGrid.setHorizontalSpacing(self.sizes.barWidth / 4)
        self.layoutGrid.setVerticalSpacing(0)

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(self.layoutGrid)
        self.layout.addWidget(self.endLabel)

        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setMinimumHeight(self.sizes.barHeight * 6)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def attributeName(self):
        return str(self.nameLabel.text())

    # @QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, a_name):
        self.nameLabel.setText(a_name)
        self.update()

    def setImage(self, image, auto_levels=False):
        if type(image) == pt.DeviceAttribute:
            im = image.value
            self.startLabel.setQuality(image.quality)
            self.endLabel.setQuality(image.quality)
            self.nameLabel.setQuality(image.quality)
        self.imageWidget.setImage(im, auto_levels)

    def fixedSize(self, fixed=True):
        if fixed is True:
            self.imageWidget.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
            self.setMaximumWidth(self.sizes.readAttributeWidth)
        else:
            self.imageWidget.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Expanding)
예제 #3
0
class QTangoWriteAttributeSlider4(QTangoAttributeSlider):
    def __init__(self, sizes=None, colors=None, parent=None):
        QTangoAttributeSlider.__init__(self, sizes, colors, parent)

    def setupLayout(self):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.unitLabel = QTangoAttributeUnitLabel(self.sizes, self.attrColors)
        sizesValue = copy.copy(self.sizes)
        sizesValue.barHeight *= 1.0
        self.valueSpinbox = QTangoReadAttributeSpinBox(sizesValue,
                                                       self.attrColors)
        s = str(self.valueSpinbox.styleSheet())
        if s != '':
            i0 = s.find('\nmax-width')
            i1 = s[i0:].find(':')
            i2 = s[i0:].find(';')
            sNew = ''.join((s[0:i0 + i1 + 1], ' ',
                            str(self.sizes.readAttributeWidth), s[i0 + i2:]))
            self.valueSpinbox.setStyleSheet(sNew)
        self.valueSpinbox.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                        QtWidgets.QSizePolicy.Minimum)

        self.valueSlider = QTangoHSliderBase2(self.sizes, self.attrColors)
        # 		self.writeValueSpinbox = QTangoWriteAttributeSpinBox2(sizesValue, self.attrColors)
        # 		self.writeValueSpinbox.editingFinished.connect(self.editingFinished)
        self.writeValueLineEdit = QTangoWriteAttributeLineEdit(
            self.sizes, self.attrColors)
        self.writeValueLineEdit.editingFinished.connect(self.updateWriteValue)
        self.writeValueLineEdit.setLayoutDirection(QtCore.Qt.RightToLeft)

        self.writeLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.writeLabel.current_attr_color = self.attrColors.backgroundColor
        self.writeLabel.setupLayout()

        self.vSpacer = QtWidgets.QSpacerItem(
            20, self.sizes.barHeight, QtWidgets.QSizePolicy.Minimum,
            QtWidgets.QSizePolicy.MinimumExpanding)

        self.layout = QtWidgets.QHBoxLayout(self)
        margin = int(self.sizes.barHeight / 10)
        self.layout.setContentsMargins(margin, margin, margin, margin)
        self.layout.setSpacing(self.sizes.barHeight / 3)

        layoutV = QtWidgets.QVBoxLayout()
        layoutH1 = QtWidgets.QHBoxLayout()
        layoutH1.addWidget(self.nameLabel)
        layoutH1.addWidget(self.valueSpinbox)
        layoutH2 = QtWidgets.QHBoxLayout()
        spacerItemH = QtWidgets.QSpacerItem(
            5, 5, QtWidgets.QSizePolicy.MinimumExpanding,
            QtWidgets.QSizePolicy.Minimum)
        layoutH2.addSpacerItem(spacerItemH)
        layoutH2.addWidget(self.writeLabel)
        layoutH2.addWidget(self.writeValueLineEdit)
        layoutV.addLayout(layoutH1)
        layoutV.addLayout(layoutH2)
        layoutV.addWidget(self.valueSlider)

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(layoutV)
        self.layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setMaximumHeight(self.sizes.barHeight * 4)
        self.setMinimumHeight(self.sizes.barHeight * 4)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def configureAttribute(self, attrInfo):
        QTangoReadAttributeSlider2.configureAttribute(self, attrInfo)
        self.valueSpinbox.setSuffix(''.join((' ', self.attrInfo.unit)))

    def setAttributeName(self, aName, aUnit=None):
        self.nameLabel.setText(aName)
        if aUnit is not None:
            self.valueSpinbox.setSuffix(
                QtCore.QString.fromUtf8(''.join((' ', aUnit))))
        self.update()

    def setAttributeValue(self, data):
        if type(data) == pt.DeviceAttribute:
            self.startLabel.setQuality(data.quality)
            self.endLabel.setQuality(data.quality)
            if data.value is not None:
                self.valueSlider.setValue(data.value)
                self.valueSpinbox.setValue(data.value)
                if self.writeValueInitialized is False:
                    print 'Initializing write value'
                    self.writeValueInitialized = True
                    self.setAttributeWriteValue(data.w_value)

                if data.w_value != self.writeValueLineEdit.value():
                    if self.writeLabel.current_attr_color != self.attrColors.secondaryColor0:
                        self.writeLabel.current_attr_color = self.attrColors.secondaryColor0
                        self.writeLabel.setupLayout()
                else:
                    if self.writeLabel.current_attr_color != self.attrColors.backgroundColor:
                        self.writeLabel.current_attr_color = self.attrColors.backgroundColor
                        self.writeLabel.setupLayout()
        else:
            self.valueSlider.setValue(data)
            self.valueSpinbox.setValue(data)
        self.update()

    def setAttributeWriteValue(self, value):
        self.writeValueLineEdit.setValue(value)
        self.valueSlider.setWriteValue(value)
        self.update()

    def setSliderLimits(self, min_limit, max_limit):
        self.valueSlider.setSliderLimits(min_limit, max_limit)

    def updateWriteValue(self):
        if self.writeValueLineEdit.validatorObject.validate(
                self.writeValueLineEdit.text(),
                0)[0] == QtGui.QValidator.Acceptable:
            self.valueSlider.setWriteValue(
                np.double(self.writeValueLineEdit.text()))
        self.update()
        print 'updating slider to ', self.writeValueLineEdit.text()

    def getWriteValue(self):
        return self.writeValueLineEdit.value()
예제 #4
0
class QTangoReadAttributeSliderCompact(QTangoAttributeBase):
    def __init__(self, sizes=None, colors=None, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.setupLayout()

    def setupLayout(self):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.unitLabel = QTangoAttributeUnitLabel(self.sizes, self.attrColors)
        self.valueSpinbox = QTangoReadAttributeSpinBox(self.sizes,
                                                       self.attrColors)
        self.valueSpinbox.setAlignment(QtCore.Qt.AlignRight)
        self.valueSlider = QTangoHSliderBaseCompact(self.sizes,
                                                    self.attrColors)

        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(self.sizes.barWidth / 3)

        self.layoutAttr = QtWidgets.QVBoxLayout()
        self.layoutAttr.setContentsMargins(0, 0, 0, 0)
        self.layoutAttr.setSpacing(0)
        self.layoutAttr.setContentsMargins(0, 0, 0, 0)
        self.layoutData = QtWidgets.QHBoxLayout()
        self.layoutData.setContentsMargins(0, 0, 0, 0)
        self.layoutData.setContentsMargins(0, 0, 0, 0)
        self.layoutData.addWidget(self.nameLabel)
        self.layoutData.addWidget(self.valueSpinbox)
        self.layoutAttr.addLayout(self.layoutData)
        self.layoutAttr.addWidget(self.valueSlider)

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(self.layoutAttr)
        self.layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setMaximumHeight(self.sizes.barHeight * 1.6)
        self.setMinimumHeight(self.sizes.barHeight * 1.6)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def attributeName(self):
        return str(self.nameLabel.text())

    #@QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, aName, aUnit=None):
        self.nameLabel.setText(aName)
        if aUnit is not None:
            self.unitLabel.setText(aUnit)
            self.valueSpinbox.setSuffix(''.join((' ', aUnit)))
        self.update()

    def setAttributeValue(self, value):
        if type(value) == pt.DeviceAttribute:
            self.startLabel.setQuality(value.quality)
            self.endLabel.setQuality(value.quality)
            self.nameLabel.setQuality(value.quality)
            if value.value is not None:
                val = value.value
                self.valueSpinbox.setValue(val)
                self.valueSlider.setValue(val)
        else:
            val = value
            self.valueSpinbox.setValue(val)
            self.valueSlider.setValue(val)
        self.update()

    def setAttributeWarningLimits(self, limits):
        self.valueSlider.setWarningLimits(limits)

    def setSliderLimits(self, min_limit, max_limit):
        self.valueSlider.setSliderLimits(min_limit, max_limit)

    def configureAttribute(self, attrInfo):
        QTangoAttributeBase.configureAttribute(self, attrInfo)
        try:
            min_warning = float(self.attrInfo.alarms.min_warning)
        except:
            min_warning = -np.inf
        try:
            max_warning = float(self.attrInfo.alarms.max_warning)
        except:
            max_warning = np.inf
        self.setAttributeWarningLimits((min_warning, max_warning))
        self.unitLabel.setText(self.attrInfo.unit)
        self.valueSpinbox.setSuffix(''.join((' ', self.attrInfo.unit)))
예제 #5
0
class QTangoReadAttributeSlider3(QTangoReadAttributeSlider2):
    def __init__(self, sizes=None, colors=None, parent=None):
        QTangoReadAttributeSlider2.__init__(self, sizes, colors, parent)

    def setupLayout(self):
        #		QTangoReadAttributeSlider2.setupLayout(self)
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.unitLabel = QTangoAttributeUnitLabel(self.sizes, self.attrColors)
        self.valueSpinbox = QTangoReadAttributeSpinBox(self.sizes,
                                                       self.attrColors)
        self.valueSlider = QTangoHSliderBase2(self.sizes, self.attrColors)
        self.writeLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.writeLabel.current_attr_color = self.attrColors.backgroundColor
        self.writeLabel.setupLayout()

        self.layout = QtWidgets.QHBoxLayout(self)
        margin = int(self.sizes.barHeight / 10)
        self.layout.setContentsMargins(margin, margin, margin, margin)
        self.layout.setSpacing(self.sizes.barHeight / 3)

        self.layoutGrid = QtWidgets.QGridLayout()
        self.layoutGrid.setContentsMargins(0, 0, 0, 0)
        self.layoutGrid.addWidget(self.nameLabel, 0, 0)
        self.layoutGrid.addWidget(self.unitLabel, 0, 1)
        self.layoutGrid.addWidget(self.valueSlider, 1, 0, 1, 2)
        # 		self.layoutGrid.addWidget(self.valueSpinbox, 0, 3)
        # 		self.layoutGrid.addWidget(self.writeLabel, 1, 2)

        self.layoutGrid.setHorizontalSpacing(self.sizes.barHeight / 4)
        self.layoutGrid.setVerticalSpacing(0)

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(self.layoutGrid)
        self.layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setMaximumHeight(self.sizes.barHeight * 2.2)
        self.setMinimumHeight(self.sizes.barHeight * 2.2)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)
        # 		self.layoutGrid.removeWidget(self.valueSpinbox)
        # 		self.valueSpinbox = None
        # 		self.layoutGrid.removeWidget(self.writeLabel)
        self.valueLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.layoutGrid.addWidget(self.valueLabel, 0, 3)

    def setAttributeValue(self, value):
        if type(value) == pt.DeviceAttribute:
            self.startLabel.setQuality(value.quality)
            self.endLabel.setQuality(value.quality)
            if value.value is not None:
                val = value.value
                self.valueLabel.setText(str(val))
                self.valueSlider.setValue(val)
        else:
            val = value
            self.valueLabel.setText(str(val))
            self.valueSlider.setValue(val)
        self.update()
예제 #6
0
class QTangoReadAttributeSlider(QTangoAttributeBase):
    def __init__(self, sizes=None, colors=None, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.setupLayout()

    def setupLayout(self):
        read_value_width = self.sizes.barWidth
        read_width = self.sizes.readAttributeWidth - self.sizes.barHeight / 6 - self.sizes.barHeight / 2

        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.valueSpinbox = QTangoReadAttributeSpinBox(self.sizes,
                                                       self.attrColors)
        self.valueSlider = QTangoHSliderBase(self.sizes, self.attrColors)

        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(self.sizes.barHeight / 3)

        self.layoutGrid = QtWidgets.QGridLayout()
        margin = int(self.sizes.barHeight / 10)
        self.layoutGrid.setContentsMargins(margin, margin, margin, margin)
        self.layoutGrid.setContentsMargins(0, 0, 0, 0)
        self.layoutGrid.addWidget(
            self.nameLabel,
            0,
            0,
        )
        self.layoutGrid.addWidget(self.valueSlider, 1, 0)
        self.layoutGrid.addWidget(self.valueSpinbox, 0, 1)
        self.layoutGrid.setHorizontalSpacing(self.sizes.barHeight / 4)
        self.layoutGrid.setVerticalSpacing(0)

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(self.layoutGrid)
        self.layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setMaximumHeight(self.sizes.barHeight * 2.2)
        self.setMinimumHeight(self.sizes.barHeight * 2.2)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def attributeName(self):
        return str(self.nameLabel.text())

    #@QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, aName):
        self.nameLabel.setText(aName)
        self.update()

    def setAttributeValue(self, value):
        if type(value) == pt.DeviceAttribute:
            self.startLabel.setQuality(value.quality)
            self.endLabel.setQuality(value.quality)
            if value.value is not None:
                val = value.value
                self.valueSpinbox.setValue(val)
                self.valueSlider.setValue(val)

        else:
            val = value
            self.valueSpinbox.setValue(val)
            self.valueSlider.setValue(val)
        self.update()

    def setAttributeWarningLimits(self, limits):
        self.valueSlider.setWarningLimits(limits)

    def setSliderLimits(self, min_limit, max_limit):
        self.valueSlider.setSliderLimits(min_limit, max_limit)
class QTangoReadAttributeSpectrum(QTangoAttributeBase):
    def __init__(self, sizes=None, colors=None, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.setupLayout()

    def setupLayout(self):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.spectrum = QTangoSpectrumBase(self.sizes, self.attrColors)

        self.layout = QtWidgets.QHBoxLayout(self)
        margin = int(self.sizes.barHeight / 10)
        self.layout.setContentsMargins(margin, margin, margin, margin)
        self.layout.setSpacing(self.sizes.barWidth / 3)

        self.layoutGrid = QtWidgets.QGridLayout()
        self.layoutGrid.setContentsMargins(0, 0, 0, 0)
        self.layoutGrid.addWidget(self.nameLabel, 0, 0)
        self.layoutGrid.addWidget(self.spectrum, 1, 0, 1, 2)
        self.layoutGrid.setHorizontalSpacing(self.sizes.barWidth / 4)
        self.layoutGrid.setVerticalSpacing(0)

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(self.layoutGrid)
        self.layout.addWidget(self.endLabel)

        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setMinimumHeight(self.sizes.barHeight * 6)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def attributeName(self):
        return str(self.nameLabel.text())

    # @QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, a_name):
        self.nameLabel.setText(a_name)
        self.update()

    def setSpectrum(self, xData, yData, index=0):
        if type(xData) == pt.DeviceAttribute:
            xData = xData.value
        if type(yData) == pt.DeviceAttribute:
            self.startLabel.setQuality(yData.quality)
            self.endLabel.setQuality(yData.quality)
            self.nameLabel.setQuality(yData.quality)
            yData = yData.value
        self.spectrum.setSpectrum(xData, yData, index)

    def setXRange(self, low, high):
        self.spectrum.setXRange(low, high)

    def fixedSize(self, fixed=True):
        if fixed is True:
            self.spectrum.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                        QtWidgets.QSizePolicy.Fixed)
            self.setMaximumWidth(self.sizes.readAttributeWidth)
        else:
            self.spectrum.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                        QtWidgets.QSizePolicy.Expanding)

    def configureAttribute(self, attr_info):
        logger.debug("Configuring attribute {0}".format(attr_info.name))
        QTangoAttributeBase.configureAttribute(self, attr_info)
        try:
            min_warning = float(self.attrInfo.alarms.min_warning)
        except ValueError:
            min_warning = -np.inf
        try:
            max_warning = float(self.attrInfo.alarms.max_warning)
        except ValueError:
            max_warning = np.inf
        logger.debug("min_warning {0}, max_warning {1}".format(
            min_warning, max_warning))
        self.setAttributeWarningLimits((min_warning, max_warning))

    def setAttributeWarningLimits(self, limits):
        self.spectrum.setWarningLimits(limits)
class QTangoReadAttributeTrend(QTangoAttributeBase):
    def __init__(self, name=None, sizes=None, colors=None, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.unit = None
        self.prefixDict = {
            'k': 1e3,
            'M': 1e6,
            'G': 1e9,
            'T': 1e12,
            'P': 1e15,
            'm': 1e-3,
            'u': 1e-6,
            'n': 1e-9,
            'p': 1e-12,
            'f': 1e-15,
            'c': 1e-2
        }
        self.prefix = None
        self.prefixFactor = 1.0

        self.curve_focus = 0
        self.setupLayout(name)

    def setupLayout(self, name=None):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.unitLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.curveNameLabel = QTangoAttributeNameLabel(self.sizes,
                                                       self.attrColors)
        if name is not None:
            self.curveNameLabel.setText(name)
        else:
            self.curveNameLabel.setText("curve 0")
        self.valueSpinbox = QTangoReadAttributeLabel(self.sizes,
                                                     self.attrColors)
        self.nameLabel.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                     QtWidgets.QSizePolicy.Fixed)
        self.valueSlider = QTangoVSliderBase2(self.sizes, self.attrColors)

        self.valueTrend = QTangoTrendBase(name=name,
                                          sizes=self.sizes,
                                          colors=self.attrColors)
        self.valueTrend.valueTrendCurves[-1].sigClicked.connect(
            self.setCurveFocus)

        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(self.sizes.barWidth / 3)

        layout2 = QtWidgets.QVBoxLayout()
        layout3 = QtWidgets.QHBoxLayout()
        layout2.addLayout(layout3)
        layout2.addWidget(self.valueTrend)
        layout3.addWidget(self.nameLabel)
        layout3.addWidget(self.curveNameLabel)
        layout3.addWidget(self.valueSpinbox)
        layout3.addWidget(self.unitLabel)

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(layout2)
        self.layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setMaximumHeight(self.sizes.barHeight * 4)
        self.setMinimumHeight(self.sizes.barHeight * 4)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def attributeName(self):
        return str(self.nameLabel.text())

    # @QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, a_name, a_unit=None):
        self.nameLabel.setText(a_name)
        if a_unit is not None:
            self.valueSlider.setUnit(a_unit)
            self.setUnit(a_unit)
        self.update()

    def setAttributeValue(self, value, curve=0):
        if type(value) == pt.DeviceAttribute:
            if value.value is not None:
                if curve == 0:
                    self.valueSlider.setValue(value)
                    self.valueSpinbox.setValue(value)
                self.valueTrend.addPoint(value, curve)
                self.nameLabel.setQuality(value.quality)
                self.unitLabel.setQuality(value.quality)
        else:
            t = time.time()
            self.valueTrend.addPoint([t, value], curve)
            if curve == 0:
                self.valueSlider.setValue(value)
                self.valueSpinbox.setValue(value)

        self.update()

    def addPoint(self, value, curve=0):
        if type(value) == pt.DeviceAttribute:
            if value.value is not None:
                value.value /= self.prefixFactor
                self.valueSlider.setValue(value)
                self.valueTrend.addPoint(value, curve)
                self.nameLabel.setQuality(value.quality)
                self.curveNameLabel.setQuality(value.quality)
                self.unitLabel.setQuality(value.quality)
                self.startLabel.setQuality(value.quality)
                self.endLabel.setQuality(value.quality)
                self.unitLabel.setQuality(value.quality)
                self.valueSpinbox.setQuality(value.quality)
        else:
            value /= self.prefixFactor
            self.valueSlider.setValue(value)
            t = time.time()
            self.valueTrend.addPoint([t, value], curve)
        if curve == self.curve_focus:
            self.valueSlider.setValue(value)
            self.valueSpinbox.setValue(value)
        self.update()

    def setUnit(self, unit):
        self.unit = unit
        if self.unit is not None:
            unit_str = self.unit
            if self.prefix is not None:
                unit_str = ''.join((self.prefix, unit_str))

            self.unitLabel.setText(unit_str)

    def setPrefix(self, prefix):
        try:
            self.prefixFactor = self.prefixDict[prefix]
            self.prefix = prefix
            self.setUnit(self.unit)
        except KeyError:
            self.prefix = None
            self.prefixFactor = 1.0

    def setAttributeWarningLimits(self, limits):
        self.valueSlider.setWarningLimits(limits)
        self.valueTrend.setWarningLimits(limits)

    def setSliderLimits(self, attr_min, attr_max):
        self.valueSlider.setSliderLimits(attr_min, attr_max)

    def setSliderRangeAnchor(self, anchor, slider_range, anchor_pos=0.75):
        """Set the slider total range. The anchor value is set at
        relative position anchorPos (0-1)
        """
        val_min = anchor - slider_range * anchor_pos
        val_max = anchor + slider_range * (1 - anchor_pos)
        self.valueSlider.setSliderLimits(val_min, val_max)

    def configureAttribute(self, attr_info):
        QTangoAttributeBase.configureAttribute(self, attr_info)
        try:
            min_warning = float(self.attrInfo.alarms.min_warning)
        except ValueError:
            min_warning = -np.inf
        try:
            max_warning = float(self.attrInfo.alarms.max_warning)
        except ValueError:
            max_warning = np.inf
        self.setAttributeWarningLimits((min_warning, max_warning))
        self.valueSlider.setUnit(self.attrInfo.unit)
        self.setUnit(self.attrInfo.unit)

    def setTrendLimits(self, low, high):
        self.valueTrend.setYRange(low, high, padding=0.05)

    def addCurve(self, name=None):
        self.valueTrend.addCurve(name)
        self.valueTrend.valueTrendCurves[-1].sigClicked.connect(
            self.setCurveFocus)

    def setCurveFocus(self, curve):
        name = curve.opts.get('name', None)
        if name is not None:
            self.curve_focus = self.valueTrend.curve_name_list.index(name)
            self.curveNameLabel.setText(name)

    def setCurveName(self, curve, name):
        self.valueTrend.setCurveName(curve, name)

    def showLegend(self, show_legend=True):
        self.valueTrend.showLegend(show_legend)

    def setDuration(self, duration):
        self.valueTrend.setDuration(duration)
class QTangoReadAttributeSlider(QTangoAttributeBase):
    """ Class for a composite read_attribute_slider.

    It consists of a start and end label with color coded state. The current value is shown and a slider
    with configurable limits.

    The slider style can be selected with the slider_style:
    1: QTangoHSliderBase
    2: QTangoHSliderBase2
    3: QTangoHSliderCompact

    If a unit is supplied with setAttributeName or configureAttribute it is displayed with the current value.

    The current write value is shown if show_write_value == True (not implemented)

    """
    def __init__(self,
                 sizes=None,
                 colors=None,
                 parent=None,
                 slider_style=2,
                 show_write_label=False):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.unit = None
        self.prefixDict = {
            'k': 1e3,
            'M': 1e6,
            'G': 1e9,
            'T': 1e12,
            'P': 1e15,
            'm': 1e-3,
            'u': 1e-6,
            'n': 1e-9,
            'p': 1e-12,
            'f': 1e-15,
            'c': 1e-2
        }
        self.prefix = None
        self.prefixFactor = 1.0

        self.setupLayout(slider_style, show_write_label)

    def setupLayout(self, slider_style=2, show_write_label=False):
        if slider_style in [1, 2, 3]:
            self.setup_horizontal(slider_style, show_write_label)
        else:
            self.setup_vertical(slider_style)

    def setup_vertical(self, slider_style=3):
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        sizes_value = copy.copy(self.sizes)
        sizes_value.barHeight *= 1.25

        self.valueSlider = QTangoVSliderBase2(self.sizes, self.attrColors)
        self.writeLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.writeLabel.current_attr_color = self.attrColors.backgroundColor
        self.writeLabel.setupLayout()

        self.unitLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)

        self.vSpacer = QtWidgets.QSpacerItem(
            20, self.sizes.barHeight, QtWidgets.QSizePolicy.Minimum,
            QtWidgets.QSizePolicy.MinimumExpanding)

        self.layout = QtWidgets.QVBoxLayout(self)
        margin = int(self.sizes.barHeight / 10)
        self.layout.setContentsMargins(margin, margin, margin, margin)
        self.layout.setSpacing(self.sizes.barHeight / 10)

        self.layout.addWidget(self.valueSlider)
        self.layout.addWidget(self.nameLabel)
        self.layout.addWidget(self.unitLabel)

        self.setMaximumWidth(self.sizes.barWidth * 4)
        self.setMinimumWidth(self.sizes.barWidth * 4)
        self.setMaximumHeight(self.sizes.readAttributeHeight)
        self.setMinimumHeight(self.sizes.readAttributeHeight)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def setup_horizontal(self, slider_style=2, show_write_label=False):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)

        # Create read_attribute_spinbox and modify max_width
        sizes_value = copy.copy(self.sizes)
        sizes_value.barHeight *= 1.25
        self.valueSpinbox = QTangoReadAttributeLabel(sizes_value,
                                                     self.attrColors)
        s = str(self.valueSpinbox.styleSheet())
        # if s != '':
        #     i0 = s.find('\nmax-width')
        #     i1 = s[i0:].find(':')
        #     i2 = s[i0:].find(';')
        #     s_new = ''.join((s[0:i0 + i1 + 1], ' ', str(self.sizes.readAttributeWidth), s[i0 + i2:]))
        #     self.valueSpinbox.setStyleSheet(s_new)
        self.valueSpinbox.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                        QtWidgets.QSizePolicy.Minimum)

        # Select slider style:
        if slider_style == 1:
            self.valueSlider = QTangoHSliderBase(self.sizes, self.attrColors)
        elif slider_style == 3:
            self.valueSlider = QTangoHSliderBaseCompact(
                self.sizes, self.attrColors)
        else:
            self.valueSlider = QTangoHSliderBase2(self.sizes, self.attrColors)

        # Create write_label if needed
        if show_write_label is True:
            self.writeLabel = QTangoStartLabel(self.sizes, self.attrColors)
            self.writeLabel.current_attr_color = self.attrColors.backgroundColor
            self.writeLabel.setupLayout()

        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(self.sizes.barWidth / 3)

        self.layoutGrid = QtWidgets.QGridLayout()
        self.layoutGrid.setContentsMargins(0, 0, 0, 0)
        self.layoutGrid.addWidget(self.nameLabel, 0, 0)
        self.layoutGrid.addWidget(self.valueSlider, 1, 0, 1, 2)
        self.layoutGrid.addWidget(self.valueSpinbox, 0, 3)
        if show_write_label is True:
            self.layoutGrid.addWidget(self.writeLabel, 1, 2)

        self.layoutGrid.addWidget(self.nameLabel, 0, 0, 1, 2)
        self.layoutGrid.addWidget(self.valueSpinbox, 1, 1)
        #        self.layoutGrid.addItem(self.vSpacer, 2, 0)
        self.layoutGrid.addWidget(self.valueSlider, 2, 0, 1, 2)

        self.layoutGrid.setHorizontalSpacing(self.sizes.barHeight / 4)
        # self.layoutGrid.setVerticalSpacing(0)

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(self.layoutGrid)
        self.layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setMaximumHeight(self.sizes.barHeight * 2.2)
        self.setMinimumHeight(self.sizes.barHeight * 2.2)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def attributeName(self):
        return str(self.nameLabel.text())

    # @QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, a_name, a_unit=None):
        self.nameLabel.setText(a_name)
        if a_unit is not None:
            self.valueSpinbox.setSuffix(
                QtCore.QString.fromUtf8(''.join((' ', a_unit))))
        self.update()

    def setAttributeValue(self, value):
        if type(value) == pt.DeviceAttribute:
            self.startLabel.setQuality(value.quality)
            self.endLabel.setQuality(value.quality)
            self.nameLabel.setQuality(value.quality)
            if value.value is not None:
                val = value.value
                self.valueSpinbox.setValue(val)
                self.valueSlider.setValue(value)
        else:
            val = value
            self.valueSpinbox.setValue(val)
            self.valueSlider.setValue(val)
        self.update()

    def setAttributeWarningLimits(self, limits):
        self.valueSlider.setWarningLimits(limits)

    def setSliderLimits(self, min_limit, max_limit):
        self.valueSlider.setSliderLimits(min_limit, max_limit)

    def configureAttribute(self, attr_info):
        QTangoAttributeBase.configureAttribute(self, attr_info)
        try:
            min_warning = float(self.attrInfo.alarms.min_warning)
        except ValueError:
            min_warning = -np.inf
        try:
            max_warning = float(self.attrInfo.alarms.max_warning)
        except ValueError:
            max_warning = np.inf
        self.setAttributeWarningLimits((min_warning, max_warning))
        self.valueSpinbox.setSuffix(''.join((' ', self.attrInfo.unit)))
class QTangoAttributeSlider(QTangoAttributeBase):
    def __init__(self,
                 sizes=None,
                 colors=None,
                 parent=None,
                 slider_style=2,
                 show_write_widget=False):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.newValueSignal = None

        self.nameLabel = None
        self.startLabel = None
        self.endLabel = None
        self.unitLabel = None
        self.valueLabel = None

        self.writeValueInitialized = False
        self.is_write_widget = show_write_widget

        self.unit = None
        self.prefixDict = {
            'k': 1e3,
            'M': 1e6,
            'G': 1e9,
            'T': 1e12,
            'P': 1e15,
            'm': 1e-3,
            'u': 1e-6,
            'n': 1e-9,
            'p': 1e-12,
            'f': 1e-15,
            'c': 1e-2
        }
        self.prefix = None
        self.prefixFactor = 1.0

        # self.setup_horizontal(1, False)
        self.setupLayout(slider_style, show_write_widget)

    def setupLayout(self, slider_style=2, show_write_widget=False):
        if slider_style in [1, 2, 3]:
            self.setup_horizontal(slider_style, show_write_widget)
        else:
            self.setup_vertical(slider_style)

    def setup_vertical(self, slider_style=4):
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        sizes_value = copy.copy(self.sizes)
        sizes_value.barHeight *= 1.25

        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.unitLabel = QTangoAttributeUnitLabel(self.sizes, self.attrColors)
        self.valueLabel = QTangoReadAttributeLabel(self.sizes, self.attrColors)

        self.valueSlider = QTangoVSliderBase2(self.sizes, self.attrColors)
        self.writeLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.writeLabel.current_attr_color = self.attrColors.backgroundColor
        self.writeLabel.setupLayout()

        # self.unitLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)

        self.vSpacer = QtWidgets.QSpacerItem(
            20, self.sizes.barHeight, QtWidgets.QSizePolicy.Minimum,
            QtWidgets.QSizePolicy.MinimumExpanding)

        self.layout = QtWidgets.QVBoxLayout(self)
        margin = int(self.sizes.barHeight / 10)
        self.layout.setContentsMargins(margin, margin, margin, margin)
        self.layout.setSpacing(self.sizes.barHeight / 10)

        self.layout.addWidget(self.valueSlider)
        self.layout.addWidget(self.nameLabel)
        self.layout.addWidget(self.unitLabel)

        self.setMaximumWidth(self.sizes.barWidth * 5)
        self.setMinimumWidth(self.sizes.barWidth * 5)
        self.setMaximumHeight(self.sizes.readAttributeHeight)
        self.setMinimumHeight(self.sizes.readAttributeHeight)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

    def setup_horizontal(self, slider_style=2, show_write_widget=False):
        logger.debug("QTangoAttributeSlider.setupLayout")
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.unitLabel = QTangoAttributeUnitLabel(self.sizes, self.attrColors)
        self.valueLabel = QTangoReadAttributeLabel(self.sizes, self.attrColors)
        if show_write_widget is True:
            logger.debug("Adding write widgets")
            self.writeValueEdit = QTangoWriteAttributeLineEdit(
                self.sizes, self.attrColors)
            self.writeValueEdit.newValueSignal.connect(self.updateWriteValue)
            self.writeLabel = QTangoStartLabel(self.sizes, self.attrColors)
            self.writeLabel.current_attr_color = self.attrColors.backgroundColor
            self.writeLabel.setupLayout()
            self.newValueSignal = self.writeValueEdit.newValueSignal

        # Select slider style:
        if slider_style == 1:
            self.valueSlider = QTangoHSliderBase(self.sizes, self.attrColors)
        elif slider_style == 3:
            self.valueSlider = QTangoHSliderBaseCompact(
                self.sizes, self.attrColors)
        else:
            self.valueSlider = QTangoHSliderBase2(self.sizes, self.attrColors)

        logger.debug("QTangoAttributeSlider.setupLayout widget")

        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(self.sizes.barWidth / 3)

        self.layoutGrid = QtWidgets.QGridLayout()
        self.layoutGrid.setContentsMargins(0, 0, 0, 0)
        self.layoutGrid.setHorizontalSpacing(self.sizes.barWidth / 4)
        self.layoutGrid.setVerticalSpacing(0)
        self.layoutGrid.addWidget(self.nameLabel, 0, 0)
        self.layoutGrid.addWidget(self.unitLabel, 0, 1)
        self.layoutGrid.addWidget(self.valueSlider, 1, 0, 1, 2)
        self.layoutGrid.addWidget(self.valueLabel, 0, 3, QtCore.Qt.AlignRight)
        if show_write_widget is True:
            self.layoutGrid.addWidget(self.writeLabel, 1, 2)
            self.layoutGrid.addWidget(self.writeValueEdit, 1, 3,
                                      QtCore.Qt.AlignRight)

        logger.debug("QTangoAttributeSlider.setupLayout: layoutGrid")

        self.layout.addWidget(self.startLabel)
        self.layout.addLayout(self.layoutGrid)
        self.layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth * 1.2)
        self.setMinimumWidth(self.sizes.readAttributeWidth * 1.2)
        self.setMaximumHeight(self.sizes.barHeight * 2.2)
        self.setMaximumHeight(self.sizes.barHeight * 3.0)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

        logger.debug("QTangoAttributeSlider.setupLayout: exit")

    def attributeName(self):
        return str(self.nameLabel.text())

    def setAttributeName(self, a_name, a_unit=None):
        self.nameLabel.setText(a_name)
        if a_unit is not None:
            self.setUnit(a_unit)
        logger.info("Setting name label to {0}".format(self.nameLabel.text()))
        self.update()

    def setUnit(self, unit):
        self.unit = codecs.raw_unicode_escape_decode(unit)[0]
        if self.unit is not None:
            if self.prefix is not None:
                unit_str = "{0}{1}".format(self.prefix, self.unit)
            else:
                unit_str = self.unit
            logger.info("Setting unit {0}".format(unit_str))
            self.unitLabel.setText(unit_str)

            try:
                self.valueSlider.setUnit(unit_str)
            except AttributeError:
                # Slider had no unit
                pass

    def setPrefix(self, prefix):
        try:
            self.prefixFactor = self.prefixDict[prefix]
            self.prefix = prefix
            self.valueLabel.setPrefix(prefix)
            self.valueSlider.setPrefix(prefix)
            self.setUnit(self.unit)
        except KeyError:
            self.prefix = None
            self.prefixFactor = 1.0

    def setAttributeValue(self, data):
        if type(data) == pt.DeviceAttribute:
            # logger.debug("QTangoAttributeSlider::setAttributeValue: quality {0}".format(data.quality))
            self.startLabel.setQuality(data.quality)
            self.endLabel.setQuality(data.quality)
            self.nameLabel.setQuality(data.quality)
            self.unitLabel.setQuality(data.quality)
            if data.value is not None:
                self.valueLabel.setValue(data)
                # logger.debug("QTangoAttributeSlider::setAttributeValue: setValue slider {0}".format(data.value))
                self.valueSlider.setValue(data)
                if self.is_write_widget is True:
                    if self.writeValueInitialized is False:
                        logger.info(
                            "QTangoAttributeSlider::setAttributeValue: Initializing write value"
                        )
                        self.writeValueInitialized = True
                        self.setAttributeWriteValue(data.w_value)

                    if data.w_value != self.writeValueEdit.value():
                        if self.writeLabel.current_attr_color != self.attrColors.secondaryColor0:
                            self.writeLabel.current_attr_color = self.attrColors.secondaryColor0
                            self.writeLabel.setupLayout()
                    else:
                        if self.writeLabel.current_attr_color != self.attrColors.backgroundColor:
                            self.writeLabel.current_attr_color = self.attrColors.backgroundColor
                            self.writeLabel.setupLayout()
        else:
            self.valueLabel.setValue(data)
            self.valueSlider.setValue(data)
        self.update()

    def setAttributeWriteValue(self, value):
        if self.is_write_widget is True:
            self.writeValueEdit.setValue(value)
            self.valueSlider.setWriteValue(value)
            self.update()

    def setAttributeWarningLimits(self, limits):
        self.valueSlider.setWarningLimits(limits)

    def setSliderLimits(self, min_limit, max_limit):
        self.valueSlider.setSliderLimits(min_limit, max_limit)

    def updateWriteValue(self):
        logger.debug("In QTangoAttributeSlider.updateWriteValue: "
                     "updating slider to {0}".format(
                         self.writeValueEdit.value()))
        self.valueSlider.setWriteValue(self.writeValueEdit.value())
        self.update()

    def getWriteValue(self):
        retval = None
        if self.is_write_widget:
            retval = self.writeValueEdit.value()
        return retval

    def configureAttribute(self, attr_info):
        logger.debug("Configuring attribute {0}".format(attr_info.name))
        QTangoAttributeBase.configureAttribute(self, attr_info)
        try:
            min_warning = float(self.attrInfo.alarms.min_warning)
        except ValueError:
            min_warning = -np.inf
        try:
            max_warning = float(self.attrInfo.alarms.max_warning)
        except ValueError:
            max_warning = np.inf
        logger.debug("min_warning {0}, max_warning {1}".format(
            min_warning, max_warning))
        self.setAttributeWarningLimits((min_warning, max_warning))
        logger.debug("unit {0}".format(self.attrInfo.unit))
        self.setUnit(self.attrInfo.unit)

        self.valueLabel.data_format = attr_info.format
        if self.is_write_widget is True:
            self.writeValueEdit.dataFormat = attr_info.format
예제 #11
0
class QTangoWriteAttributeDouble(QTangoAttributeBase):
    def __init__(self, sizes=None, colors=None, precision=4, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)

        self.writeValueInitialized = False
        self.unit = None
        self.precision = precision
        self.prefix = None

        self.setupLayout()

    def setupLayout(self):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.nameLabel.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                     QtWidgets.QSizePolicy.Minimum)
        self.unitLabel = QTangoAttributeUnitLabel(self.sizes, self.attrColors)
        self.valueSpinbox = QTangoReadAttributeLabel(self.sizes,
                                                     self.attrColors)
        self.writeValueLineEdit = QTangoWriteAttributeLineEdit(
            self.sizes, self.attrColors)
        self.writeValueLineEdit.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.writeLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.writeLabel.current_attr_color = self.attrColors.backgroundColor
        self.writeLabel.setupLayout()

        layout = QtWidgets.QHBoxLayout(self)
        margin = int(self.sizes.barHeight / 10)
        layout.setContentsMargins(margin, margin, margin, margin)

        layout_grid = QtWidgets.QGridLayout()
        margin = int(self.sizes.barHeight / 10)
        layout_grid.setContentsMargins(margin, margin, margin, margin)
        layout_grid.addWidget(self.nameLabel, 0, 0)
        layout_grid.addWidget(self.valueSpinbox, 0, 2)
        layout_grid.addWidget(self.unitLabel, 0, 3)
        layout_grid.addWidget(self.writeLabel, 1, 1)
        layout_grid.addWidget(self.writeValueLineEdit, 1, 2)

        layout.addWidget(self.startLabel)
        layout.addLayout(layout_grid)
        layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                           QtWidgets.QSizePolicy.Minimum)

    def attributeName(self):
        return str(self.nameLabel.text())

    # @QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, a_name, a_unit=None):
        self.nameLabel.setText(a_name)
        if a_unit is not None:
            self.setUnit(a_unit)
        self.update()

    def setUnit(self, unit):
        self.unit = unit
        if self.unit is not None:
            unit_str = self.unit
            if self.prefix is not None:
                unit_str = ''.join((self.prefix, unit_str))
            self.unitLabel.setText(unit_str)

    def setAttributeValue(self, value):
        if type(value) == pt.DeviceAttribute:
            if value.value is not None:
                if self.writeValueInitialized is False:
                    logger.debug('Initializing write value')
                    self.writeValueInitialized = True
                    self.setAttributeWriteValue(value.w_value)

                if value.w_value != self.writeValueLineEdit.value():
                    if self.writeLabel.current_attr_color != self.attrColors.secondaryColor0:
                        self.writeLabel.current_attr_color = self.attrColors.secondaryColor0
                        self.writeLabel.setupLayout()
                else:
                    if self.writeLabel.current_attr_color != self.attrColors.backgroundColor:
                        self.writeLabel.current_attr_color = self.attrColors.backgroundColor
                        self.writeLabel.setupLayout()
            self.startLabel.setQuality(value.quality)
            self.endLabel.setQuality(value.quality)
            self.unitLabel.setQuality(value.quality)
            self.valueSpinbox.setQuality(value.quality)
            self.nameLabel.setQuality(value.quality)

            val = value.value
        else:
            val = value

        self.valueSpinbox.setValue(val)
        self.update()

    def setAttributeWriteValue(self, value):
        self.writeValueLineEdit.setValue(value)
        self.update()

    def getWriteValue(self):
        return self.writeValueLineEdit.value()
예제 #12
0
class QTangoWriteAttributeComboBox(QtWidgets.QWidget):
    def __init__(self, sizes=None, colors=None, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.attrColors = QTangoColors()
        if colors is None:
            self.attrColors = QTangoColors()
        else:
            self.attrColors = colors
        if sizes is None:
            self.sizes = QTangoSizes()
        else:
            self.sizes = sizes

        self.writeValueInitialized = False
        self.unit = None

        self.setupLayout()

    def setupLayout(self):
        read_value_width = self.sizes.barWidth

        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.writeValueComboBox = QTangoComboBoxBase(self.sizes,
                                                     self.attrColors)

        layout = QtWidgets.QHBoxLayout(self)
        margin = int(self.sizes.barHeight / 10)
        layout.setContentsMargins(margin, margin, margin, margin)

        layout_grid = QtWidgets.QHBoxLayout()
        layout_grid.setContentsMargins(0, 0, 0, 0)
        margin = int(self.sizes.barHeight / 10)
        layout_grid.setContentsMargins(margin, margin, margin, margin)
        layout_grid.addWidget(self.nameLabel)
        layout_grid.addWidget(self.writeValueComboBox)

        layout.addWidget(self.startLabel)
        layout.addLayout(layout_grid)
        layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                           QtWidgets.QSizePolicy.Minimum)

        self.writeValueComboBox.activated[str].connect(self.onActivated)

    def attributeName(self):
        return str(self.nameLabel.text())

    # @QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, a_name, a_unit=None):
        self.nameLabel.setText(a_name)
        if a_unit is not None:
            self.unit = a_unit
        self.update()

    def setAttributeValue(self, value):
        if type(value) == pt.DeviceAttribute:
            if value.value is not None:
                if self.writeValueInitialized is False:
                    logger.info('Initializing write value')
                    self.writeValueInitialized = True
                    self.setAttributeWriteValue(value.w_value)

            self.startLabel.setQuality(value.quality)
            self.endLabel.setQuality(value.quality)
        self.update()

    def setAttributeWriteValue(self, value):
        self.writeValueComboBox.setValue(value)
        self.update()

    def getWriteValue(self):
        return self.writeValueComboBox.value()

    def addItem(self, item_text):
        self.writeValueComboBox.addItem(item_text)

    def setActivatedMethod(self, method):
        self.writeValueComboBox.activated[str].connect(method)

    def onActivated(self, text):
        logger.debug(text)
예제 #13
0
class QTangoCommandSelection(QTangoAttributeBase):
    def __init__(self, title, sizes=None, colors=None, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.cmdButtons = OrderedDict()
        self.title = title
        self.layout = None
        self.setupLayout()

    def setupLayout(self):
        # Init layouts once
        if self.layout is None:
            self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
            self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
            self.nameLabel = QTangoAttributeNameLabel(self.sizes,
                                                      self.attrColors)
            self.nameLabel.setText(self.title)
            self.nameLabel.setAlignment(QtCore.Qt.AlignLeft
                                        | QtCore.Qt.AlignVCenter)
            self.nameLabel.setMinimumWidth(0)
            self.statusLabel = QTangoAttributeNameLabel(
                self.sizes, self.attrColors)
            self.statusLabel.setSizePolicy(
                QtWidgets.QSizePolicy.MinimumExpanding,
                QtWidgets.QSizePolicy.Fixed)
            self.statusLabel.setAlignment(QtCore.Qt.AlignRight
                                          | QtCore.Qt.AlignVCenter)
            self.statusLabel.setText('')

            self.layout = QtWidgets.QHBoxLayout(self)
            self.layout.setContentsMargins(0, 0, 0, 0)
            self.layout.setContentsMargins(0, 0, 0, 0)
            self.layout.setSpacing(self.sizes.barWidth / 3)

            self.layout2 = QtWidgets.QVBoxLayout()
            self.layout2.setContentsMargins(0, 0, 0, 0)
            self.layout2.setContentsMargins(0, 0, 0, 0)

            self.layoutInfo = QtWidgets.QHBoxLayout()
            self.layoutInfo.setContentsMargins(0, 0, 0, 0)
            self.layoutInfo.setContentsMargins(0, 0, 0, 0)
            self.layoutInfo.setSpacing(int(self.sizes.barWidth / 6))
            self.layoutInfo.addWidget(self.nameLabel)
            self.layoutInfo.addWidget(self.statusLabel)
            self.layoutButtons = QtWidgets.QHBoxLayout()
            self.layoutButtons.setContentsMargins(0, 0, 0, 0)
            self.layoutButtons.setContentsMargins(0, 0, 0, 0)
            self.layoutButtons.setSpacing(int(self.sizes.barHeight / 3))
            self.layout2.addLayout(self.layoutInfo)
            self.layout2.addLayout(self.layoutButtons)

            self.layout.addWidget(self.startLabel)
            self.layout.addLayout(self.layout2)
            self.layout.addWidget(self.endLabel)

        # Clear out old layout
        if self.cmdButtons.keys().__len__() > 0:
            for i in reversed(range(self.layoutButtons.count())):
                self.layoutButtons.itemAt(i).widget().setParent(None)

            # Add buttons
        for cmdButton in self.cmdButtons.itervalues():
            self.layoutButtons.addWidget(cmdButton)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                           QtWidgets.QSizePolicy.Fixed)

        self.update()

    def setStatus(self, status, state=None):
        if type(status) == pt.DeviceAttribute:
            self.startLabel.setQuality(status.quality)
            self.endLabel.setQuality(status.quality)
            self.nameLabel.setQuality(status.quality)
            self.statusLabel.setQuality(status.quality)
            for cmdButton in self.cmdButtons.itervalues():
                cmdButton.setQuality(status.quality)
            status_text = str(status.value)
        else:
            status_text = status
        if status_text is not None:
            self.statusLabel.setText(status_text)
        else:
            self.statusLabel.setText('--')
        self.statusLabel.repaint()

    def addCmdButton(self, name, slot):
        cmd_button = QTangoCommandButton(name, slot, self.sizes,
                                         self.attrColors)
        self.cmdButtons[name] = cmd_button

        self.setupLayout()
예제 #14
0
class QTangoReadAttributeDouble(QTangoAttributeBase):
    def __init__(self, sizes=None, colors=None, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.unit = None
        self.prefixDict = {
            'k': 1e-3,
            'M': 1e-6,
            'G': 1e-9,
            'T': 1e-12,
            'P': 1e-15,
            'm': 1e3,
            'u': 1e6,
            'n': 1e9,
            'p': 1e12,
            'f': 1e15,
            'c': 1e2
        }
        self.prefix = None
        self.prefixFactor = 1.0
        self.setupLayout()

    def setupLayout(self):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.nameLabel.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                     QtWidgets.QSizePolicy.Minimum)
        self.unitLabel = QTangoAttributeUnitLabel(self.sizes, self.attrColors)
        self.valueSpinbox = QTangoReadAttributeLabel(self.sizes,
                                                     self.attrColors)
        self.unitLabel.setAlignment(QtCore.Qt.AlignLeft
                                    | QtCore.Qt.AlignBottom)

        layout = QtWidgets.QHBoxLayout(self)
        margin = int(self.sizes.barHeight / 10)
        layout.setContentsMargins(margin, margin, margin, margin)

        layout.addWidget(self.startLabel)
        layout.addWidget(self.nameLabel)
        layout.addWidget(self.valueSpinbox)
        layout.addWidget(self.unitLabel)
        layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        self.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                           QtWidgets.QSizePolicy.Minimum)

    def attributeName(self):
        return str(self.nameLabel.text())

    # @QtCore.pyqtSignature('setAttributeName(QString)')
    def setAttributeName(self, a_name, a_unit=None):
        self.nameLabel.setText(a_name)
        if a_unit is not None:
            self.setUnit(a_unit)
        self.update()

    def setAttributeValue(self, value):
        if type(value) == pt.DeviceAttribute:
            self.startLabel.setQuality(value.quality)
            self.endLabel.setQuality(value.quality)
            self.unitLabel.setQuality(value.quality)
            self.valueSpinbox.setQuality(value.quality)
            self.nameLabel.setQuality(value.quality)
            val = value.value
        else:
            val = value
        self.valueSpinbox.setValue(val * self.prefixFactor)
        self.update()

    def setUnit(self, unit):
        self.unit = unit
        if self.unit is not None:
            unit_str = self.unit
            if self.prefix is not None:
                unit_str = ''.join((self.prefix, unit_str))

            self.unitLabel.setText(unit_str)

    def setPrefix(self, prefix):
        try:
            self.prefixFactor = self.prefixDict[prefix]
            self.prefix = prefix
            self.setUnit(self.unit)
        except KeyError:
            self.prefix = None
            self.prefixFactor = 1.0