PyInvoice/pyinvoice/components.py

58 lines
1.8 KiB
Python
Raw Normal View History

2015-05-30 13:15:47 +00:00
from reportlab.lib.units import inch
from reportlab.platypus import Paragraph, Table, TableStyle
2015-05-27 09:35:13 +00:00
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
from reportlab.lib import colors
class CodeSnippet(Paragraph):
style = ParagraphStyle(
name='CodeSnippet',
parent=getSampleStyleSheet()['Code'],
backColor=colors.lightgrey, leftIndent=0,
borderPadding=(5, 5, 5, 5)
)
def __init__(self, code):
2015-05-27 17:09:44 +00:00
Paragraph.__init__(self, code, self.style)
2015-05-28 10:17:55 +00:00
class SimpleTable(Table):
2015-05-30 16:30:00 +00:00
def __init__(self, data, horizontal_align=None):
Table.__init__(self, data, hAlign=horizontal_align)
2015-05-28 10:17:55 +00:00
2015-05-30 16:30:00 +00:00
class TableWithHeader(Table):
2015-06-09 13:25:42 +00:00
def __init__(self, data, horizontal_align=None, style=None):
Table.__init__(self, data, hAlign=horizontal_align)
2015-05-28 10:17:55 +00:00
2015-06-09 13:25:42 +00:00
default_style = [
2015-05-30 16:30:00 +00:00
('INNERGRID', (0, 0), (-1, -1), .25, colors.black),
('BOX', (0, 0), (-1, -1), .25, colors.black),
('BACKGROUND', (0, 0), (-1, -len(data)), colors.lightgrey),
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
('VALIGN', (0, 0), (-1, -1), 'MIDDLE')
2015-06-09 13:25:42 +00:00
]
if style and isinstance(style, list):
default_style.extend(style)
self.setStyle(TableStyle(default_style))
2015-05-30 16:30:00 +00:00
2015-05-28 10:17:55 +00:00
class PaidStamp(object):
def __init__(self, x, y):
self.x = x
self.y = y
def __call__(self, canvas, doc):
2015-05-30 13:15:47 +00:00
# "PAID"
2015-05-28 10:17:55 +00:00
canvas.saveState()
2015-05-30 13:15:47 +00:00
canvas.setFontSize(50)
canvas.setFillColor(colors.red)
canvas.setStrokeColor(colors.red)
canvas.rotate(45)
2015-05-28 10:17:55 +00:00
canvas.drawString(self.x, self.y, 'PAID')
2015-05-30 13:15:47 +00:00
canvas.setLineWidth(4)
canvas.setLineJoin(1) # Round join
canvas.rect(self.x - .25 * inch, self.y - .25 * inch, width=2*inch, height=inch)
2015-05-28 10:17:55 +00:00
canvas.restoreState()