Exemple #1
0
    def __init__(self, parent: QListWidget, id_no: int, text: str):
        """
        A custom widget used for acting as a template in the pixel mapping list. Consists of a label and an input box.
        :param parent: The QListWidget that will contain this list item.
        :param id_no: The "temporary" ID number based on the number of faces in the mesh/number of cylinders. Used
        to distinguish elements in the list but doesn't define the actual IDs that are saved upon clicking Add Component.
        :param text: The text that appears in the list widget. Will be either "cylinder" or "face."
        """
        super().__init__(parent)
        self.pixelIDLabel = QLabel()
        self.pixelIDLineEdit = QLineEdit()

        # Create the label text based on the face number
        self.pixelIDLabel.setText("Pixel ID for " + text + " #" + str(id_no) +
                                  ":")

        # Give the line edit a validator that requires values of zero or greater
        self.pixelIDLineEdit.setValidator(NullableIntValidator(bottom=0))

        self.layout = QHBoxLayout()
        self.layout.addWidget(self.pixelIDLabel)
        self.layout.addWidget(self.pixelIDLineEdit)

        self.setLayout(self.layout)
def test_GIVEN_integer_WHEN_using_nullable_int_validator_THEN_returns_acceptable():

    validator = NullableIntValidator()
    assert validator.validate("5", 0)[0] == QValidator.State.Acceptable
def test_GIVEN_nonemptry_string_WHEN_using_nullable_int_validator_THEN_returns_invalid(
    invalid_input,
):

    validator = NullableIntValidator()
    assert validator.validate(invalid_input, 0)[0] == QValidator.State.Invalid
def test_GIVEN_empty_string_WHEN_using_nullable_int_validator_THEN_returns_acceptable():

    validator = NullableIntValidator()
    assert validator.validate("", 0) == QValidator.Acceptable