scientific_spinbox.validators

Validators module.

Provides the text validators and text processing utilities to be used within a ScientificSpinBox.

Since:

2024/02/06

Authors:
class ScientificCapturedGroups(text: str, validator: ScientificInputValidator)[source]

Bases: object

Class that represents captured groups for a given text.

Implements methods to access each group with ease.

Parameters:
text : str

text to fill the capture groups.

validator : ScientificInputValidator

validator object reference.

property decimalNumbers : str | None

Numbers of the decimal part.

property decimalRepresentation : str | None

Decimal part, including separator and numbers.

property decimalSeparator : str | None

Decimal separator.

property exponentialNumber : str | None

Number after the exponential sign, including signal.

property exponentialRepresentation : str | None

Exponential part, including exponential sign, number and signal.

property exponentialSignal : str | None

Signal of the exponential.

property fullText : str | None

Full captured text.

property integerNumbers : str | None

Integer part, not including signal.

property numericRepresentation : str | None

Numeric representation, without exponential.

Can contain:
  • numeric signal

  • integer numbers

  • decimal separator

  • decimal numbers

Doesn’t contain:
  • exponential symbol

  • exponential signal

  • exponential numbers

  • unit text

property numericSignal : str | None

Signal of the numeric part.

property scientificRepresentation : str | None

Scientific representation, without unit text.

Can contain:
  • numeric signal

  • integer numbers

  • decimal separator

  • decimal numbers

  • exponential symbol

  • exponential signal

  • exponential numbers.

Doesn’t contain:
  • unit text

property unitRepresentation : str | None

Unit part, with the preceding spaces.

property unitText : str | None

Text of the unit part, without the preceding spaces.

class ScientificInputValidator(parent=None)[source]

Bases: QRegularExpressionValidator

Input validator for a ScientificSpinBox.

Verifies if the provided input is a valid scientific number with or without units based on a regular expression.

Implements methods for manipulating captured groups to extract parts from the scientific input.

Parameters:
parent : object

parent Qt object

fixup(a0)[source]

Reimplements the fixup method from the parent class.

On the current implementation, it just returns the result from the parent class method.

Parameters:
text : str

text to fixup.

Returns:

fixed up text.

Return type:

str

getAllCaptured(text)[source]

Returns a dictionary with all the capture groups and the corresponding text captured by each group.

Parameters:
text : str

text to fill the capture groups.

getCapturedGroups(text)[source]

Returns a ScientificCapturedGroups object for the given text.

Parameters:
text : str

text to fill the capture groups.

Returns:

object with the captured groups.

Return type:

ScientificCapturedGroups

getRegExpGroupIdx(group_name: str)[source]

Gets the index of a named capture group based on its name.

Parameters:
group_name : str

name of the group to get index.

Returns:

index of the group.

Return type:

int

Raises:

Exception – if the group doesn’t exist on the regex.

interpretText(text)[source]

Replaces commas with dots on the text.

Parameters:
text : str

text to replace commas.

Returns:

text with only dots.

Return type:

str

stateToStr(state: State)[source]

Transforms a QValidator state into a string.

Parameters:
state : QtGui.QValidator.State

QValidator state.

Raises:

InvalidValidatorStateError – if the provided state is not one of the known QValidator states (Acceptable, Invalid, Intermediate).

Returns:

string representation of the QValidator state.

Can be Acceptable, Invalid or Intermediate.

Return type:

str

validate(text, position)[source]

Reimplements the validate method from the parent class.

On the current implementation, it just returns the result from the parent class method.

Parameters:
text : str

text to validate.

position : int

position of the cursor before validation.

Returns:

state of the validator. text (str): text after the validation. position (int): position of the cursor after validation.

Return type:

state (QtGui.QValidator.State)

property regExpCaptureGroups

Returns the named capture groups from the regex.

Returns:

list of named capture groups.

Return type:

list