Example #1
0
class CrossMgrPrintoutPDF( CrossMgrPrintout ):
	def __init__( self, dir, fileBase, orientation, categories = None, allInOne = False ):
		CrossMgrPrintout.__init__(self, categories)
		self.dir = dir
		self.fileBase = fileBase
		self.orientation = orientation
		self.allInOne = allInOne
		self.pdf = None
		self.lastFName = None
		
	def OnEndPrinting(self):
		if self.pdf and self.allInOne:
			if self.dir and not os.path.isdir( self.dir ):
				os.mkdir( self.dir )
			fname = u'{fileBase}.pdf'.format( fileBase=self.fileBase )
			self.pdf.set_title( unicode(os.path.splitext(fname)[0].replace('-', ' ')).encode('iso-8859-1','ignore') )
			fname = os.path.join( self.dir, fname )
			self.pdf.output( fname, 'F' )
			self.lastFName = fname
			self.pdf = None
		return super(CrossMgrPrintoutPDF, self).OnEndPrinting()

	def OnPrintPage( self, page ):
		exportGrid = self.prepareGrid( page )

		try:
			category = self.pageInfo[page][0]
		except Exception as e:
			# Handle case of no data.
			return True
		
		pageNumber = self.pageInfo[page][3]
		pageTotal = self.pageInfo[page][4]
		
		fname = u'{fileBase}-{categoryName}.pdf'.format(
			fileBase = self.fileBase,
			categoryName = category.fullname if category != 'Primes' else 'Primes'
		)
		fname = Utils.RemoveDisallowedFilenameChars( fname ).replace( ' ', '-' )
		
		if not self.pdf:
			self.pdf = PDF( orientation = 'L' if self.orientation == wx.LANDSCAPE else 'P' )
			self.pdf.set_font( 'Arial', '', 12 )
			self.pdf.set_author( unicode(getpass.getuser()).encode('iso-8859-1','ignore') )
			self.pdf.set_keywords( unicode('CrossMgr Results').encode('iso-8859-1','ignore') )
			self.pdf.set_creator( unicode(Version.AppVerName).encode('iso-8859-1','ignore') )
			self.pdf.set_title( unicode(os.path.splitext(fname)[0].replace('-', ' ')).encode('iso-8859-1','ignore') )
		
		exportGrid.drawToFitPDF( *([self.pdf, self.orientation] + self.pageInfo[page][1:-1]) )
		
		if not self.allInOne and pageNumber == pageTotal:
			if self.dir and not os.path.isdir( self.dir ):
				os.mkdir( self.dir )
			fname = os.path.join( self.dir, fname )
			self.pdf.output( fname, 'F' )
			self.lastFName = fname
			self.pdf = None
		
		return True
Example #2
0
def print_aso_bib_two_per_page(participant):

    pdf = PDF(orientation='P')
    pdf.set_subject(
        'Bib number and rider info in modified aso format, two per page.')
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross RFID'
    )

    license_holder = participant.license_holder
    aso_bib_two_per_page(pdf, participant.bib, license_holder.first_name,
                         license_holder.last_name,
                         participant.competition.name)

    return pdf.output(dest='s')
Example #3
0
def print_aso_bib(participant, copies=2):
    license_holder = participant.license_holder
    copies = int(copies)

    pdf = PDF(orientation='P')
    pdf.set_subject('Bib number and rider info in aso format.')
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross RFID'
    )

    for c in xrange(copies):
        aso_bib(pdf, participant.bib, license_holder.first_name,
                license_holder.last_name, participant.competition.name)

    return pdf.output(dest='s')
Example #4
0
	def doExport( self, event=None ):
		race = Model.race
		if not race:
			return
		
		fileName = Utils.getMainWin().fileName if Utils.getMainWin() else 'Test.cmn'
		
		#---------------------------------------------------------------------------------
		# Create an Excel file.
		#
		xlFileName = os.path.splitext(fileName)[0] + '-TeamResults.xlsx'

		try:
			wb = xlsxwriter.Workbook( xlFileName )
			formats = ExportGrid.ExportGrid.getExcelFormatsXLSX( wb )
			
			ues = Utils.UniqueExcelSheetName()
			for category in race.getCategories( publishOnly=True ):			
				eg = self.toExportGrid( category )
				if eg:
					ws = wb.add_worksheet( ues.getSheetName(category.fullname) )
					eg.toExcelSheetXLSX( formats, ws )
			wb.close()
		except Exception as e:
			logException( e, sys.exc_info() )
		del wb
		
		#---------------------------------------------------------------------------------
		# Create a PDF file.
		#
		pdfFileName = os.path.splitext(fileName)[0] + '-TeamResults.pdf'
		
		try:
			pdf = PDF( orientation = 'P' )
			pdf.set_font( 'Arial', '', 12 )
			pdf.set_author( getpass.getuser() )
			pdf.set_keywords( 'CrossMgr Team Results' )
			pdf.set_creator( Version.AppVerName )
			pdf.set_title( os.path.splitext(pdfFileName)[0].replace('-', ' ') )
			for category in race.getCategories( publishOnly=True ):
				eg = self.toExportGrid( category )
				if eg:
					eg.drawToFitPDF( pdf, orientation=wx.PORTRAIT )
			pdf.output( pdfFileName, 'F' )
		except Exception as e:
			logException( e, sys.exc_info() )
		del pdf
Example #5
0
def print_id_label(participant):
    competition = participant.competition
    license_holder = participant.license_holder

    bib = participant.bib
    name = license_holder.first_last
    if len(name) > 32:
        name = license_holder.first_last_short

    system_name = 'CrossMgr'

    inches_to_points = 72.0

    # Use points at the units.
    page_width = 3.9 * inches_to_points
    page_height = 2.4 * inches_to_points

    pdf = PDF('L', (page_height, page_width))
    pdf.set_author(RaceDBVersion)
    pdf.set_title('Bib Number: {}'.format(bib))
    pdf.set_subject('Rider ID and Emergency Information.')
    pdf.set_creator(getpass.getuser())
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross'
    )

    margin = min(page_height, page_width) / 18.0
    sep = margin / 2.5

    height = page_height - margin * 2.0
    width = page_width - margin * 2.0

    header = Rect(margin, margin, width, height / 10.0)
    footer_height = height / 20
    footer = Rect(margin, page_height - margin - footer_height, header.width,
                  footer_height)
    field = Rect(header.x, header.bottom + sep, width,
                 footer.top - header.bottom - sep * 2)

    leftArrow, rightArrow = chr(172), chr(174)

    font_name = 'Helvetica'
    pdf.add_page()
    pdf.set_font(font_name, 'b')

    header.draw_text_to_fit(pdf, name, Rect.AlignLeft, True)

    pdf.set_font(font_name)
    info = []
    info.append([
        '',
        u',  '.join([
            u'Age: {}'.format(license_holder.get_age()),
            u'Gender: {}'.format(license_holder.get_gender_display()),
            u'Nation: {}'.format(license_holder.nation_code),
        ]),
    ])
    info.append(['', ''])
    if participant.team:
        info.append(['', u'{}'.format(participant.team.name)])
    info.append([
        '',
        u',  '.join([
            u'Bib: {}'.format(participant.bib),
            u'Category: {}'.format(participant.category.code_gender
                                   if participant.category else ''),
        ]),
    ])
    if license_holder.phone:
        info.append([
            '',
            u'  '.join([
                u'Phone: {}'.format(format_phone(license_holder.phone)),
            ]),
        ])

    info.append(['', ''])
    if license_holder.emergency_medical:
        info.append([
            '', u'Medical Alert: {}'.format(license_holder.emergency_medical)
        ])
    info.append(['', u'Emergency Contact:'])
    if license_holder.emergency_contact_name:
        info.append([
            '', u'  {}'.format(license_holder.emergency_contact_name
                               or 'None provided')
        ])
    info.append([
        '', u'  {}'.format(
            format_phone(license_holder.emergency_contact_phone)
            or 'No phone number provided')
    ])

    pdf.table_in_rectangle(field.x,
                           field.y,
                           field.width,
                           field.height,
                           info,
                           leftJustifyCols=[0, 1],
                           hasHeader=False,
                           horizontalLines=False)

    footer.draw_text_to_fit(pdf, system_name, Rect.AlignRight, True)

    pdf_str = pdf.output(dest='s')
    return pdf_str
