-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathcolorFrame.py
More file actions
36 lines (27 loc) · 1.25 KB
/
colorFrame.py
File metadata and controls
36 lines (27 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from reportlab.lib.colors import toColor
from reportlab.platypus import Frame
# ref https://gist.github.com/styrmis/5317292
# pylint complains about things which are decided by the base Frame class, so...
# pylint: disable=too-many-arguments,redefined-builtin,too-many-function-args
class ColorFrame(Frame):
""" Extends the reportlab Frame with the ability to draw a background color. """
def __init__(self, x1, y1, width,height, leftPadding=6, bottomPadding=6,
rightPadding=6, topPadding=6, id=None, showBoundary=0,
overlapAttachedSpace=None,_debug=None,background=None):
Frame.__init__(self, x1, y1, width, height, leftPadding,
bottomPadding, rightPadding, topPadding, id, showBoundary,
overlapAttachedSpace, _debug)
self.background = background
def drawBackground(self, canv):
color = toColor(self.background)
canv.saveState()
canv.setFillColor(color)
canv.rect(
self._x1, self._y1, self._x2 - self._x1, self._y2 - self._y1,
stroke=0, fill=1
)
canv.restoreState()
def addFromList(self, drawlist, canv):
if self.background:
self.drawBackground(canv)
Frame.addFromList(self, drawlist, canv)