MCPcopy Create free account
hub / github.com/PageBot/PageBot / px

Function px

Lib/pagebot/toolbox/units.py:1615–1642  ·  view source on GitHub ↗
(v, *args, **kwargs)

Source from the content-addressed store, hash-verified

1613# Px
1614
1615def 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
1644class Px(RelativeUnit):
1645 """Answers the `px` (pixel) instance.

Callers 5

constants.pyFile · 0.90
stylelib.pyFile · 0.90
build_htmlMethod · 0.90
build_htmlMethod · 0.90
_get_pxMethod · 0.85

Calls 5

asNumberOrNoneFunction · 0.90
PxClass · 0.85
unitsFunction · 0.85
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected