Answers the `px` (pixel) instance. >>> # Direct creation of class instance, only for (int, float, Unit) >>> Px(12) 12px >>> # Through creator function >>> px(12) 12px >>> # Through creator function, strings are interpreted (int, float, Unit, str) >>> px('12px') 1
| 1642 | return u |
| 1643 | |
| 1644 | class Px(RelativeUnit): |
| 1645 | """Answers the `px` (pixel) instance. |
| 1646 | |
| 1647 | >>> # Direct creation of class instance, only for (int, float, Unit) |
| 1648 | >>> Px(12) |
| 1649 | 12px |
| 1650 | >>> # Through creator function |
| 1651 | >>> px(12) |
| 1652 | 12px |
| 1653 | >>> # Through creator function, strings are interpreted (int, float, Unit, str) |
| 1654 | >>> px('12px') |
| 1655 | 12px |
| 1656 | >>> u = units('12px') |
| 1657 | >>> u |
| 1658 | 12px |
| 1659 | >>> # Math on Unit create new Unit instance of same type. |
| 1660 | >>> u/2 |
| 1661 | 6px |
| 1662 | >>> u-1 |
| 1663 | 11px |
| 1664 | >>> # Answer pt value, assuming here an 1:1 conversion |
| 1665 | >>> u.pt |
| 1666 | 12 |
| 1667 | >>> u = units('1050px') |
| 1668 | >>> u |
| 1669 | 1050px |
| 1670 | >>> u.pt |
| 1671 | 1050 |
| 1672 | """ |
| 1673 | PT_FACTOR = 1.3333 # This may not always be 1:1 to points. |
| 1674 | UNIT = 'px' |
| 1675 | |
| 1676 | def _get_px(self): |
| 1677 | """No transforming or casting, just answer the self.v. |
| 1678 | |
| 1679 | >>> px(23).px |
| 1680 | 23 |
| 1681 | """ |
| 1682 | return self.rv |
| 1683 | px = property(_get_px) |
| 1684 | |
| 1685 | def _get_pt(self): |
| 1686 | """Answers the rendered value in `pt` (points). We cannot set relative |
| 1687 | units directly from the `pt` property, except for `px` (pixels), which |
| 1688 | are then assumed to be equal. |
| 1689 | |
| 1690 | >>> u = px(24, base=12) |
| 1691 | >>> u, u.pt |
| 1692 | (24px, 288) |
| 1693 | >>> u = px(12) |
| 1694 | >>> u.pt |
| 1695 | 12 |
| 1696 | >>> u.pt = 100 |
| 1697 | >>> u |
| 1698 | 100px |
| 1699 | """ |
| 1700 | # Renders value and casts it to points. |
| 1701 | return asIntOrFloat(pt(self.ru).rv) |