def print_list(self, event=None): #html = '''<style type=\"text/css\">td{{font-family:Arial; color:black; font-size:8pt;}}</style> # {}<table border="1" cellspacing="0"><tr>\n'''.format(header) html = '''<table border="1" cellspacing="0"><tr>\n''' #write out headers for index, col in enumerate(range(self.GetColumnCount())): html += u'''<th align="left" valign="top">{}</th>\n'''.format( self.GetColumn(col).GetText()) html += '</tr>' #write out data for row in range(self.GetItemCount()): html += '<tr>' for index, col in enumerate(range(self.GetColumnCount())): html += '''<td align="left" valign="top" nowrap>{} </td>\n'''.format( self.GetItem(row, col).GetText()) html += '</tr>' html += '</table>' printer = HtmlEasyPrinting() printer.SetHeader( '{}, Printed on @DATE@, Page @PAGENUM@ of @PAGESCNT@'.format( self.printer_header).lstrip(', ')) printer.SetStandardFonts(self.printer_font_size) printer.GetPrintData().SetPaperId(self.printer_paper_type) printer.GetPrintData().SetOrientation(self.printer_paper_orientation) if self.printer_paper_margins: printer.GetPageSetupData().SetMarginTopLeft( (self.printer_paper_margins[0], self.printer_paper_margins[1])) printer.GetPageSetupData().SetMarginBottomRight( (self.printer_paper_margins[2], self.printer_paper_margins[3])) printer.PrintText(html)
def on_click_print_revisions(event): notebook = ctrl(General.app.main_frame, 'notebook:revisions') item_entries = [] for index in range(notebook.GetPageCount()): item_entries.append(notebook.GetPageText(index).strip().split(' ')[0]) cursor = Database.connection.cursor() for item in item_entries: column_names = Database.get_table_column_names('revisions', presentable=True) revisions = cursor.execute( 'SELECT * FROM revisions WHERE item = \'{}\''.format( item)).fetchall() if revisions == None: continue # Revisions for Item Number: {} # <hr> html_to_print = '''<style type=\"text/css\">td{{font-family:Arial; color:black; font-size:8pt;}}</style> <table border="1" cellspacing="0"><tr> '''.format(item) blacklisted_columns = ['dollars_reconciled', 'related_ecr'] for column_name in column_names: if column_name.replace(' ', '_').lower() not in blacklisted_columns: html_to_print += '<th align=\"right\" valign=\"top\">{}</th>'.format( column_name.replace(' ', ' ')) html_to_print += '</tr>' for revision in revisions: html_to_print += '<tr>' for index, column_value in enumerate(revision): if column_names[index].replace( ' ', '_').lower() not in blacklisted_columns: if column_names[index] == 'When Revised': column_value = General.format_date_nicely(column_value) if column_names[index] != 'Description': column_value = str(column_value).replace(' ', ' ') html_to_print += '<td align=\"left\" valign=\"top\">{}</td>'.format( column_value) html_to_print += '</tr>' html_to_print += '</table>' printer = HtmlEasyPrinting() printer.GetPrintData().SetPaperId(wx.PAPER_LETTER) printer.GetPrintData().SetOrientation(wx.LANDSCAPE) printer.SetStandardFonts(9) printer.GetPageSetupData().SetMarginTopLeft((0, 0)) printer.GetPageSetupData().SetMarginBottomRight((0, 0)) printer.PrintText(html_to_print)