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

Method drawGrid

Lib/pagebot/elements/views/pageview.py:807–932  ·  view source on GitHub ↗

Draws a 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_SQR)

(self, e, origin, background=False)

Source from the content-addressed store, hash-verified

805 # G R I D
806
807 def drawGrid(self, e, origin, background=False):
808 """Draws a grid of lines and / or rectangles if colors are set in the
809 style. Normally origin is ORIGIN pt(0, 0, 0), but it's possible to give
810 the grid a fixed offset.
811
812 If types self.showGrid is set, display the type of grid in forground
813 for (GRID_COL, GRID_ROW, GRID_SQR) and draw in background for
814 (GRID_COL_BG, GRID_ROW_BG, GRID_SQR_BG)
815
816 >>> from pagebot import getContext
817 >>> context = getContext()
818 >>> from pagebot.elements.element import Element
819 >>> from pagebot.style import getRootStyle
820 >>> # Get default values.
821 >>> style = getRootStyle()
822 >>> # Works on generic elements as well as pages.
823 >>> e = Element(style=style)
824 >>> view = PageView(context=context, style=style)
825 >>> view.showGrid = [GRID_COL, GRID_ROW]
826 >>> view.drawGrid(e, (0, 0))
827 >>> view.showGrid = [GRID_COL_BG]
828 >>> view.drawGrid(e, (0, 0), background=True)
829 """
830 if (self.showGrid and e.isPage):
831 showGrid = self.showGrid
832 elif e.showGrid:
833 showGrid = e.showGrid
834 else:
835 return
836
837 context = self.context
838
839 p = pointOffset(e.origin, origin)
840 p = self._applyScale(e, p)
841 px, py, _ = e._applyAlignment(p) # Ignore z-axis for now.
842
843 # Drawing the grid as vertical lines. Check on foreground / background
844 # flags.
845 if (background and GRID_COL_BG in showGrid) or \
846 (not background and GRID_COL in showGrid):
847 # Set color for vertical grid lines.
848 context.fill(noColor)
849
850 # Use local element color setting, otherwise find by view.css.
851 gridStrokeColor = e.style.get('viewGridStrokeY',
852 self.css('viewGridStrokeY', noColor))
853 gridStrokeWidth = e.style.get('viewGridStrokeWidthY',
854 self.css('viewGridStrokeWidthY',
855 self.DEFAULT_STROKE_WIDTH))
856 context.stroke(gridStrokeColor, gridStrokeWidth)
857 gridX = e.gridX
858
859 if gridX:
860 x = px + e.pl # Position on left padding of page/e
861 y1 = py + e.pb
862 y2 = y1 + e.ph
863
864 for cw in gridX:

Callers 2

drawPageMetaInfoMethod · 0.95

Calls 9

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

Tested by

no test coverage detected