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

Method drawGrid

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

Draws grid of lines and / or rectangles if colors are set in the style. Normally origin is ORIGIN `pt(0, 0, 0)`, but it's possible to give the grid a fixed offset. If types self.showGrid is set, display the type of grid in forground for `(GRID_COL, GRID_ROW, GRID_SQ

(self, e, origin, background=False)

Source from the content-addressed store, hash-verified

607 # G R I D
608
609 def drawGrid(self, e, origin, background=False):
610 """Draws grid of lines and / or rectangles if colors are set in the
611 style. Normally origin is ORIGIN `pt(0, 0, 0)`, but it's possible to
612 give the grid a fixed offset.
613
614 If types self.showGrid is set, display the type of grid in forground for
615 `(GRID_COL, GRID_ROW, GRID_SQR)` and draw in background for `(GRID_COL_BG,
616 GRID_ROW_BG, GRID_SQR_BG)`.
617
618 >>> from pagebot import getContext
619 >>> context = getContext()
620 >>> from pagebot.elements.element import Element
621 >>> from pagebot.style import getRootStyle
622 >>> from pagebot.elements.views.pageview import PageView
623 >>> # Get default values.
624 >>> style = getRootStyle()
625 >>> # Works on generic elements as well as pages.
626 >>> e = Element(style=style)
627 >>> view = PageView(context=context, style=style)
628 >>> view.showGrid = [GRID_COL, GRID_ROW]
629 >>> view.drawGrid(e, (0, 0))
630 >>> view.showGrid = [GRID_COL_BG]
631 >>> view.drawGrid(e, (0, 0), background=True)
632 """
633 if (self.showGrid and e.isPage):
634 showGrid = self.showGrid
635 elif e.showGrid:
636 showGrid = e.showGrid
637 else:
638 return
639
640 p = pointOffset(e.origin, origin)
641 p = self._applyScale(e, p)
642 px, py, _ = e._applyAlignment(p) # Ignore z-axis for now.
643
644 # Drawing the grid as vertical lines. Check on foreground/background flags.
645 if (background and GRID_COL_BG in showGrid) or (not background and GRID_COL in showGrid):
646 # Set color for vertical grid lines
647 self.context.fill(noColor)
648 gridStrokeColor = e.css('viewGridStrokeY', noColor)
649 gridStrokeWidth = e.css('viewGridStrokeWidthY', blackColor)
650 self.context.stroke(gridStrokeColor, gridStrokeWidth)
651
652 gridX = e.gridX
653 if gridX:
654 x = px+e.pl # Position on left padding of page/e
655 y1 = py+e.pb
656 y2 = y1 + e.ph
657 for cw in gridX:
658 if isinstance(cw, (tuple, list)):
659 cw, gx = cw
660 else:
661 gx = 0
662 self.context.line((x, y1), (x, y2))
663 if gx:
664 self.context.line((x+cw, y1), (x+cw, y2))
665 x += cw + gx
666

Callers 1

drawPageMetaInfoMethod · 0.95

Calls 8

pointOffsetFunction · 0.90
_applyScaleMethod · 0.80
_applyAlignmentMethod · 0.80
fillMethod · 0.45
cssMethod · 0.45
strokeMethod · 0.45
lineMethod · 0.45
rectMethod · 0.45

Tested by

no test coverage detected