Skip to content

ScientificIntegerValidator

Qt Base Class: QValidator

Signature: QValidator(self, parent: Optional[PySide6.QtCore.QObject] = None) -> None

Base classes

Name Children Inherits
BaseScientificValidator
prettyqt.validators.scientificvalidators

⋔ Inheritance diagram

graph TD
  1473367011104["validators.ScientificIntegerValidator"]
  1473367015984["validators.BaseScientificValidator"]
  1473245568976["gui.Validator"]
  1473245536768["gui.ValidatorMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289208592["QtGui.QValidator"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473367015984 --> 1473367011104
  1473245568976 --> 1473367015984
  1473245536768 --> 1473245568976
  1473299815024 --> 1473245536768
  140713234304496 --> 1473299815024
  1473289208592 --> 1473245568976
  1473288842240 --> 1473289208592
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: BaseScientificValidator

This is a validator for int values represented as strings in scientific notation.

Using engineering notation only positive exponents are allowed (i.e. "1e9", "2E+8", "14e+3" etc.) Also supports non-fractional SI unit prefix like 'M', 'k' etc.

Source code in prettyqt\validators\scientificvalidators.py
class ScientificIntegerValidator(BaseScientificValidator):
    """This is a validator for int values represented as strings in scientific notation.

    Using engineering notation only positive exponents are allowed
    (i.e. "1e9", "2E+8", "14e+3" etc.)
    Also supports non-fractional SI unit prefix like 'M', 'k' etc.
    """

    ID = "scientific_integer"

    re_pattern = re.compile(
        r"(([+-]?\d+)([eE]\+?\d+)?\s?([YZEPTGMk])?\s*)", flags=re.UNICODE
    )
    group_map = {"match": 0, "mantissa": 1, "exponent": 2, "si": 3}

    def validate(self, string, position):
        if not string.strip() or string.strip() in list("YZEPTGMk"):
            return self.State.Intermediate, string, position

        if not (group_dict := self.get_group_dict(string)):
            return self.State.Invalid, "", position
        if group_dict["match"] == string:
            return self.State.Acceptable, string, position

        position = min(position, len(string))
        if string[position - 1] in "eE-+":
            return self.State.Intermediate, string, position

        return self.State.Invalid, group_dict["match"], position

⌗ Property table

Qt Property Type Doc
objectName QString

Validator ID: scientific_integer