Exemplo n.º 1
0
    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 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")
Exemplo n.º 3
0
    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 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)
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
Exemplo n.º 6
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()
Exemplo n.º 7
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