Example #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))
Example #2
0
 def add_form(self, num_rows, form, is_mini_form=False):
     cols = form.get_fields(print_only=True)
     field_aliases, field_widths = ['ID'], [5]
     field_aliases.extend([c.col_alias for c in cols])
     field_widths.extend([c.display_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(['', '', '', ''])
         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)
Example #3
0
 def get_basemap_and_extents(self, map_type, zoom, center, width, height):
     import os, urllib, StringIO, Image
     #units.Units.add_pixels_to_latlng(center_lat, center_lng, zoom, 300, 300)
     map_url = None
     if map_type.overlay_source.name == 'cloudmade':
         styleid = map_type.provider_id
         api_key = settings.CLOUDMADE_KEY
         map_url = 'http://staticmaps.cloudmade.com/' + api_key + \
             '/staticmap?styleid=' + styleid + '&zoom=' + str(zoom) + \
             '&center=' + str(center.y) + ',' + str(center.x) + \
             '&size=' + str(width) + 'x' + str(height)
     #if google is the map provider:
     else:
         scale_factor = 1
         if not settings.IS_GOOGLE_REGISTERED_NONPROFIT:
             zoom, width, height = zoom-1, int(width/2), int(height/2)
             scale_factor = 2
         
         map_url = map_type.wms_url + '&zoom=' + str(zoom) + '&center=' + \
             str(center.y) + ',' + str(center.x) + '&size=' + str(width) + \
             'x' + str(height) + '&scale=' + str(scale_factor)
     
     #calculate extents (returns geos Point):
     #(0,0) in pacific northwest; x = lat, y = lng
     northeast = Units.add_pixels_to_latlng(center.clone(), zoom, int(width/2), -1*int(height/2))
     southwest = Units.add_pixels_to_latlng(center.clone(), zoom, -1*int(width/2), int(height/2))
     
     try:
         file = urllib.urlopen(map_url)
         map_image = StringIO.StringIO(file.read()) # constructs a StringIO holding the image
         map_image = Image.open(map_image).convert('RGB')
     except IOError:
         error_image_url = 'https://chart.googleapis.com/chart?chst=d_fnote_title&chld=sticky_y|1|FF0000|l|Map%20Service%20Unavailable|'
         file = urllib.urlopen(error_image_url)
         map_image = StringIO.StringIO(file.read()) # constructs a StringIO holding the image
         map_image = Image.open(map_image).convert('RGB')
     return {
         'map_image': map_image,
         'northeast': northeast,
         'southwest': southwest
     }
Example #4
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)