scientific_spinbox.backend.interfaces¶
- class BackendInterface(unit_system: str, precision: int)[source]¶
Bases:
ABCAbstract interface between the unit-handling backend and the ScientificSpinbox
Requires the implementation of methods for handling quantities, units and their representations in numeric and text forms.
- Parameters:¶
- abstract changeQuantityUnit(quantity, new_unit, formatter) object[source]¶
Returns a new quantity object with the new unit.
Takes in a quantity object with numeric and unit parts, and returns a new quantity object with the numeric and unit parts converted to the new unit.
- abstract getQuantityUnitStr(quantity) str[source]¶
Returns the text representation of the unit part of a quantity object.
- abstract getQuantityValueNumeric(quantity) Decimal[source]¶
Returns the numeric part of a quantity object.
- abstract getQuantityValueStr(quantity) str[source]¶
Returns the numeric part of a quantity object converted to string.
- abstract isArrayOfSameDimension(array) bool[source]¶
Verifies if an array of units are all of the same dimension.
- abstract isQuantitiesUnitsEqual(q1, q2) bool[source]¶
Verifies if the units of two quantities have the same text representations.
- abstract isQuantityCompatibleWithUnit(quantity, unit) bool[source]¶
Verifies if a quantity is compatible with an unit.
- abstract isUnitRegistered(unit) bool[source]¶
Verifies if a unit is registered in the Unit Registry.
- abstract quantityFromText(text: str, unit: str) object[source]¶
Creates a new quantity object based on the text representation.
- abstract quantityTextRepr(quantity, unit_separator: str, normalize: bool, formatter) str[source]¶
Returns the text representation of a quantity object.
- abstract unitFromText(text: str) object[source]¶
Creates a new Unit object based on its text representation.
-
class PintInterface(unit_system: str =
'SI', precision=30)[source]¶ Bases:
BackendInterfaceInterface between pint and ScientificSpinbox
Implements required methods for creating quantities, verifying units and converting units.
- Parameters:¶
- QuantityType¶
alias of
PlainQuantity
-
changeQuantityUnit(quantity: PlainQuantity, new_unit: str | Unit, formatter=
None) PlainQuantity[source]¶ Returns a new quantity object with the new unit.
Takes in a quantity object with numeric and unit parts, and returns a new quantity object with the numeric and unit parts converted to the new unit.
- getQuantityUnit(quantity: PlainQuantity) Unit | PlainUnit[source]¶
Returns the unit object of a quantity.
- getQuantityUnitStr(quantity: PlainQuantity) str[source]¶
Returns the text representation of the unit part of a quantity object.
- getQuantityValueNumeric(quantity: PlainQuantity) Decimal[source]¶
Returns the numeric part of a quantity object as Decimal.
- getQuantityValueStr(quantity: PlainQuantity) str[source]¶
Returns the numeric part of a quantity object converted to string.
- isArrayOfSameDimension(array: list[str]) bool[source]¶
Verifies if an array of units are all of the same dimension.
- isQuantitiesCompatible(q1: PlainQuantity, q2: PlainQuantity) bool[source]¶
Verifies if two quantities are compatible.
- isQuantitiesUnitsEqual(q1, q2) bool[source]¶
Verifies if the units of two quantities have the same text representations.
- isQuantityCompatibleWithUnit(quantity: PlainQuantity, unit: Unit | str) bool[source]¶
Verifies if a quantity is compatible with an unit.
- quantityFromDecimal(value: Decimal, unit: str)[source]¶
Creates a new quantity object based on the numeric representation.
- quantityFromText(text: str, unit: str) PlainQuantity[source]¶
Creates a new quantity object based on the text representation.
- quantityTextRepr(quantity: ~pint.facets.plain.quantity.PlainQuantity, unit_separator: str, normalize: bool = False, formatter=<function PintInterface.<lambda>>) str[source]¶
Returns the text representation of a quantity object.
- property decimalsContext¶
Context to be used in Decimal library.