(v, *args, **kwargs)
| 1613 | # Px |
| 1614 | |
| 1615 | def px(v, *args, **kwargs): |
| 1616 | u = None |
| 1617 | base = kwargs.get('base', Px.BASE) |
| 1618 | # Not used by Px. |
| 1619 | g = kwargs.get('g', 0) |
| 1620 | |
| 1621 | # If there are more arguments, bind them together in a list. |
| 1622 | if args: |
| 1623 | v = [v]+list(args) |
| 1624 | if isinstance(v, (tuple, list)): |
| 1625 | u = [] |
| 1626 | for uv in v: |
| 1627 | u.append(px(uv, base=base, g=g)) |
| 1628 | u = tuple(u) |
| 1629 | elif isinstance(v, (int, float, RelativeUnit)): |
| 1630 | u = Px(v, base=base, g=g) |
| 1631 | elif isinstance(v, str): |
| 1632 | v = v.strip().lower() |
| 1633 | if v.endswith(Px.UNIT): |
| 1634 | v = asNumberOrNone(v[:-2]) |
| 1635 | if v is not None: |
| 1636 | u = Px(v, base=base, g=g) |
| 1637 | else: |
| 1638 | # Something else, recursively try again. |
| 1639 | u = units(v, base=base, g=g) |
| 1640 | # Only makes sense for relative if the same. |
| 1641 | assert isinstance(u, Px) |
| 1642 | return u |
| 1643 | |
| 1644 | class Px(RelativeUnit): |
| 1645 | """Answers the `px` (pixel) instance. |
no test coverage detected