How validation works

The validation of inputs are made in two steps:

  1. Validation through the ScientificInputValidator validator

  2. Validation through the ScientificSpinBox.validate function

If the input passes on the first validation, it has the state Acceptable, meaning it has an acceptable text format and can go on to the second validation. If the first validation step gives a Intermmediate state, then the text still needs to be edited to pass into the first validation.

After that, it needs to pass into some heuristics in the ScientificSpinBox.validate that will handle specific requirements, like dimensionality of units.

If the input doesn’t pass on the second validation, it will have an Intermmediate state, which means it still can be edited and corrected.

A more detailed review of each step of validation is given below on each step specific section.

Step 1: ScientificInputValidator validation

This validator will verify if the input matches the following regular expression:

regex = r"^(?<full>(?<sci_repr>^(?<num_repr>(?<num_sgn>[+-])?(?<int_num>[0-9]+)?(?<dec_repr>(?<dec_sep>[.,])?(?<dec_num>[0-9]+))?)(?<exp_repr>[eE](?<exp_num>(?<exp_sgn>[+-])[0-9]+))?)(?<txt_repr> *(?<txt_unit>\µ?\Ω?\º?[a-zA-Z0-9?\/*\**\(*\)*]+))?)$"

The regular expression can be visualized in the diagram below, which shows all capture groups and their patterns:

diagram showing the capturing groups for the regular expression

Diagram showing the capturing groups for the regular expression.

This regular expression ensures that the given input is in the format:

[signal][integer][decimal separator][decimal][exponent][text]

Some valid examples are:

-12345.6789E-934abcdefgh
+12.34E+56a
12.34E+56
-0123456789.0123456789E+0123456789 µΩº/aBCde/FG***HI*Jkl*m*/no
.1
,2
.2e-9
e-9m/s
12345
12345 m/(s**2)
m/s

Some invalid examples are:

-1.234E-9 ab     cd
-1.234E-9 m/(s**   m)
ab c
1.5E6 m
1abc.3
1.5abcde4.3

To make it easier to extract certain parts of the input, the ScientificInputValidator provides some methods:

Method

Arg

Returned group

Meaning

getNumerical

text

sci_repr

All of the numeric part

getIntegers

text

int_num

Only the integer part

getDecimals

text

dec_num

Only the decimal numbers

getExponential

text

exp_num

Only the exponent

getText

text

txt_unit

Only the unit text

getSignal

text

num_sgn

The signal of the numeric part

Step 2: ScientificSpinBox.validate validation

After passing through the basic input validation from ScientificInputValidato, the input needs to be validaded by the ScientificSpinBox.validate.

This function will verify if the unit field, txt_unit represents a valid unit, that is not empty and that is compatible with the baseUnit of the widget. It will also trigger error events if the input doesn’t satisfy the validation, showing a tooltip for the user if this feature is enabled.

The behaviour of validate is shown in details in the flowchart below:

flowchart showing the behaviour of the ScientificSpinBox validate function.

Flowchart showing the behaviour of the ScientificSpinBox validate function.