Пример #1
0
class Detail(Flowable):
    def __init__(self, results, components, references, title=""):
        self.styles = getSampleStyleSheet()
        self.has_references = bool(references)
        self.title = title
        comps = components.split(',')
        res = results.split(',')
        # self.data = [["" for x in range(3)] for y in len(comps)]
        self.data = []
        if self.has_references:
            ref = references.split(",")
            for t in zip(comps, res, ref):
                self.data.append(list(t))
        else:
            for t in zip(comps, res):
                self.data.append(list(t))

    def split(self, availWidth, availHeight):
        return []  # do not split

    def wrap(self, availWidth, availHeight):
        width = availWidth * .8
        colwidth = width / 3

        row_count = len(self.data)
        row_height = availHeight / row_count

        fontsize = int((row_height * 1000) / 2)
        print "row_height = ", row_height
        print "fontsize = ", fontsize
        if fontsize > 14:
            fontsize = 14

        sH = self.styles["Heading2"]
        sH.fontSize = fontsize + 2
        sN = self.styles["Normal"]
        sN.fontSize = fontsize
        sN.alignment = TA_CENTER
        fontSmall = fontsize - 4
        data = []
        for l in self.data:
            row = []
            for idx, m in enumerate(l):
                if m:
                    if idx == 0:
                        sN.alignment = TA_RIGHT
                    else:
                        sN.alignment = TA_CENTER
                    if idx == 2:
                        sN.fontSize = fontSmall
                    else:
                        sN.fontSize = fontsize
                    row.append(Paragraph(m, sN))
                else:
                    row.append("xxx")
            data.append(row)

        self.table = Table(data, colWidths=[colwidth] * 3, hAlign='CENTER')
        self.table.canv = self.canv
        return self.table.wrap(width, availHeight)

    def draw(self):
        self.table.draw()
Пример #2
0
class Detail(Flowable):
    def __init__(self,
                 results,
                 components,
                 references,
                 title=""):
        self.styles = getSampleStyleSheet()
        self.has_references = bool(references)
        self.title = title
        comps = components.split(',')
        res = results.split(',')
        # self.data = [["" for x in range(3)] for y in len(comps)]
        self.data = []
        if self.has_references:
            ref = references.split(",")
            for t in zip(comps, res, ref):
                self.data.append(list(t))
        else:
            for t in zip(comps, res):
                self.data.append(list(t))

    def split(self, availWidth, availHeight):
        return []  # do not split

    def wrap(self, availWidth, availHeight):
        width = availWidth * .8
        colwidth = width / 3

        row_count = len(self.data)
        row_height = availHeight / row_count

        fontsize = int((row_height * 1000) / 2)
        print "row_height = ", row_height
        print "fontsize = ", fontsize
        if fontsize > 14:
            fontsize = 14

        sH = self.styles["Heading2"]
        sH.fontSize = fontsize + 2
        sN = self.styles["Normal"]
        sN.fontSize = fontsize
        sN.alignment = TA_CENTER
        fontSmall = fontsize - 4
        data = []
        for l in self.data:
            row = []
            for idx, m in enumerate(l):
                if m:
                    if idx == 0:
                        sN.alignment = TA_RIGHT
                    else:
                        sN.alignment = TA_CENTER
                    if idx == 2:
                        sN.fontSize = fontSmall
                    else:
                        sN.fontSize = fontsize
                    row.append(Paragraph(m, sN))
                else:
                    row.append("xxx")
            data.append(row)

        self.table = Table(data, colWidths=[colwidth]*3, hAlign='CENTER')
        self.table.canv = self.canv
        return self.table.wrap(width, availHeight)

    def draw(self):
        self.table.draw()
Пример #3
0
class Signatories(Flowable):
    def __init__(self, master, margin=10):
        Flowable.__init__(self)
        self.master = master
        self.margin = 10
        if master.medical_technologist or master.pathologist:
            self.has_data = True
        else:
            self.has_data = False

    def split(self, availWidth, availHeight):
        return []

    def wrap(self, availWidth, availHeight):
        return self.do_table_wrap(availWidth, availHeight)

    def do_table_wrap(self, availWidth, availHeight):
        styles = getSampleStyleSheet()
        sN = styles['Normal']
        sN.alignment = TA_CENTER
        data = [["" for x in range(12)] for y in range(3)]

        data[0][1] = Paragraph(
            "<br/><br/><strong>%s</strong>" % self.master.pathologist.fullname,
            sN)
        data[1][1] = Paragraph(
            self.master.pathologist.get_designation_display(), sN)
        data[2][1] = Paragraph(
            "PRC LIC #: %s" % self.master.pathologist.license, sN)

        data[0][7] = Paragraph(
            "<br/><br/><br/><strong>%s</strong>" %
            self.master.medical_technologist.fullname, sN)
        data[1][7] = Paragraph(
            self.master.medical_technologist.get_designation_display(), sN)
        data[2][7] = Paragraph(
            "PRC LIC #: %s" % self.master.medical_technologist.license, sN)

        w = availWidth - self.margin * 2
        spacer = int(w * 0.05)
        remWidth = (w - (spacer * 4)) / 8
        colWidths = [spacer] + \
            [remWidth] * 4 + \
            [spacer] * 2 + \
            [remWidth] * 4 + \
            [spacer]
        self.table = Table(data, colWidths=colWidths)
        self.table.setStyle(
            TableStyle([
                # config padding
                ('TOPPADDING', (0, 0), (-1, -1), 0),
                ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
                # lines
                ('LINEBELOW', (1, 0), (4, 0), 1, black),
                ('LINEBELOW', (7, 0), (10, 0), 1, black),
                # ('GRID', (0, 0), (-1, -1), 1, black),
                # Column 1
                ('SPAN', (1, 0), (4, 0)),
                ('SPAN', (1, 1), (4, 1)),
                ('SPAN', (1, 2), (4, 2)),
                # Column 2
                ('SPAN', (7, 0), (10, 0)),
                ('SPAN', (7, 1), (10, 1)),
                ('SPAN', (7, 2), (10, 2)),
            ]))
        self.table.canv = self.canv
        return self.table.wrap(availWidth, availHeight)

    def draw(self):
        self.table.draw()
Пример #4
0
class Signatories(Flowable):
    def __init__(self, master, margin=10):
        Flowable.__init__(self)
        self.master = master
        self.margin = 10
        if master.medical_technologist or master.pathologist:
            self.has_data = True
        else:
            self.has_data = False

    def split(self, availWidth, availHeight):
        return []

    def wrap(self, availWidth, availHeight):
        return self.do_table_wrap(availWidth, availHeight)

    def do_table_wrap(self, availWidth, availHeight):
        styles = getSampleStyleSheet()
        sN = styles['Normal']
        sN.alignment = TA_CENTER
        data = [["" for x in range(12)] for y in range(3)]

        data[0][1] = Paragraph("<br/><br/><strong>%s</strong>" %
                               self.master.pathologist.fullname, sN)
        data[1][1] = Paragraph(self.master.pathologist.
                               get_designation_display(), sN)
        data[2][1] = Paragraph("PRC LIC #: %s" %
                               self.master.pathologist.license, sN)

        data[0][7] = Paragraph("<br/><br/><br/><strong>%s</strong>" %
                               self.master.medical_technologist.fullname, sN)
        data[1][7] = Paragraph(self.master.medical_technologist.
                               get_designation_display(), sN)
        data[2][7] = Paragraph("PRC LIC #: %s" %
                               self.master.medical_technologist.license, sN)

        w = availWidth - self.margin * 2
        spacer = int(w * 0.05)
        remWidth = (w - (spacer * 4)) / 8
        colWidths = [spacer] + \
            [remWidth] * 4 + \
            [spacer] * 2 + \
            [remWidth] * 4 + \
            [spacer]
        self.table = Table(data, colWidths=colWidths)
        self.table.setStyle(TableStyle([
            # config padding
            ('TOPPADDING', (0, 0), (-1, -1), 0),
            ('BOTTOMPADDING', (0, 0), (-1, -1), 0),
            # lines
            ('LINEBELOW', (1, 0), (4, 0), 1, black),
            ('LINEBELOW', (7, 0), (10, 0), 1, black),
            # ('GRID', (0, 0), (-1, -1), 1, black),
            # Column 1
            ('SPAN', (1, 0), (4, 0)),
            ('SPAN', (1, 1), (4, 1)),
            ('SPAN', (1, 2), (4, 2)),
            # Column 2
            ('SPAN', (7, 0), (10, 0)),
            ('SPAN', (7, 1), (10, 1)),
            ('SPAN', (7, 2), (10, 2)),
        ]))
        self.table.canv = self.canv
        return self.table.wrap(availWidth, availHeight)

    def draw(self):
        self.table.draw()