pyaccesskit.units¶
pyaccesskit.units ¶
Physical lengths for form and report layout.
Access measures positions and sizes in twips (1/1440 inch, 1/20 point). PyAccessKit lets you work in familiar units instead and converts exactly once, when talking to Access::
from pyaccesskit.units import cm, mm, inch
width = cm(6) + mm(5) # Length(twips=3685)
width.cm # 6.5 (approximately; lengths are whole twips)
A :class:Length is an immutable whole number of twips. In specs it serializes to a readable string such
as "6.5cm" and parses from strings ("2cm", "10mm", "1.5in", "12pt", "300tw") or plain
integers (twips).
Length ¶
Length(twips: int)
An immutable length, stored as a whole number of twips.
Construct lengths with the helper functions :func:twips, :func:pt, :func:mm, :func:cm and
:func:inch, or parse text with :meth:parse.
parse
classmethod
¶
parse(value: str | int | Length) -> Length
Parse "2cm", "10 mm", "1.5in", "12pt", "300tw" or an integer number of twips.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the text is not a recognised length. |
format ¶
format(unit: str = 'cm') -> str
Format in unit ("cm", "mm", "in", "pt" or "tw").
The result is the shortest decimal that parses back to exactly the same number of twips:
cm(1.5).format() == "1.5cm" and Length.parse(x.format(unit)) == x for every length and unit.