Example #6
0
def print_bib_on_rect(bib,
                      license_code=None,
                      name=None,
                      logo=None,
                      widthInches=5.9,
                      heightInches=3.9,
                      copies=1,
                      onePage=False):
    page_width = widthInches * inches_to_points
    page_height = heightInches * inches_to_points

    pdf = PDF('L', (page_height * (copies if onePage else 1), page_width))
    pdf.set_author(RaceDBVersion)
    pdf.set_title('Race Bib Number: {}'.format(bib))
    pdf.set_subject('Bib number.')
    pdf.set_creator(getpass.getuser())
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross RFID'
    )
    pdf.add_font('din1451alt',
                 style='',
                 fname=get_font_file('din1451alt G.ttf'),
                 uni=True)

    margin = min(page_height, page_width) / 17.5
    sep = margin / 2.5

    height = page_height - margin * 2.0
    width = page_width - margin * 2.0

    text_margin = margin
    text_height = margin * 0.4

    for c in xrange(copies):
        if c == 0 or not onePage:
            pdf.add_page()
            page_y = 0
        else:
            page_y = page_height * c
            pdf.dashed_line(0, page_y, page_width, page_y, space_length=12)

        pdf.set_font('din1451alt', '', 16)
        field = Rect(margin, margin + page_y, width, height)
        field.draw_text_to_fit(pdf, bib, Rect.AlignCenter | Rect.AlignMiddle)

        pdf.set_font('Helvetica')
        if logo:
            x = text_margin
            logo_rect = Rect(x, page_height - margin + page_y,
                             (page_width - barcode_width_max) / 2.0 - x,
                             text_height)
            logo_rect.draw_text_to_fit(pdf, logo,
                                       Rect.AlignLeft | Rect.AlignMiddle)

        if license_code:
            barcode_rect = Rect(margin, page_height - margin * 1.2 + page_y,
                                width, margin * 0.8)
            draw_code128(pdf, license_code, barcode_rect.x, barcode_rect.y,
                         barcode_rect.width, barcode_rect.height)

        if name:
            x = (page_width + barcode_width_max) / 2.0
            name_rect = Rect(x, page_height - margin + page_y,
                             page_width - text_margin - x, text_height)
            name_rect.draw_text_to_fit(pdf, name,
                                       Rect.AlignRight | Rect.AlignMiddle)

    pdf_str = pdf.output(dest='s')
    return pdf_str
Example #7
0
def print_bib_tag_label(participant,
                        sponsor_name=None,
                        left_page=True,
                        right_page=True,
                        barcode=True):
    competition = participant.competition
    license_holder = participant.license_holder

    bib = participant.bib
    name = license_holder.first_last
    if len(name) > 32:
        name = license_holder.first_last_short

    if sponsor_name is None:
        if competition.number_set and competition.number_set.sponsor:
            sponsor_name = competition.number_set.sponsor
        else:
            sponsor_name = competition.name
    system_name = 'CrossMgr'

    # Use points at the units.
    page_width = 3.9 * inches_to_points
    page_height = 2.4 * inches_to_points

    pdf = PDF('L', (page_height, page_width))
    pdf.set_author(RaceDBVersion)
    pdf.set_title('Race Bib Number: {}'.format(bib))
    pdf.set_subject(
        'Bib number and rider info to be printed as a label to apply on the chip tag.'
    )
    pdf.set_creator(getpass.getuser())
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross RFID'
    )

    pdf.add_font('din1451alt',
                 style='',
                 fname=get_font_file('din1451alt G.ttf'),
                 uni=True)
    pdf.add_font('Arrows',
                 style='',
                 fname=get_font_file('Arrrows-Regular.ttf'),
                 uni=True)

    margin = min(page_height, page_width) / 18.0
    sep = margin / 2.5

    height = page_height - margin * 2.0
    width = page_width - margin * 2.0

    header = Rect(margin, margin, width, height / 18.0)
    footer = Rect(margin, page_height - margin - header.height, header.width,
                  header.height)
    field = Rect(header.x, header.bottom + sep, width,
                 footer.top - header.bottom - sep * 2)

    license_code = license_holder.uci_id or license_holder.license_code

    leftArrow, rightArrow = 'A', 'a'

    font_name = 'Helvetica'
    for lp in ([True] if left_page else []) + ([False] if right_page else []):
        pdf.add_page()

        arrow = copy.deepcopy(header)
        arrow.y -= arrow.height * 0.5
        arrow.height *= 2
        pdf.set_font('Arrows')
        arrowWidth = arrow.draw_text_to_fit(
            pdf,
            leftArrow if lp else rightArrow,
            (Rect.AlignLeft if lp else Rect.AlignRight) | Rect.AlignMiddle,
            consider_descenders=True,
            convert_to_text=False,
        )
        arrowWidth += pdf.get_string_width('  ')

        header_remain = copy.deepcopy(header)
        if lp:
            header_remain.x += arrowWidth
        header_remain.width -= arrowWidth

        pdf.set_font(font_name)
        header_remain.draw_text_to_fit(
            pdf, sponsor_name,
            (Rect.AlignLeft if lp else Rect.AlignRight) | Rect.AlignMiddle,
            True)

        pdf.set_font('din1451alt', '', 16)
        field.draw_text_to_fit(pdf, bib, Rect.AlignCenter | Rect.AlignMiddle)

        pdf.set_font(font_name)
        name_width = footer.draw_text_to_fit(
            pdf, name,
            (Rect.AlignRight if lp else Rect.AlignLeft) | Rect.AlignMiddle)

        logo = copy.deepcopy(footer)
        if not lp:
            logo.x += name_width + sep
        logo.width -= name_width + sep
        if logo.width > 20:
            logo_width = logo.draw_text_to_fit(
                pdf, system_name,
                (Rect.AlignLeft if lp else Rect.AlignRight) | Rect.AlignMiddle)
        else:
            logo_width = 0

        if barcode:
            remaining_width = header.width - name_width - logo_width
            if lp:
                barcode_rect = Rect(footer.x + logo_width, footer.y,
                                    remaining_width, footer.height)
            else:
                barcode_rect = Rect(
                    footer.right - logo_width - remaining_width, footer.y,
                    remaining_width, footer.height)
            if license_code:
                draw_code128(pdf, license_code, barcode_rect.x, barcode_rect.y,
                             barcode_rect.width, barcode_rect.height)

    pdf_str = pdf.output(dest='s')
    return pdf_str
