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

Method drawNameInfo

Lib/pagebot/elements/views/mapview.py:278–330  ·  view source on GitHub ↗

Draws additional document information, color markers, page number, date, version, etc. outside the page frame, if drawing crop marks. >>> from pagebot import getContext >>> context = getContext() >>> from pagebot.elements.element import Element >>> from pageb

(self, e, origin, path)

Source from the content-addressed store, hash-verified

276 e._restoreScale(self)
277
278 def drawNameInfo(self, e, origin, path):
279 """Draws additional document information, color markers, page number,
280 date, version, etc. outside the page frame, if drawing crop marks.
281
282 >>> from pagebot import getContext
283 >>> context = getContext()
284 >>> from pagebot.elements.element import Element
285 >>> from pagebot.style import getRootStyle
286 >>> from pagebot.elements.views.pageview import PageView
287 >>> path = '_export/PageNameInfo.pdf'
288 >>> # Get default values.
289 >>> style = getRootStyle()
290 >>> # Works on generic elements as well as pages.
291 >>> e = Element(style=style)
292 >>> view = PageView(context=context, style=style)
293 >>> view.showNameInfo = True
294 >>> view.drawNameInfo(e, (0, 0), path)
295 """
296 if (self.showNameInfo and e.isPage) or e.showNameInfo:
297 # Position of text is based on crop mark size.
298 cmDistance = self.css('viewCropMarkDistance')
299 cmSize = self.css('viewCropMarkSize') - cmDistance
300 fontSize = self.css('viewNameFontSize')
301 dt = datetime.datetime.now()
302 d = dt.strftime("%A, %d. %B %Y %I:%M%p")
303 # Test if there is a document.
304 if e.isPage and e.parent is not None:
305 pn = e.parent.getPageNumber(e)
306 # First or only page on this page number, then just show pn[0].
307 if pn[1] == 0:
308 pn = pn[0]
309
310 # More than one page, then show total.
311 if len(e.parent.pages) > 1:
312 pn = '%s/%d' % (pn, len(e.parent.pages))
313
314 title = e.parent.title or 'Untitled'
315 s = 'Page %s | %s | %s' % (pn, d, title)
316 # Otherwise always page number #1.
317 else:
318 pn = 1
319 title = 'Untitled'
320 s = 'Element %s | %s' % (d, title)
321 if e.name and e.name != 'default':
322 s += ' | ' + e.name
323 if path is not None:
324 # We're only interested in the file name.
325 s += ' | ' + path.split('/')[-1]
326 bs = self.context.newString(s, style=dict(font=self.css('viewNameFont'),
327 textFill=blackColor, fontSize=fontSize))
328 # Draw on top of page.
329 self.context.text(bs, (self.pl + cmDistance,
330 self.pb + e.h + cmSize - fontSize*2))
331
332
333 def drawFlowConnections(self, e, origin):

Callers 1

drawPageMetaInfoMethod · 0.95

Calls 4

getPageNumberMethod · 0.80
newStringMethod · 0.80
cssMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected