Skip to content

Commit fa9c77b

Browse files
author
Robert Wang
committed
Add date, name, score section at the top of first page
1 parent 11aa6b2 commit fa9c77b

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

run.py

+38-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, type_: str, max_number: int, question_count: int):
2626
self.large_font_size = 30
2727
self.size = 21
2828
self.tiny_pad_size = 2
29+
self.middle_pad_size = 6
2930
self.pad_size = 10
3031
self.large_pad_size = 30
3132
self.num_x_cell = 4
@@ -99,7 +100,10 @@ def make_question_page(self, data: List[QuestionInfo]):
99100
total_pages = len(problems_per_page)
100101
for page in range(total_pages):
101102
self.pdf.add_page(orientation='L')
102-
if problems_per_page[page] < self.num_x_cell:
103+
104+
if page == 0:
105+
self.print_header_section()
106+
elif problems_per_page[page] < self.num_x_cell:
103107
self.print_question_row(data, page * page_area, problems_per_page[page])
104108
else:
105109
problems_per_row = self.split_arr(problems_per_page[page], self.num_x_cell)
@@ -118,9 +122,9 @@ def split_arr(self, x: int, y: int):
118122

119123
return [y] * quotient
120124

121-
def print_top_row(self, question_num: str):
125+
def print_top_row(self, question_num: str, font_size: int=15):
122126
"""Helper function to print first character row of a question row"""
123-
self.pdf.set_font(self.font_1, size=self.middle_font_size)
127+
self.pdf.set_font(self.font_1, size=font_size)
124128
self.pdf.cell(self.pad_size, self.pad_size, txt=question_num, border='LT', align='C')
125129
self.pdf.cell(self.size, self.pad_size, border='T')
126130
self.pdf.cell(self.size, self.pad_size, border='T')
@@ -173,6 +177,14 @@ def print_bottom_row_division(self):
173177
self.pdf.cell(self.size, self.size, border='B')
174178
self.pdf.cell(self.pad_size, self.size, border='BR')
175179

180+
def print_header_section_bottom_row(self):
181+
"""Helper function to print bottom row of header section"""
182+
self.pdf.set_font(self.font_2, size=self.tiny_pad_size)
183+
self.pdf.cell(self.pad_size, self.pad_size, border='LB', align='C')
184+
self.pdf.cell(self.size, self.pad_size, border='B', align='C')
185+
self.pdf.cell(self.size, self.pad_size, border='B', align='C')
186+
self.pdf.cell(self.pad_size, self.pad_size, border='BR', align='C')
187+
176188
def print_edge_vertical_separator(self):
177189
"""Print space between question for the top or bottom row"""
178190
self.pdf.cell(self.pad_size, self.pad_size)
@@ -186,6 +198,29 @@ def print_horizontal_separator(self):
186198
self.pdf.cell(self.size, self.size)
187199
self.pdf.ln()
188200

201+
def print_header_section(self):
202+
self.print_top_row(question_num='Date', font_size=self.small_font_size)
203+
self.print_edge_vertical_separator()
204+
205+
self.print_top_row(question_num='Name', font_size=self.small_font_size)
206+
self.print_edge_vertical_separator()
207+
208+
self.print_top_row(question_num='Score', font_size=self.small_font_size)
209+
self.print_edge_vertical_separator()
210+
211+
self.print_top_row(question_num='')
212+
self.print_edge_vertical_separator()
213+
self.pdf.ln()
214+
215+
for _ in range(self.num_x_cell):
216+
self.print_header_section_bottom_row()
217+
self.print_edge_vertical_separator()
218+
219+
self.pdf.ln()
220+
221+
self.print_horizontal_separator(dimension=self.tiny_pad_size)
222+
223+
189224
def print_question_row(self, data, offset, num_problems):
190225
"""Print a single row of questions (total question in a row is set by num_x_cell)"""
191226
for x in range(0, num_problems):

0 commit comments

Comments
 (0)