By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

HELP Printing with wxPython

P: n/a
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("some
text\n")?

Thanks in advance if anyone can give any help.

Mario
Jul 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
> 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("some text\n")?


On the strict wxPython front, I can't help
you, but I might be able to offer some help.
Depends a little bit on how much you're tied
to wxPython and how much you need to be cross-platform.

Essentially, if you're on Windows (and have no need
to run on anything else) then consider some of the
solutions here:

http://tgolden.sc.sabren.com/python/...o_i/print.html

If you're on Unix / whatever with no need to do
anything else, then I'm sure there are straightforward
ways to push stuff to a printer. (Something using lpr
he thinks, hoping someone with real knowledge can chip
in).

If you *really* want to use wxPython for cross-platform
needs, or just because you think it's cleaner, then try
on the wxPython lists if you haven't already.

TJG

Jul 19 '05 #2

P: n/a
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
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("some
text\n")?

Thanks in advance if anyone can give any help.

Mario

Jul 19 '05 #3

P: n/a
Hi Mario,
Something like SendPrinter("some text\n")?
If you are doing this just for yourself, and you know you have a
printer that will really print just the plain text when you send it
plain text (like a dot matrix printer from the early 90s) then you can
probably open the printer device and send it text. Under windows you
can try opening LPT1 or on unix it's probably /dev/lpr or something
like that.

wxPython makes it pretty easy to give full modern support for any
printer, including letting the user select which printer to print to,
and getting a print preview, choosing paper size, etc.

I especially like the HtmlEasyPrinting write-up here:
http://wiki.wxpython.org/index.cgi/Printing

-Jim


On 5/11/05, Mario <ma***@nospam.noext> 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 simpleto
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("some
text\n")?

Thanks in advance if anyone can give any help.

Mario

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #4

P: n/a

"Tim G" <ti********@viacom-outdoor.co.uk> wrote:
Essentially, if you're on Windows (and have no need
to run on anything else) then consider some of the
solutions here:

http://tgolden.sc.sabren.com/python/...o_i/print.html


That was exactly what I needed! Thanks SO MUCH! :) I tested all the
different things and worked perfectly with no problem.

Thanks again, I was trying to do the printing since a lot but never seen
that windows api thing before.

Mario

Jul 19 '05 #5

P: n/a

"Larry Bates" <lb****@syscononline.com> ha scritto nel messaggio
news:42**************@syscononline.com...
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.


Thank you very much for the help, I will study all the code that you sent me
for a future and a more professional programming, for now I used a very
simple win32api call, not very evolved but working fine for what I needed,
since what I am doing needs to run only on a windows machine.

Thanks again :)

Mario

Jul 19 '05 #6

P: n/a

"James Carroll" <mr*****@gmail.com> wrote:
I especially like the HtmlEasyPrinting write-up here:
http://wiki.wxpython.org/index.cgi/Printing


Thank you for your suggestion but I'm just not able to make it work, as i
said on the original post, I do exactly what is wrote there, but it gives
errors, I think the script is not updated and not working fine with the
latest versions of python or wxpython.

Mario


Jul 19 '05 #7

P: n/a
James Carroll <mr*****@gmail.com> writes:
If you are doing this just for yourself, and you know you have a
printer that will really print just the plain text when you send it
plain text (like a dot matrix printer from the early 90s) then you can
probably open the printer device and send it text. Under windows you
can try opening LPT1 or on unix it's probably /dev/lpr or something
like that.


Under Unix, you shouldn't be able to open the line printer, whether
it's /dev/lpr or /dev/lpt0 or whater. You shouldn't have
permission.

Instead, as was suggested earlier, use the "lpr" command and send it
the text/data on standard input. Any reasonably managed Unix system
should be able to handle a fair range of graphics formats, though
postscript is preferred.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #8

P: n/a
On Thursday 12 May 2005 04:56 am, Mike Meyer wrote:
James Carroll <mr*****@gmail.com> writes:
If you are doing this just for yourself, and you know you have a
printer that will really print just the plain text when you send it
plain text (like a dot matrix printer from the early 90s) then you can
probably open the printer device and send it text. Under windows you
can try opening LPT1 or on unix it's probably /dev/lpr or something
like that.


Under Unix, you shouldn't be able to open the line printer, whether
it's /dev/lpr or /dev/lpt0 or whater. You shouldn't have
permission.

Instead, as was suggested earlier, use the "lpr" command and send it
the text/data on standard input. Any reasonably managed Unix system
should be able to handle a fair range of graphics formats, though
postscript is preferred.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more
information.


I've been using:

p=os.popen('lp','w')
p.write("some text')
p.Close()
Jeff

Jul 19 '05 #9

P: n/a
jeff elkins <je********@earthlink.net> writes:
Instead, as was suggested earlier, use the "lpr" command and send it
the text/data on standard input. Any reasonably managed Unix system
should be able to handle a fair range of graphics formats, though
postscript is preferred.

I've been using:

p=os.popen('lp','w')
p.write("some text')
p.Close()


Yeah. System V called it lp. BSD called it lpr. Most modern systems
have both, as they are just a front end to the line printer (when was
the last time you saw an honest-to-gods line printer?) daemon.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #10

P: n/a
There's a working version in the wxPython Demo...

If you run the wxpython demo, and choose Print Framework under
Miscellaneous it has code that looks a whole lot like what's on the
wiki, only you can test it and try it out and see if it's broken for
you there. If anything doesn't work, let the wxPython mailing list
people know about it, and they'll have a work-around or a fix (or show
you what you should be doing) in no time.

-Jim
On 5/11/05, Mario <ma***@nospam.noext> wrote:

"James Carroll" <mr*****@gmail.com> wrote:
I especially like the HtmlEasyPrinting write-up here:
http://wiki.wxpython.org/index.cgi/Printing


Thank you for your suggestion but I'm just not able to make it work, as i
said on the original post, I do exactly what is wrote there, but it gives
errors, I think the script is not updated and not working fine with the
latest versions of python or wxpython.

Mario

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.