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

Method build

Lib/pagebot/elements/ruler.py:55–106  ·  view source on GitHub ↗

Build the Ruler in the current context >>> from pagebot import getContext >>> from pagebot.toolbox.units import pt >>> from pagebot.document import Document >>> c = getContext() >>> w, h = pt(300, 400) >>> doc = Document(w=w, h=h, autoPages=1, padding

(self, view, origin=ORIGIN, **kwargs)

Source from the content-addressed store, hash-verified

53 # D R A W B O T / F L A T S U P P O R T
54
55 def build(self, view, origin=ORIGIN, **kwargs):
56 """Build the Ruler in the current context
57
58 >>> from pagebot import getContext
59 >>> from pagebot.toolbox.units import pt
60 >>> from pagebot.document import Document
61 >>> c = getContext()
62 >>> w, h = pt(300, 400)
63 >>> doc = Document(w=w, h=h, autoPages=1, padding=30, context=c)
64 >>> c.newDrawing(doc=doc)
65 >>> page = doc[1]
66 >>> e = Ruler(parent=page, x=0, y=20, w=page.w, h=3)
67 >>> e.build(doc.getView(), pt(0, 0))
68 >>> e.xy
69 (0pt, 20pt)
70 >>> e.size
71 (300pt, 3pt)
72 >>> view = doc.getView()
73 >>> e.build(view, (0, 0))
74 >>> from pagebot.contexts.flatcontext.flatcontext import FlatContext
75 >>> from pagebot.document import Document
76 >>> c = FlatContext()
77 >>> doc = Document(w=w, h=h, autoPages=1, padding=30, context=c)
78 >>> page = doc[1]
79 >>> e = Ruler(parent=page, x=0, y=20, w=page.w, h=3)
80 >>> # Allow the context to create a new document and page canvas. Normally view does it.
81 >>> c.newPage(w, h)
82 >>> e.build(doc.getView(), pt(0, 0))
83 >>> e.xy
84 (0pt, 20pt)
85 >>> e.size
86 (300pt, 3pt)
87 """
88 context = self.context # Get current context and builder.
89 p = pointOffset(self.origin, origin)
90 p = self._applyScale(view, p)
91 px, py, _ = self._applyAlignment(p) # Ignore z-axis for now.
92 sIndent = self.css('indent')
93 sTailIndent = self.css('tailIndent')
94 w = self.w - sIndent - sTailIndent
95
96 # Let the view draw frame info for debugging, in case
97 # view.showFrame == True
98 #view.drawElementFrame(self, p)
99 context.fill(noColor)
100 context.stroke(self.css('stroke', noColor), self.css('strokeWidth'))
101 context.line((px + sIndent, py), (px + w, py))
102
103 # If there are child elements, recursively draw them over the pixel image.
104 self.buildChildElements(view, origin, **kwargs)
105 self._restoreScale(view)
106 view.drawElementInfo(self, origin)
107
108 # H T M L / S A S S S U P P O R T
109

Callers

nothing calls this directly

Calls 10

pointOffsetFunction · 0.90
_applyScaleMethod · 0.80
_applyAlignmentMethod · 0.80
buildChildElementsMethod · 0.80
_restoreScaleMethod · 0.80
cssMethod · 0.45
fillMethod · 0.45
strokeMethod · 0.45
lineMethod · 0.45
drawElementInfoMethod · 0.45

Tested by

no test coverage detected