[Tutor] Printing HTML files
Gardner, Dean
Dean.Gardner at barco.com
Mon Sep 10 14:55:39 CEST 2007
Hi
I am currently trying to print out a html file that is essentially a
summary table and I am running into problems. From the link below it
seems that the method I am using to print the table doesn't handle
column width and wrapping but confusingly we use a similar method
elsewhere in the code and it works fine.
This is the summary builder
class TestingSummary:
def __init__(self,records):
self.records = records
def splitRecordAndBuildSummaryText(self):
summary_dict={}
test_fields=[]
keys=[]
fields =
["TestedDate:","TestId:","Branch:","Version:","SpecId:","PassOrFail:"]
records = self.records.split("\n\n")
for record in records:
record=record.split("\n")
for item in record:
if "TestId" in item:
testid=record.pop(1)
testid = testid.replace("TestId:","")
for field in record:
for item in fields:
#print item
field = field.replace(item,"")
test_fields.append(field)
summary_dict[testid]=test_fields
test_fields = []
# print summary_dict
summary = self.buildHtmlSummaryPage(summary_dict)
return summary
def buildHtmlSummaryPage(self,dict_of_summary):
#print list_of_ids
test_summary_details=""
for key, value in dict_of_summary.items():
#print value
#print details
test_summary_details+="""<tr><td width="11%%">%s</td><td
width="18%%">%s</td><td width="12%%">%s</td><td
width="29%%">%s</td></tr>\n""" %
(key,value[3],value[-1],"".join(value[1]+value[2]))
summary =
"".join(["""<html><head><title></title></head><body><table border="0"
width="88%">\n""",
"""<tr><td width="24%"><b><font face="Arial">Testing
Summary</font></b></td><td width="31%"> </td><td
width="26%"> </td></tr>\n""",
"""<tr><td width="24%"><b><font face="Arial Black">Tested
by:</font></b></td><td width="31%"> </td>\n""",
"""<td width="26%"><b><font face="Arial Black">Machine
Name:</font></b> </td></tr>\n""",
"""<tr><td width="24%"> </td><td width="31%"> </td><td
width="26%"> </td></tr>\n""",
"""<tr><td width="24%"> </td><td width="31%"> </td><td
width="26%"> </td></tr>\n""",
"""<tr><td width="11%"><b><u><font
face="Arial">TestID</font></u></b></td><td width="18%"><b><u><font
face="Arial">Specification</font></u></b></td>\n""",
"""<td width="12%"><b><u><font
face="Arial">Result</font></u></b></td><td width="39%"><b><u><font
face="Arial">BuildID</font></u></b></td></tr><tr>\n"""])
summary+=test_summary_details
summary+="</body></html>"
return summary
and the mechanism for printing
def printSummary(self,summary):
print_dialog = wx.PrintDialog(self)
if print_dialog.ShowModal() == wx.ID_CANCEL:
return
print_dialog_data = print_dialog.GetPrintDialogData()
printer = wx.Printer(print_dialog_data)
printout = wx.html.HtmlPrintout("Printing Test Summary")
# margins (top, bottom, left, right)
printout.SetMargins(15, 15, 20, 20)
#REMOVE
#-----This was for testing purposes only
htmlOutput = open("TestingSummary.html","w")
htmlOutput.write(summary)
htmlOutput.close()
#-------------------------------------------------
printout.SetHtmlText(summary)
printout.SetFooter(self.HtmlFooterForPrint(1, 1))
printer.Print(self, printout, False)
When I save the file as html the browser will open it fine and it is I
expect but if I print it I end up with
Testing Summary Tested by: Machine Name:
TestIDSpecificationResultBuildID 000003 -0000-0009
Pass 0000 1111 000002 Specification-0000-0009 Pass 0000 1111
000001 Specification-0000-0009 Pass 0000 1111
http://archives.devshed.com/forums/python-122/printing-problem-1843805.h
tml
Am I doing something silly?
Thanks
Dean Gardner
DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070910/e445bd08/attachment-0001.htm
More information about the Tutor
mailing list