Ejemplo n.º 1
0
class QTangoDeviceNameStatus(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.startLabel.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                      QtWidgets.QSizePolicy.Fixed)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.endLabel.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                    QtWidgets.QSizePolicy.Fixed)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.nameLabel.setAlignment(QtCore.Qt.AlignLeft
                                    | QtCore.Qt.AlignBottom)
        self.nameLabel.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                     QtWidgets.QSizePolicy.Fixed)

        layout = QtWidgets.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.startLabel)
        layout.addWidget(self.nameLabel)
        layout.addWidget(self.endLabel)

        self.setMaximumWidth(self.sizes.readAttributeWidth)
        self.setMinimumWidth(self.sizes.readAttributeWidth)
        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 setState(self, state):
        self.endLabel.setState(state)
        self.startLabel.setState(state)
        self.nameLabel.setState(state)
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
class QTangoDeviceStatus(QTangoAttributeBase):
    def __init__(self, sizes=None, colors=None, parent=None):
        QTangoAttributeBase.__init__(self, sizes, colors, parent)
        self.startLabel = None
        self.endLabel = None
        self.nameLabel = None
        self.stateLabel = None
        self.statusLabel = None
        self.setupLayout()

    def setupLayout(self):
        self.startLabel = QTangoStartLabel(self.sizes, self.attrColors)
        self.startLabel.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                      QtWidgets.QSizePolicy.Expanding)
        self.endLabel = QTangoEndLabel(self.sizes, self.attrColors)
        self.endLabel.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                    QtWidgets.QSizePolicy.Expanding)
        self.nameLabel = QTangoAttributeNameLabel(self.sizes, self.attrColors)
        self.nameLabel.setAlignment(QtCore.Qt.AlignLeft
                                    | QtCore.Qt.AlignBottom)
        self.nameLabel.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                     QtWidgets.QSizePolicy.Fixed)
        self.nameLabel.setText("Status")
        self.stateLabel = QTangoStateLabel(self.sizes, self.attrColors)
        self.stateLabel.setAlignment(QtCore.Qt.AlignLeft
                                     | QtCore.Qt.AlignBottom)
        self.stateLabel.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                      QtWidgets.QSizePolicy.Fixed)
        self.statusLabel = QTangoAttributeNameLabel(self.sizes,
                                                    self.attrColors)
        self.statusLabel.setAlignment(QtCore.Qt.AlignLeft
                                      | QtCore.Qt.AlignBottom)
        self.statusLabel.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                       QtWidgets.QSizePolicy.Expanding)
        self.statusLabel.setWordWrap(True)

        s = ''.join(
            ('QLabel {min-height: ', str(self.sizes.barHeight), 'px; \n',
             'background-color: ', self.attrColors.backgroundColor, '; \n',
             'color: ', self.current_attr_color, ';}'))
        self.statusLabel.setStyleSheet(s)
        font = self.font()
        font.setPointSize(int(self.sizes.barHeight * 0.3))
        font.setStyleStrategy(QtGui.QFont.PreferAntialias)
        self.statusLabel.setFont(font)

        spacer_item = QtWidgets.QSpacerItem(
            0, 0, QtWidgets.QSizePolicy.MinimumExpanding,
            QtWidgets.QSizePolicy.MinimumExpanding)

        layout = QtWidgets.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout_top = QtWidgets.QHBoxLayout()
        layout_top.setContentsMargins(0, 0, 0, 0)
        layout2 = QtWidgets.QVBoxLayout()
        layout2.setContentsMargins(0, 0, 0, 0)
        layout2.setSpacing(0)
        layout2.setContentsMargins(0, 0, 0, 3)

        layout.addWidget(self.startLabel)
        layout.addLayout(layout2)
        layout2.addLayout(layout_top)
        layout_top.addWidget(self.nameLabel)
        layout_top.addWidget(self.stateLabel)
        layout2.addSpacerItem(spacer_item)
        layout2.addWidget(self.statusLabel)
        layout.addWidget(self.endLabel)

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

    def statusText(self):
        return str(self.statusLabel.text())

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

    def setState(self, state):
        self.endLabel.setState(state)
        self.startLabel.setState(state)
        self.nameLabel.setState(state)
        self.stateLabel.setState(state)
        self.statusLabel.setState(state)

    def setStatus(self, state, status):
        self.setState(state)
        self.statusLabel.setText(status)
        self.update()