示例#1
0
 def add_map(self, map_image, is_data_entry=True, has_mini_form=False):
     y = self.origin_y
     map_width, map_height = map_image.size
     if is_data_entry:
         y = y + self.qr_size + self.gutter_size
     if has_mini_form:
         y = y + Units.pixel_to_point(300)
     self.canvas.drawInlineImage(
         map_image, self.origin_x, y,
         Units.pixel_to_point(map_width), Units.pixel_to_point(map_height))
示例#2
0
 def add_form(self, num_rows, form, print_object, is_mini_form=False):
     cols = print_object.get_form_field_layout()
     field_aliases, field_widths = ['ID'], [5]
     field_aliases.extend([c.field.col_alias for c in cols])
     field_widths.extend([c.width for c in cols])
     field_widths = [n/100.0*self.inner_width for n in field_widths] #normalize
     x, y = self.origin_x, self.origin_y + self.qr_size
     width = self.inner_width
     height = self.inner_height - self.qr_size - 35
     if is_mini_form:
         height = Units.pixel_to_point(300) #only render a 300-pixel tall form
     
     data, rowheights, header_flowables = [], [39], []
     style = ParagraphStyle(name='Helvetica', fontName='Helvetica', fontSize=10)
     for a in field_aliases:
         header_flowables.append(Paragraph('<b>%s</b>' % a, style))
     data.append(header_flowables)
     for n in range(0, num_rows):
         data.append(['' for n in field_widths])
         rowheights.append(39)
 
     t=Table(data, field_widths, rowheights)
     GRID_STYLE = TableStyle([
         ('GRID', (0,0), (-1,-1), 0.25, colors.black),
         ('FONT', (0,0), (-1,-1), 'HandSean'),
         ('BOX',(0,0),(-1,-1),2,colors.black)
     ])
     t.setStyle(GRID_STYLE)
     frame = Frame(x, y, width, height, showBoundary=0, leftPadding=0,
                   bottomPadding=0, rightPadding=0, topPadding=0)
     frame.addFromList([t], self.canvas)
示例#3
0
    def add_footer(self, qr_image, uuID, instructions):
        # output QR-code:
        self.qr_size = Units.pixel_to_point(qr_image.size[0])
        x = self.origin_x + self.inner_width - self.qr_size #align right
        self.canvas.drawInlineImage(qr_image, x, self.origin_y, self.qr_size,
                                    self.qr_size)

        # output Print ID:
        items = []
        style = ParagraphStyle(name='Helvetica', fontName='Helvetica', fontSize=10)
        items.append(Paragraph('Print ID: ' + uuID, style))
        frame = Frame(x, self.origin_y-self.qr_size, self.inner_width-self.qr_size,
                      self.qr_size, showBoundary=0, leftPadding=0, bottomPadding=0,
                      rightPadding=0, topPadding=0)
        frame.addFromList(items, self.canvas)

        # output default instructions:
        link_text = "When you're done drawing on the map, scan or photograph it and \
                    submit it to our website: http://localground.org/upload, or \
                    email it to [email protected]."

        items = []
        style = ParagraphStyle(
            name='Helvetica', fontName='Helvetica', fontSize=8,
            backColor=colors.HexColor(0xEEEEEE), borderColor=colors.HexColor(0xEEEEEE),
            leftIndent=0, rightIndent=0, spaceBefore=5, spaceAfter=5, borderWidth=5)
        items.append(Paragraph(link_text, style))

        padding_x, padding_y = -4, 12
        width, height = self.inner_width - self.qr_size, self.qr_size
        frame = Frame(self.origin_x+padding_x, self.origin_y+3, width, height, showBoundary=0)
        frame.addFromList(items, self.canvas)

        # output custom instructions:
        items = []
        style = ParagraphStyle(name='Helvetica', fontName='Helvetica', fontSize=10)
        items.append(Paragraph(instructions, style))
        frame = Frame(self.origin_x+padding_x-2, self.origin_y-padding_y, width,
                      height-15, showBoundary=0)
        frame.addFromList(items, self.canvas)