Ejemplo n.º 1
0
 def setTextColor(self, color):
     """set the text paint color"""
     if type(color) == tuple and len(color) == 3:
         color = QtGui.QColor(color[0], color[1], color[2])
     elif type(color) == int:
         color = QtGui.QColor(color, color, color)
     setattr(self, '__textColor', color)
Ejemplo n.º 2
0
    def is_valid(control_instance, *args, **kwargs):
        """ Method to check if the new control value is correct.

        If the new entered value is not correct, the backroung control color
        will be red.

        Parameters
        ----------
        control_instance: QWidget (mandatory)
            the control widget we want to validate

        Returns
        -------
        out: bool
            True if the control value is a file,
            False otherwise
        """
        # Get the current control palette
        control_palette = control_instance.path.palette()

        # Get the control current value
        control_value = control_instance.path.value()

        color = QtCore.Qt.white
        red = QtGui.QColor(255, 220, 220)
        yellow = QtGui.QColor(255, 255, 200)

        # If the control value contains a file, the control is valid and the
        # backgound color of the control is white
        is_valid = False
        if control_value is traits.Undefined:
            # Undefined is an exception: allow to reset it (File instances,
            # even mandatory, are initialized with Undefined value)
            is_valid = True
            if not control_instance.optional:
                color = red
        else:

            if os.path.isdir(control_value) \
                    or (control_instance.output and control_value != "") \
                    or (control_instance.trait.handler.exists is False
                        and control_value != ""):
                is_valid = True

            # If the control value is optional, the control is valid and the
            # backgound color of the control is yellow
            elif control_instance.optional is True and control_value == "":
                color = yellow
                is_valid = True

            # If the control value is empty, the control is not valid and the
            # backgound color of the control is red
            else:
                color = red

        # Set the new palette to the control instance
        control_palette.setColor(control_instance.path.backgroundRole(), color)
        control_instance.path.setPalette(control_palette)

        return is_valid
Ejemplo n.º 3
0
    def is_valid(control_instance, *args, **kwargs):
        """ Method to check if the new control value is correct.

        If the new entered value is not correct, the backroung control color
        will be red.

        Parameters
        ----------
        control_instance: QLineEdit (mandatory)
            the control widget we want to validate

        Returns
        -------
        out: bool
            True if the control value is valid,
            False otherwise
        """
        # Get the current control palette
        control_palette = control_instance.palette()

        # Get the control current value: format the float string
        # Valid float strings are: +1, -1, 1, 1.1
        control_text = control_instance.text()
        if type(control_text) not in (str, six.text_type):
            # old QString with PyQt API v1
            control_text = six.text_type(control_text)
        control_value = control_text.replace(".", "", 1)
        control_value = re.sub("^([-+])", "", control_value, count=1)

        red = QtGui.QColor(255, 220, 220)
        yellow = QtGui.QColor(255, 255, 200)

        # If the control value contains only digits, the control is valid and
        # the backgound color of the control is white
        is_valid = False
        if control_value.isdigit():
            control_palette.setColor(control_instance.backgroundRole(),
                                     QtCore.Qt.white)
            is_valid = True

        # If the control value is optional, the control is valid and the
        # backgound color of the control is yellow
        elif control_instance.optional is True and control_value == "":
            control_palette.setColor(control_instance.backgroundRole(), yellow)
            is_valid = True

        # If the control value is empty, the control is not valid and the
        # backgound color of the control is red
        else:
            control_palette.setColor(control_instance.backgroundRole(), red)

        # Set the new palette to the control instance
        control_instance.setPalette(control_palette)

        return is_valid
Ejemplo n.º 4
0
    def is_valid(control_instance, *args, **kwargs):
        """ Method to check if the new control value is correct.

        If the new entered value is not correct, the backroung control color
        will be red.

        Parameters
        ----------
        control_instance: QLineEdit (mandatory)
            the control widget we want to validate

        Returns
        -------
        out: bool
            True if the control value is valid,
            False otherwise
        """
        # Get the current control palette
        control_palette = control_instance.palette()

        # Get the control current value
        control_value = control_instance.value()

        color = QtCore.Qt.white
        red = QtGui.QColor(255, 220, 220)
        yellow = QtGui.QColor(255, 255, 200)

        # If the control value is not empty, the control is valid and the
        # backgound color of the control is white
        is_valid = False

        if control_value in ('', None, traits.Undefined):
            if control_instance.optional:
                # If the control value is optional, the control is valid and
                # the backgound color of the control is yellow
                color = yellow
                is_valid = True
            else:
                color = red
                if control_value != '':
                    # allow to reset value
                    is_valid = True

        else:
            is_valid = True

        # Set the new palette to the control instance
        control_palette.setColor(control_instance.backgroundRole(), color)
        control_instance.setPalette(control_palette)

        return is_valid
Ejemplo n.º 5
0
 def textColor(self):
     """text paint color"""
     return getattr(self, '__textColor', QtGui.QColor(125, 125, 125))