Example #8
0
class CrossMgrPrintoutPDF(CrossMgrPrintout):
    def __init__(self,
                 dir,
                 fileBase,
                 orientation,
                 categories=None,
                 allInOne=False):
        CrossMgrPrintout.__init__(self, categories)
        self.dir = dir
        self.fileBase = fileBase
        self.orientation = orientation
        self.allInOne = allInOne
        self.pdf = None
        self.lastFName = None

    def OnEndPrinting(self):
        if self.pdf and self.allInOne:
            if self.dir and not os.path.isdir(self.dir):
                os.mkdir(self.dir)
            fname = u'{fileBase}.pdf'.format(fileBase=self.fileBase)
            self.pdf.set_title(
                unicode(os.path.splitext(fname)[0].replace('-', ' ')).encode(
                    'iso-8859-1', 'ignore'))
            fname = os.path.join(self.dir, fname)
            self.pdf.output(fname, 'F')
            self.lastFName = fname
            self.pdf = None
        return super(CrossMgrPrintoutPDF, self).OnEndPrinting()

    def OnPrintPage(self, page):
        exportGrid = self.prepareGrid(page)

        category = self.pageInfo[page][0]
        pageNumber = self.pageInfo[page][3]
        pageTotal = self.pageInfo[page][4]

        fname = u'{fileBase}-{categoryName}.pdf'.format(
            fileBase=self.fileBase,
            categoryName=category.fullname
            if category != 'Primes' else 'Primes')
        fname = Utils.RemoveDisallowedFilenameChars(fname).replace(' ', '-')

        if not self.pdf:
            self.pdf = PDF(
                orientation='L' if self.orientation == wx.LANDSCAPE else 'P')
            self.pdf.set_font('Arial', '', 12)
            self.pdf.set_author(
                unicode(getpass.getuser()).encode('iso-8859-1', 'ignore'))
            self.pdf.set_keywords(
                unicode('CrossMgr Results').encode('iso-8859-1', 'ignore'))
            self.pdf.set_creator(
                unicode(Version.AppVerName).encode('iso-8859-1', 'ignore'))
            self.pdf.set_title(
                unicode(os.path.splitext(fname)[0].replace('-', ' ')).encode(
                    'iso-8859-1', 'ignore'))

        exportGrid.drawToFitPDF(*([self.pdf, self.orientation] +
                                  self.pageInfo[page][1:-1]))

        if not self.allInOne and pageNumber == pageTotal:
            if self.dir and not os.path.isdir(self.dir):
                os.mkdir(self.dir)
            fname = os.path.join(self.dir, fname)
            self.pdf.output(fname, 'F')
            self.lastFName = fname
            self.pdf = None

        return True