From a1bea40c6752f865d92351bce51b15f009902cfe Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 16 Feb 2024 19:17:15 +0100 Subject: Start writing a colour chart index --- forms/colour_chart.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'forms') diff --git a/forms/colour_chart.py b/forms/colour_chart.py index efcd7d0..bbdf021 100755 --- a/forms/colour_chart.py +++ b/forms/colour_chart.py @@ -2,6 +2,7 @@ import argparse import math +import operator import fpdf import strictyaml @@ -10,6 +11,7 @@ import strictyaml class Chart: COLUMNS=4 ROWS=16 + INDEX_COLS=6 def __init__(self): self.parser = self.get_parser() @@ -42,6 +44,14 @@ class Chart: ] return(cells) + def get_index(self): + index = [ + (c["label"], i // self.ROWS) + for i, c in enumerate(self.data["colours"]) + ] + index.sort(key=operator.itemgetter(0)) + return index + def write_pdf(self, fname): pdf = fpdf.FPDF(format="A5") pdf.add_font( @@ -78,6 +88,21 @@ class Chart: pdf.cell(16, 8, cell["label"], ) pdf.ln(10) + pdf.set_font("FreeSerif", size=10) + with pdf.text_columns( + ncols=self.INDEX_COLS, + balance=True, + gutter=4, + text_align="RIGHT", + ) as cols: + for c in self.get_index(): + pdf.set_font("FreeSerif", size=10) + cols.write(str(c[0])) + cols.write(" ") + pdf.set_font("FreeSans", "B", size=10) + cols.write(str(c[1])) + cols.ln() + pdf.output(fname) -- cgit v1.2.3