Various interoperable units classes and some related helper functions.
Recursively convert all numbers found in an iterable to a unit in place.
(Iterable): The iterable to recursively convert
(type): The unit to convert numerical elements to
This function works in place. Immutable structures (namely tuples) found
iterable will be replaced.
iterable itself may not be immutable.
In dictionaries, only values will be converted. Keys will be left as-is.
An immutable graphical distance with a unit.
Unit objects enable easy conversion from one unit to another and convenient operations between them.
Common operators (
/, etc.) are supported between them.
Return values from these operations are given in the type on the left.
Unit(or subclass) is to the left of an
float, the value on the right will be converted to the left object's type before performing the operation. The resulting value will be a new object of the left-side object's type.
floatare on the left hand side of any operator except
//, a TypeError will be raised.
>>> print(2 * Inch(1)) Inch(2) >>> print(1 + Inch(1)) Traceback (most recent call last): ... TypeError: unsupported operand type(s) for +: 'int' and 'Inch'
Unitobjects are immutable. Any attempts to modify them in place will result in much sadness.
Return this value as a float in base unit values.
Assert the near-equality of two units.
A helpful failure message is given in the event of failure.
This is primarily for testing purposes, as the stdlib
assertAlmostEqual doesn't play nice with custom numeric types.
Args: other (Unit): The unit to compare against places (int): The number of decimal places of accuracy required.
Raises: AssertionError: If failed.
— the ratio of this class to
Subclasses should override this.
A unit with a 1:1 ratio with Qt units.
This will typically be the size of a pixel in
brown.show() preview mode.
In most cases, you probably want to use a more descriptive unit type.