Inch 72 * the base unit size of all PageBot measures. >>> units('0.4"') 0.40" >>> Inch(0.4) 0.40" >>> inch('0.4"') 0.40" >>> u = units('0.4inch') >>> u 0.40" >>> u*2 0.80" >>> u/2 0.20" >>> u-0.1 0.30" >>> # Multiple arguments create a
| 1359 | return u |
| 1360 | |
| 1361 | class Inch(Unit): |
| 1362 | """Inch 72 * the base unit size of all PageBot measures. |
| 1363 | |
| 1364 | >>> units('0.4"') |
| 1365 | 0.40" |
| 1366 | >>> Inch(0.4) |
| 1367 | 0.40" |
| 1368 | >>> inch('0.4"') |
| 1369 | 0.40" |
| 1370 | >>> u = units('0.4inch') |
| 1371 | >>> u |
| 1372 | 0.40" |
| 1373 | >>> u*2 |
| 1374 | 0.80" |
| 1375 | >>> u/2 |
| 1376 | 0.20" |
| 1377 | >>> u-0.1 |
| 1378 | 0.30" |
| 1379 | >>> # Multiple arguments create a list of tuple inch. |
| 1380 | >>> inch(10, 11, 12) |
| 1381 | (10", 11", 12") |
| 1382 | >>> # Arguments can be submitted as list or tuple. |
| 1383 | >>> inch((10, 11, 12, 13)) |
| 1384 | (10", 11", 12", 13") |
| 1385 | >>> # Arguments can be a list of other units types. |
| 1386 | >>> inch(mm(5), pt(24), px(5)) |
| 1387 | (0.20", 0.33", 0.07") |
| 1388 | >>> # Arguments can interpret from strings of other units types. |
| 1389 | >>> inch('10pt', '11mm') |
| 1390 | (0.14", 0.43") |
| 1391 | """ |
| 1392 | PT_FACTOR = INCH # 72pt = 1" |
| 1393 | UNIT = 'inch' # Alternative is " |
| 1394 | UNITC = '"' |
| 1395 | |
| 1396 | def _get_inch(self): |
| 1397 | """No transforming or casting, just answer the self.rv. |
| 1398 | |
| 1399 | >>> inch(6).inch |
| 1400 | 6 |
| 1401 | >>> inch(7.0).inch |
| 1402 | 7 |
| 1403 | """ |
| 1404 | return self.rv |
| 1405 | inch = property(_get_inch) |
| 1406 | |
| 1407 | def __repr__(self): |
| 1408 | v = asIntOrFloat(self.v) |
| 1409 | if isinstance(v, int): |
| 1410 | return '%d%s' % (v, self.UNITC) |
| 1411 | return '%0.2f%s' % (v, self.UNITC) |
| 1412 | |
| 1413 | class Formula(Unit): |
| 1414 | """Unit class that contains a sequence of other units and rules how to |