Untitled
unknown
plain_text
9 months ago
3.3 kB
15
Indexable
# File path for centered squares with outlined gray box (retry)
file_path_final = "/mnt/data/30_day_schedule_habits_final.pdf"
# Create canvas in landscape
c = canvas.Canvas(file_path_final, pagesize=landscape(A4))
width, height = landscape(A4)
# Margins and spacing
margin_x = 60
margin_y = 50
row_height = 25
col_width = (width - 2*margin_x - 100) / 30 # 30 days plus space for gray column
num_days = 30
num_cols = 8 # habits column
square_size = 15
# Title
c.setFont("Helvetica-Bold", 16)
c.drawCentredString(width/2, height - 30, "30-Day Daily Activities Tracker with Habits")
# Gray habit column with outline
habit_labels = [
"2.5 liters of water",
"No fap",
"Exercise",
"Healthy food",
"Less than 2 hours of phone usage",
"Mirror picture",
"Call family",
"Cold shower"
]
gray_col_x = margin_x
gray_col_width = 150
c.setFillColor(colors.lightgrey)
c.rect(gray_col_x, height - margin_y - num_cols*row_height, gray_col_width, num_cols*row_height, fill=True, stroke=True)
c.setFillColor(colors.black)
# Write habit labels centered vertically in each row
c.setFont("Helvetica", 10)
for i, label in enumerate(habit_labels):
y = height - margin_y - (i+0.7) * row_height
c.drawString(gray_col_x + 5, y, label)
# Draw tickable squares for each day (30 columns) and habits (8 rows), centered
start_x = gray_col_x + gray_col_width + 10
for i in range(num_days):
x = start_x + i*col_width + (col_width - square_size)/2 # center in column
for j in range(num_cols):
y = height - margin_y - (j+1) * row_height + (row_height - square_size)/2 # center in row
c.rect(x, y, square_size, square_size)
# Draw vertical lines between days (for clarity)
for i in range(num_days + 1):
x = start_x + i*col_width
y_top = height - margin_y
y_bottom = height - margin_y - num_cols * row_height
c.setStrokeColor(colors.black)
c.line(x, y_top, x, y_bottom)
# Draw horizontal lines for habit rows
for j in range(num_cols + 1):
y = height - margin_y - j*row_height
c.line(start_x, y, start_x + num_days*col_width, y)
# Label days on top
c.setFont("Helvetica", 8)
for i in range(num_days):
x = start_x + i*col_width + col_width/2
c.drawCentredString(x, height - margin_y + 5, f"{i+1}")
# Sleep graph title
graph_top = height - margin_y - num_cols*row_height - 40
c.setFont("Helvetica-Bold", 12)
c.drawString(margin_x, graph_top, "Sleep Hours Graph (plot manually)")
# Draw graph grid (30 days on X, 12 hours on Y)
graph_height = 200
graph_width = width - 2*margin_x
num_sleep_hours = 12
# horizontal lines (hours)
for i in range(num_sleep_hours + 1):
y = graph_top - 20 - (i/num_sleep_hours)*graph_height
c.setStrokeColor(colors.lightgrey)
c.line(margin_x, y, margin_x + graph_width, y)
c.setStrokeColor(colors.black)
c.drawString(margin_x - 25, y - 3, str(i))
# vertical lines (days)
for i in range(num_days + 1):
x = margin_x + (i/num_days)*graph_width
c.setStrokeColor(colors.lightgrey)
c.line(x, graph_top - 20, x, graph_top - 20 - graph_height)
c.setStrokeColor(colors.black)
if i < num_days:
c.drawCentredString(x + graph_width/num_days/2, graph_top - 35 - graph_height, f"{i+1}")
# Save PDF
c.save()
file_path_final
Editor is loading...
Leave a Comment