Exemplo n.º 1
0
    def __init__(self, parameter, parent=None):
        _ParameterWidget.__init__(self, parameter, parent=parent)

        # Widgets
        self._cb_time = TimeComboBox()

        self._txt_values = MultiNumericalLineEdit()
        validator = _FactorParameterValidator(parameter, self._cb_time)
        self._txt_values.setValidator(validator)

        # Layouts
        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._txt_values, 1)
        layout.addWidget(self._cb_time)
        self.setLayout(layout)

        # Signals
        self.valuesChanged.connect(self._onChanged)
        self.validationRequested.connect(self._onChanged)

        self._txt_values.textChanged.connect(self.valuesChanged)
        self._cb_time.currentIndexChanged.connect(self.valuesChanged)

        self.validationRequested.emit()
Exemplo n.º 2
0
class TimeParameterWidget(_ParameterWidget):

    def __init__(self, parameter, parent=None):
        _ParameterWidget.__init__(self, parameter, parent=parent)

        # Widgets
        self._cb_time = TimeComboBox()

        self._txt_values = MultiNumericalLineEdit()
        validator = _FactorParameterValidator(parameter, self._cb_time)
        self._txt_values.setValidator(validator)

        # Layouts
        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._txt_values, 1)
        layout.addWidget(self._cb_time)
        self.setLayout(layout)

        # Signals
        self.valuesChanged.connect(self._onChanged)
        self.validationRequested.connect(self._onChanged)

        self._txt_values.textChanged.connect(self.valuesChanged)
        self._cb_time.currentIndexChanged.connect(self.valuesChanged)

        self.validationRequested.emit()

    def _onChanged(self):
        if self.hasAcceptableInput():
            self._txt_values.setStyleSheet("background: none")
        else:
            self._txt_values.setStyleSheet("background: pink")

    def values(self):
        return self._txt_values.values() * self._cb_time.factor()

    def setValues(self, values):
        self._txt_values.setValues(values)
        self._cb_time.setScale('s')

    def isReadOnly(self):
        return self._txt_values.isReadOnly() and not self._cb_time.isEnabled()

    def setReadOnly(self, state):
        self._txt_values.setReadOnly(state)
        self._cb_time.setEnabled(not state)

    def hasAcceptableInput(self):
        if not _ParameterWidget.hasAcceptableInput(self):
            return False
        return self._txt_values.hasAcceptableInput()