Skip to content

yex.value.Muglue

yex.value.Muglue(space=0.0, space_unit=None, stretch=0.0, stretch_unit=None, shrink=0.0, shrink_unit=None) #

Bases: yex.value.glue.Glue

Source code in yex/value/glue.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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)