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.write lines("T","Ente ring OuterFrame.DO_p rintpreview")
self.SetStatusT ext('Generating Print Preview', 0)
#
# Define the columns on the printout
#
columndefs=(("C ust#", 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.previewfra me=PreviewFrame (None, sys.stdout)
if self._trace:
log.writelines( "T","DO_ppv-Creating PrintTable instance")
prt=PrintTable( self.previewfra me)
#
# Set printout column widths
#
if self._trace: self.logf.write lines("T","DO_p pv-Setting column widths")
prt.set_column=[a[1] for a in columndefs]
#
# Set the column labels (headings)
#
if self._trace:
self.logf.write lines("T","DO-ppv-Setting column headings")
prt.label=[a[0] for a in columndefs]
#
# Set the column alignments
#
if self._trace:
self.logf.write lines("T", "DO-ppv-Setting column alignments")
map(prt.SetColA lignment, range(columncou nt), [a[2] for a in columndefs])
#
# Get the data values from the grid that are selected
#
data=self._getd ata('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=colum ncount*[''] # Create a blank output line
lastcustomer=No ne
pdata=[]
for values in data:
if lastcustomer != None and values[0] != lastcustomer:
pdata.append(bl ankline)
lastcustomer=va lues[0]
pdata.append(va lues)
pdata.append(bl ankline)
prt.data=pdata
prt.left_margin =0.3
prt.SetLandscap e()
prt.SetHeader(" OMMC Recap Listing-Hardware Items")
prt.SetFooter()
prt.SetFooter(" Date: ", type = "Date & Time", \
align=wxALIGN_L EFT, \indent=prt.lef t_margin)
#
# Override the default font sizes
#
prt.text_font_s ize = 8
#prt.label_font _size= 7
prt.cell_left_m argin = 1.0/32.0
prt.Preview()
if self._trace:
self.logf.write lines("T","Ente ring OuterFrame.DO_p rintpreview")
return
Mario wrote:
Hello all, I'm trying hard to make possible to print some simple text from
python to the default printer using wxPython, after days of internet
searches I found this page: http://wiki.wxpython.org/index.cgi/Printing but
is impossible to use this script even if I do exactly as said there. I think
the script is buggy or I am not able to use it, even if seems very simple to
use...
Anyone can give me an hint on how to easily and simply print some text? Is
there a library ready to download and use? Something like SendPrinter("so me
text\n")?
Thanks in advance if anyone can give any help.
Mario