>>> from pagebot import getContext >>> context = getContext() >>> from pagebot.elements.element import Element >>> from pagebot.style import getRootStyle >>> path = '_export/PageNameInfo.pdf' >>> # Get default values. >>> style = getRootStyle(
(self, e, path)
| 443 | self.context.drawString(bs, (x, y+cropmarkDistance)) |
| 444 | |
| 445 | def getNameString(self, e, path): |
| 446 | """ |
| 447 | >>> from pagebot import getContext |
| 448 | >>> context = getContext() |
| 449 | >>> from pagebot.elements.element import Element |
| 450 | >>> from pagebot.style import getRootStyle |
| 451 | >>> path = '_export/PageNameInfo.pdf' |
| 452 | >>> # Get default values. |
| 453 | >>> style = getRootStyle() |
| 454 | >>> e = Element(style=style) |
| 455 | >>> e.name = 'ElementName' |
| 456 | >>> view = PageView(context=context, style=style) |
| 457 | >>> view.showNameInfo = True |
| 458 | >>> s = view.getNameString(e, '/test/path') |
| 459 | >>> s.endswith('path') |
| 460 | True |
| 461 | """ |
| 462 | dt = datetime.datetime.now() |
| 463 | d = dt.strftime("%A, %d. %B %Y %I:%M%p") |
| 464 | |
| 465 | if e.isPage and e.parent is not None: |
| 466 | # Test if there is a document. |
| 467 | pn = e.parent.getPageNumber(e) |
| 468 | |
| 469 | # First or only page on this page number, then just show pn[0]. |
| 470 | if pn[1] == 0: |
| 471 | pn = pn[0] |
| 472 | |
| 473 | # More than one page, then show total. |
| 474 | if len(e.parent.pages) > 1: |
| 475 | pn = '%s/%d' % (pn, len(e.parent.pages)) |
| 476 | |
| 477 | title = e.parent.name or e.parent.title or 'Untitled' |
| 478 | s = 'Page %s | %s | %s' % (pn, d, title) |
| 479 | |
| 480 | else: |
| 481 | # Otherwise always page number #1. |
| 482 | pn = 1 |
| 483 | title = 'Untitled' |
| 484 | s = 'Element %s | %s' % (d, title) |
| 485 | |
| 486 | if e.name and e.name != 'default': |
| 487 | s += ' | %s' % e.name |
| 488 | |
| 489 | if path is not None: |
| 490 | # We're only interested in the file name. |
| 491 | s += ' | %s' % path.split('/')[-1] |
| 492 | |
| 493 | return s |
| 494 | |
| 495 | |
| 496 | # D R A W I N G F L O W S |
no test coverage detected