Mario,
Here is a function stripped from a working program that uses printpreview
from wxWindows to print out cells from a grid that the user is working
on. Hopefully this can point you in the proper direction.
Regards,
Larry Bates
def DO_printpreview(self, event):
if self._trace:
self.logf.writelines("T","Entering OuterFrame.DO_printpreview")
self.SetStatusText('Generating Print Preview', 0)
#
# Define the columns on the printout
#
columndefs=(("Cust#", 8.0/16.0, wxALIGN_LEFT),
("Customer Name", 29.0/16.0, wxALIGN_LEFT),
("Reference", 16.0/16.0, wxALIGN_LEFT),
("Type", 6.0/16.0, wxALIGN_CENTRE),
("Inv. #", 8.0/16.0, wxALIGN_CENTRE),
("InvDate", 9.0/16.0, wxALIGN_CENTRE),
("L#", 4.0/16.0, wxALIGN_CENTRE),
("Item #", 12.0/16.0, wxALIGN_CENTRE),
("Item Description",45.0/16.0, wxALIGN_LEFT),
("Qty", 6.0/16.0, wxALIGN_RIGHT),
("Cost", 10.0/16.0, wxALIGN_RIGHT),
("OMMC $", 10.0/16.0, wxALIGN_RIGHT)
)
columncount=len(columndefs)
#
# Create a new frame for the print preview and give it to PrintTable
#
self.previewframe=PreviewFrame(None, sys.stdout)
if self._trace:
log.writelines("T","DO_ppv-Creating PrintTable instance")
prt=PrintTable(self.previewframe)
#
# Set printout column widths
#
if self._trace: self.logf.writelines("T","DO_ppv-Setting column widths")
prt.set_column=[a[1] for a in columndefs]
#
# Set the column labels (headings)
#
if self._trace:
self.logf.writelines("T","DO-ppv-Setting column headings")
prt.label=[a[0] for a in columndefs]
#
# Set the column alignments
#
if self._trace:
self.logf.writelines("T", "DO-ppv-Setting column alignments")
map(prt.SetColAlignment, range(columncount), [a[2] for a in columndefs])
#
# Get the data values from the grid that are selected
#
data=self._getdata('1')
#
# Skip the first (flag) column and columns 11,13,15,16
# to delete them from the printout.
#
data=[[v[1],v[2],v[3],v[4][0:2],v[5],v[6],
v[7],v[8],v[9],v[10],v[12],v[14]] for v in data]
#
# Loop over the lines and insert a blank line between customers
#
blankline=columncount*[''] # Create a blank output line
lastcustomer=None
pdata=[]
for values in data:
if lastcustomer != None and values[0] != lastcustomer:
pdata.append(blankline)
lastcustomer=values[0]
pdata.append(values)
pdata.append(blankline)
prt.data=pdata
prt.left_margin=0.3
prt.SetLandscape()
prt.SetHeader("OMMC Recap Listing-Hardware Items")
prt.SetFooter()
prt.SetFooter("Date: ", type = "Date & Time", \
align=wxALIGN_LEFT, \indent=prt.left_margin)
#
# Override the default font sizes
#
prt.text_font_size = 8
#prt.label_font_size= 7
prt.cell_left_margin = 1.0/32.0
prt.Preview()
if self._trace:
self.logf.writelines("T","Entering OuterFrame.DO_printpreview")
return