-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormal-painter.py
86 lines (68 loc) · 3.12 KB
/
normal-painter.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
from core import CardPainter
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import Paragraph, Frame, KeepInFrame
class NormalCardPainter(CardPainter):
def paint(self):
for story in self.backlog:
self.__paint_story_card(story)
self.canvas.save()
def __paint_story_card(self, story):
self.story_count += 1
if self.story_count % 2 == 1:
if self.story_count > 1:
self.canvas.showPage()
x0, y0 = self.padding, self.page_height / 2 + self.padding
x1, y1 = self.page_width - self.padding, self.page_height - self.padding
else:
x0, y0 = self.padding, self.padding
x1, y1 = self.page_width - self.padding, self.page_height / 2 - self.padding
# background
self.canvas.setFillGray(self.lite_gray)
self.canvas.setLineWidth(4)
self.canvas.setStrokeGray(self.black)
self.canvas.rect(x0, y0, x1-x0, y1-y0, stroke=1, fill=1)
self.canvas.setFillGray(self.white)
self.canvas.setStrokeGray(self.gray)
self.canvas.setLineWidth(1)
self.canvas.rect(x0+20, y0+160, 360, 100, stroke=1, fill=1)
self.canvas.rect(x0+20, y0+20, 360, 100, stroke=1, fill=1)
self.canvas.rect(x0+420, y0+210, 100, 80, stroke=1, fill=1)
self.canvas.rect(x0+420, y0+90, 100, 80, stroke=1, fill=1)
# keys
self.setFontSize(16)
self.canvas.setFillGray(self.black)
self.canvas.drawString(x0+20, y1-30, 'Backlog item #%s' % story.sid)
self.canvas.setFillGray(self.gray)
self.canvas.drawString(x0+20, y0+270, 'How to demo')
self.canvas.drawString(x0+20, y0+130, 'Notes')
self.canvas.drawString(x0+420, y0+300, 'Importance')
self.canvas.drawString(x0+420, y0+180, 'Estimate')
# values
self.canvas.setFillGray(self.black)
self.setFontSize(36)
self.canvas.drawString(x0+440, y0+240, story.imp)
self.canvas.drawString(x0+440, y0+120, story.est)
style = ParagraphStyle('normal', fontName=self.fontname, fontSize=36, leading=40, textColor=[self.black]*3)
text = [Paragraph(story.name, style)]
text_inframe = KeepInFrame(360, 60, text)
frame = Frame(x0+14, y1-95, 360, 60)
frame.addFromList([text_inframe], self.canvas)
style = ParagraphStyle('normal', fontName=self.fontname, fontSize=18, leading=24, textColor=[self.black]*3)
text = [Paragraph(story.demo, style)]
text_inframe = KeepInFrame(360, 100, text)
frame = Frame(x0+20, y0+160, 360, 100)
frame.addFromList([text_inframe], self.canvas)
text = [Paragraph(story.notes, style)]
text_inframe = KeepInFrame(360, 100, text)
frame = Frame(x0+20, y0+20, 360, 100)
frame.addFromList([text_inframe], self.canvas)
def main():
input_path = 'input.csv'
output_path = 'normal-cards.pdf'
fontname = 'msyh'
fontpath = 'assets/msyh.ttf'
painter = NormalCardPainter(input_path, output_path, fontname, fontpath)
painter.paint()
if __name__ == '__main__':
main()