def __init__(self,
space: (float|Dimen) = 0.0,
space_unit: (str|None) = None,
stretch: (float|Dimen) = 0.0,
stretch_unit: (str|None) = None,
shrink: (float|Dimen) = 0.0,
shrink_unit: (str|None) = None,
):
"""
space, stretch, and shrink are all numeric. They're passed to
Dimen()'s constructor along with the unit supplied.
They may also be Dimens, in which case their unit must not
be specified.
space_unit, stretch_unit, and shrink_unit are the units for
the space, stretch, and shrink parameters, respectively.
In addition to the usual possibilities,
stretch_unit and shrink_unit may be 'fil', 'fill', or 'filll'
for infinities.
"""
args = locals()
def _to_dimen(arg, can_be_infinite):
length = args[arg]
unit = args[f'{arg}_unit']
if isinstance(length, Dimen):
if unit is not None:
raise ValueError(
f'"{arg}" was a Dimen, '
f'but {arg}_unit was not None'
)
if not can_be_infinite and length.infinity!=0:
raise ValueError(
f'"{arg}" must be finite'
)
return Dimen.from_another(length)
else:
try:
length = float(length)
except TypeError:
raise ValueError(
f'{arg}=={length} must be numeric or Dimen '
f'(and not {type(length)})'
)
if can_be_infinite:
inf = {'can_use_fil': True}
else:
inf = {}
return Dimen(
float(length),
unit = unit,
**inf)
self._space = _to_dimen('space', False)
self._stretch = _to_dimen('stretch', True)
self._shrink = _to_dimen('shrink', True)